]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db/src/org/simantics/db/function/DbBiFunction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / function / DbBiFunction.java
diff --git a/bundles/org.simantics.db/src/org/simantics/db/function/DbBiFunction.java b/bundles/org.simantics.db/src/org/simantics/db/function/DbBiFunction.java
new file mode 100644 (file)
index 0000000..c2cca57
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************\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 a function that accepts one argument and produces a result that\r
+ * can throw database exceptions.\r
+ * This is the two-arity specialization of {@link DbFunction}.\r
+ *\r
+ * @param <T> the type of the first argument to the function\r
+ * @param <U> the type of the second argument to the function\r
+ * @param <R> the type of the result of the function\r
+ *\r
+ * @see Function\r
+ * @since 1.22.1 & 1.24.0\r
+ */\r
+@FunctionalInterface\r
+public interface DbBiFunction<T, U, R> {\r
+\r
+    /**\r
+     * Applies this function to the given arguments.\r
+     *\r
+     * @param t the first function argument\r
+     * @param u the second function argument\r
+     * @return the function result\r
+     */\r
+    R apply(T t, U u) throws DatabaseException;\r
+\r
+    /**\r
+     * Returns a composed function that first applies this function to\r
+     * its input, and then applies the {@code after} function to the result.\r
+     * If evaluation of either function throws an exception, it is relayed to\r
+     * the caller of the composed function.\r
+     *\r
+     * @param <V> the type of output of the {@code after} function, and of the\r
+     *           composed function\r
+     * @param after the function to apply after this function is applied\r
+     * @return a composed function that first applies this function and then\r
+     * applies the {@code after} function\r
+     * @throws NullPointerException if after is null\r
+     */\r
+    default <V> DbBiFunction<T, U, V> andThen(DbFunction<? super R, ? extends V> after) {\r
+        Objects.requireNonNull(after);\r
+        return (T t, U u) -> after.apply(apply(t, u));\r
+    }\r
+}\r