]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.db/src/org/simantics/db/function/DbBiConsumer.java b/bundles/org.simantics.db/src/org/simantics/db/function/DbBiConsumer.java
new file mode 100644 (file)
index 0000000..a1f378c
--- /dev/null
@@ -0,0 +1,63 @@
+/*******************************************************************************\r
+ * Copyright (c) 2016 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.function;\r
+\r
+import java.util.Objects;\r
+\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+/**\r
+ * Represents an operation that accepts two input arguments and returns no\r
+ * result and can throw database exceptions. This is the two-arity\r
+ * specialization of {@link DbConsumer}. Unlike most other functional interfaces,\r
+ * {@code BiDbConsumer} is expected to operate via side-effects.\r
+ *\r
+ * @param <T>\r
+ *            the type of the first argument to the operation\r
+ * @param <U>\r
+ *            the type of the second argument to the operation\r
+ *\r
+ * @see Consumer\r
+ * @since 1.22.1 & 1.24.0\r
+ */\r
+@FunctionalInterface\r
+public interface DbBiConsumer<T, U> {\r
+\r
+    /**\r
+     * Performs this operation on the given arguments.\r
+     *\r
+     * @param t the first input argument\r
+     * @param u the second input argument\r
+     */\r
+    void accept(T t, U u) throws DatabaseException;\r
+\r
+    /**\r
+     * Returns a composed {@code BiConsumer} that performs, in sequence, this\r
+     * operation followed by the {@code after} operation. If performing either\r
+     * operation throws an exception, it is relayed to the caller of the\r
+     * composed operation.  If performing this operation throws an exception,\r
+     * the {@code after} operation will not be performed.\r
+     *\r
+     * @param after the operation to perform after this operation\r
+     * @return a composed {@code BiConsumer} that performs in sequence this\r
+     * operation followed by the {@code after} operation\r
+     * @throws NullPointerException if {@code after} is null\r
+     */\r
+    default DbBiConsumer<T, U> andThen(DbBiConsumer<? super T, ? super U> after) {\r
+        Objects.requireNonNull(after);\r
+\r
+        return (l, r) -> {\r
+            accept(l, r);\r
+            after.accept(l, r);\r
+        };\r
+    }\r
+}\r