]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/function/DbBiFunction.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / function / DbBiFunction.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 a function that accepts one argument and produces a result that
20  * can throw database exceptions.
21  * This is the two-arity specialization of {@link DbFunction}.
22  *
23  * @param <T> the type of the first argument to the function
24  * @param <U> the type of the second argument to the function
25  * @param <R> the type of the result of the function
26  *
27  * @see Function
28  * @since 1.22.1 & 1.24.0
29  */
30 @FunctionalInterface
31 public interface DbBiFunction<T, U, R> {
32
33     /**
34      * Applies this function to the given arguments.
35      *
36      * @param t the first function argument
37      * @param u the second function argument
38      * @return the function result
39      */
40     R apply(T t, U u) throws DatabaseException;
41
42     /**
43      * Returns a composed function that first applies this function to
44      * its input, and then applies the {@code after} function to the result.
45      * If evaluation of either function throws an exception, it is relayed to
46      * the caller of the composed function.
47      *
48      * @param <V> the type of output of the {@code after} function, and of the
49      *           composed function
50      * @param after the function to apply after this function is applied
51      * @return a composed function that first applies this function and then
52      * applies the {@code after} function
53      * @throws NullPointerException if after is null
54      */
55     default <V> DbBiFunction<T, U, V> andThen(DbFunction<? super R, ? extends V> after) {
56         Objects.requireNonNull(after);
57         return (T t, U u) -> after.apply(apply(t, u));
58     }
59 }