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