1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package Torello.Java.Function;

import java.util.function.Function;

/**
 * <CODE>TriIntFunc Documentation.</CODE><BR /><BR />
 * Primitive's Extension to Java's {@code java.util.function.*} package.
 * <BR /><BR />This {@code FunctionalInterface} has an {@code apply(...)} method which accepts
 * three primitives: three {@code int}-primitives.
 */
@FunctionalInterface
public interface TriIntFunc<R>
{
    /**
     * Applies a user-provided function to input aruments, returning a result of type {@code R}
     * @param i1 The first integer-parameter.
     * @param i2 The second integer-parameter.
     * @param i3 The third integer-parameter.
     * @return The result of the function.  Return result is of type {@code 'R'}
     */
    public R apply(int i1, int i2, int i3);

    /**
     * Returns a composed function that first applies {@code '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 output-type of the {@code 'after'} function, and also of the (returned)
     * {@code 'composed'} function.
     * 
     * @param after The function to apply, after this function is applied.
     * @throws NullPointerException This throws if null is passed to {@code 'after'}.
     */
    public default <V> TriIntFunc<V> andThen(Function<R, V> after)
    {
        if (after == null) throw new NullPointerException
            ("null has been passed to parameter 'after'");

        return (int i1, int i2, int i3) -> after.apply(this.apply(i1, i2, i3));
    }
}