]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/function/DbBiConsumer.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / function / DbBiConsumer.java
1 /*******************************************************************************
2  * Copyright (c) 2016 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.function;
13
14 import java.util.Objects;
15
16 import org.simantics.db.exception.DatabaseException;
17
18 /**
19  * Represents an operation that accepts two input arguments and returns no
20  * result and can throw database exceptions. This is the two-arity
21  * specialization of {@link DbConsumer}. Unlike most other functional interfaces,
22  * {@code BiDbConsumer} is expected to operate via side-effects.
23  *
24  * @param <T>
25  *            the type of the first argument to the operation
26  * @param <U>
27  *            the type of the second argument to the operation
28  *
29  * @see Consumer
30  * @since 1.22.1 & 1.24.0
31  */
32 @FunctionalInterface
33 public interface DbBiConsumer<T, U> {
34
35     /**
36      * Performs this operation on the given arguments.
37      *
38      * @param t the first input argument
39      * @param u the second input argument
40      */
41     void accept(T t, U u) throws DatabaseException;
42
43     /**
44      * Returns a composed {@code BiConsumer} that performs, in sequence, this
45      * operation followed by the {@code after} operation. If performing either
46      * operation throws an exception, it is relayed to the caller of the
47      * composed operation.  If performing this operation throws an exception,
48      * the {@code after} operation will not be performed.
49      *
50      * @param after the operation to perform after this operation
51      * @return a composed {@code BiConsumer} that performs in sequence this
52      * operation followed by the {@code after} operation
53      * @throws NullPointerException if {@code after} is null
54      */
55     default DbBiConsumer<T, U> andThen(DbBiConsumer<? super T, ? super U> after) {
56         Objects.requireNonNull(after);
57
58         return (l, r) -> {
59             accept(l, r);
60             after.accept(l, r);
61         };
62     }
63 }