]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db/src/org/simantics/db/function/DbFunction.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / function / DbFunction.java
index f9e2059bde4c26b9d168c92990f4970b0d67f3e1..75b685f74f782499b9b0290bbc654d642b9a8b9c 100644 (file)
@@ -1,88 +1,88 @@
-/*******************************************************************************\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
- *\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
- * @since 1.22.1 & 1.24.0\r
- */\r
-@FunctionalInterface\r
-public interface DbFunction<T, R> {\r
-\r
-    /**\r
-     * Applies this function to the given argument.\r
-     *\r
-     * @param t the function argument\r
-     * @return the function result\r
-     */\r
-    R apply(T t) throws DatabaseException;\r
-\r
-    /**\r
-     * Returns a composed function that first applies the {@code before}\r
-     * function to its input, and then applies this 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 input to the {@code before} function, and to the\r
-     *           composed function\r
-     * @param before the function to apply before this function is applied\r
-     * @return a composed function that first applies the {@code before}\r
-     * function and then applies this function\r
-     * @throws NullPointerException if before is null\r
-     *\r
-     * @see #andThen(DbFunction)\r
-     */\r
-    default <V> DbFunction<V, R> compose(DbFunction<? super V, ? extends T> before) {\r
-        Objects.requireNonNull(before);\r
-        return (V v) -> apply(before.apply(v));\r
-    }\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
-     * @see #compose(DbFunction)\r
-     */\r
-    default <V> DbFunction<T, V> andThen(DbFunction<? super R, ? extends V> after) {\r
-        Objects.requireNonNull(after);\r
-        return (T t) -> after.apply(apply(t));\r
-    }\r
-\r
-    /**\r
-     * Returns a function that always returns its input argument.\r
-     *\r
-     * @param <T> the type of the input and output objects to the function\r
-     * @return a function that always returns its input argument\r
-     */\r
-    static <T> DbFunction<T, T> identity() {\r
-        return t -> t;\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2016 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.function;
+
+import java.util.Objects;
+
+import org.simantics.db.exception.DatabaseException;
+
+/**
+ * Represents a function that accepts one argument and produces a result that
+ * can throw database exceptions.
+ *
+ * @param <T> the type of the first argument to the function
+ * @param <U> the type of the second argument to the function
+ * @param <R> the type of the result of the function
+ * 
+ * @since 1.22.1 & 1.24.0
+ */
+@FunctionalInterface
+public interface DbFunction<T, R> {
+
+    /**
+     * Applies this function to the given argument.
+     *
+     * @param t the function argument
+     * @return the function result
+     */
+    R apply(T t) throws DatabaseException;
+
+    /**
+     * Returns a composed function that first applies the {@code before}
+     * function to its input, and then applies this function to the result.
+     * If evaluation of either function throws an exception, it is relayed to
+     * the caller of the composed function.
+     *
+     * @param <V> the type of input to the {@code before} function, and to the
+     *           composed function
+     * @param before the function to apply before this function is applied
+     * @return a composed function that first applies the {@code before}
+     * function and then applies this function
+     * @throws NullPointerException if before is null
+     *
+     * @see #andThen(DbFunction)
+     */
+    default <V> DbFunction<V, R> compose(DbFunction<? super V, ? extends T> before) {
+        Objects.requireNonNull(before);
+        return (V v) -> apply(before.apply(v));
+    }
+
+    /**
+     * Returns a composed function that first applies this function to
+     * its input, and then applies the {@code after} function to the result.
+     * If evaluation of either function throws an exception, it is relayed to
+     * the caller of the composed function.
+     *
+     * @param <V> the type of output of the {@code after} function, and of the
+     *           composed function
+     * @param after the function to apply after this function is applied
+     * @return a composed function that first applies this function and then
+     * applies the {@code after} function
+     * @throws NullPointerException if after is null
+     *
+     * @see #compose(DbFunction)
+     */
+    default <V> DbFunction<T, V> andThen(DbFunction<? super R, ? extends V> after) {
+        Objects.requireNonNull(after);
+        return (T t) -> after.apply(apply(t));
+    }
+
+    /**
+     * Returns a function that always returns its input argument.
+     *
+     * @param <T> the type of the input and output objects to the function
+     * @return a function that always returns its input argument
+     */
+    static <T> DbFunction<T, T> identity() {
+        return t -> t;
+    }
+}