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
10 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.function;
\r
14 import java.util.Objects;
\r
16 import org.simantics.db.exception.DatabaseException;
\r
19 * Represents a function that accepts one argument and produces a result that
\r
20 * can throw database exceptions.
\r
21 * This is the two-arity specialization of {@link DbFunction}.
\r
23 * @param <T> the type of the first argument to the function
\r
24 * @param <U> the type of the second argument to the function
\r
25 * @param <R> the type of the result of the function
\r
28 * @since 1.22.1 & 1.24.0
\r
30 @FunctionalInterface
\r
31 public interface DbBiFunction<T, U, R> {
\r
34 * Applies this function to the given arguments.
\r
36 * @param t the first function argument
\r
37 * @param u the second function argument
\r
38 * @return the function result
\r
40 R apply(T t, U u) throws DatabaseException;
\r
43 * Returns a composed function that first applies this function to
\r
44 * its input, and then applies the {@code after} function to the result.
\r
45 * If evaluation of either function throws an exception, it is relayed to
\r
46 * the caller of the composed function.
\r
48 * @param <V> the type of output of the {@code after} function, and of the
\r
50 * @param after the function to apply after this function is applied
\r
51 * @return a composed function that first applies this function and then
\r
52 * applies the {@code after} function
\r
53 * @throws NullPointerException if after is null
\r
55 default <V> DbBiFunction<T, U, V> andThen(DbFunction<? super R, ? extends V> after) {
\r
56 Objects.requireNonNull(after);
\r
57 return (T t, U u) -> after.apply(apply(t, u));
\r