Package com.ocient.util
Class Functions
java.lang.Object
com.ocient.util.Functions
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A,R> Function <A, R> Returns a function that always returns a constant value.static <A,B, R> BiFunction <A, B, R> Returns a function that always returns a constant value.static booleanA function that always returnsfalse.static <T> booleanalwaysFalse(T t) A function that always returnsfalse, regardless of the argument.static <T,U> boolean alwaysFalse(T t, U u) A function that always returnsfalse, regardless of the argument.static <A,B> A alwaysFirst(A a, B b) Returns the first argument of typeA.static <A,B> B alwaysSecond(A a, B b) Returns the second argument of typeB.static booleanA function that always returnstrue.static <T> booleanalwaysTrue(T t) A function that always returnstrue, regardless of the argument.static <T,U> boolean alwaysTrue(T t, U u) A function that always returnstrue, regardless of the argument.static <A,R> Function <A, R> constant(R r) Returns a function that always returns the given constant value, regardless of its input.static <A,B, R> BiFunction <A, B, R> constant2(R r) Returns a function that always returns the given constant value, regardless of its input arguments.static <T> Tidentity(T t) A function that returns its argument unchanged.static booleannegate(boolean b) Returns the logical negation of the boolean argument.Returns a composed predicate that represents the logical negation of the given function.static voidnoop()A function that does nothing.static <T> voidnoop(T t) A function that does nothing with the given argument.static <T,U> void noop(T t, U u) A function that does nothing with the given arguments.static VoidA function that returns a Void.static <T> VoidnoopBoxedVoid(T t) A function that does nothing with the given argument.
-
Method Details
-
noop
public static void noop()A function that does nothing. -
noop
public static <T> void noop(T t) A function that does nothing with the given argument.- Type Parameters:
T- the type of the argument- Parameters:
t- the argument to ignore
-
noopBoxedVoid
A function that returns a Void. -
noopBoxedVoid
A function that does nothing with the given argument.- Type Parameters:
T- the type of the argument- Parameters:
t- the argument to ignore
-
noop
public static <T,U> void noop(T t, U u) A function that does nothing with the given arguments.- Type Parameters:
T- the type of the first argumentU- the type of the second argument- Parameters:
t- the first argument to ignoreu- the second argument to ignore
-
constant
Returns a function that always returns the given constant value, regardless of its input.- Type Parameters:
A- the type of the input to the functionR- the type of the constant value to return- Parameters:
r- the constant value to return- Returns:
- a function that always returns the given constant value
-
constant2
Returns a function that always returns the given constant value, regardless of its input arguments.- Type Parameters:
A- the type of the first input argument to the functionB- the type of the second input argument to the functionR- the type of the constant value to return- Parameters:
r- the constant value to return- Returns:
- a function that always returns the given constant value
-
alwaysTrue
public static boolean alwaysTrue()A function that always returnstrue.- Returns:
- always
true
-
alwaysTrue
public static <T> boolean alwaysTrue(T t) A function that always returnstrue, regardless of the argument.- Type Parameters:
T- the type of the argument- Parameters:
t- the argument (ignored)- Returns:
- always
true
-
alwaysTrue
public static <T,U> boolean alwaysTrue(T t, U u) A function that always returnstrue, regardless of the argument.- Type Parameters:
T- the type of the argumentU- the type of the argument- Parameters:
t- the argument (ignored)u- the argument (ignored)- Returns:
- always
true
-
alwaysFalse
public static boolean alwaysFalse()A function that always returnsfalse.- Returns:
- always
false
-
alwaysFalse
public static <T> boolean alwaysFalse(T t) A function that always returnsfalse, regardless of the argument.- Type Parameters:
T- the type of the argument- Parameters:
t- the argument (ignored)- Returns:
- always
false
-
alwaysFalse
public static <T,U> boolean alwaysFalse(T t, U u) A function that always returnsfalse, regardless of the argument.- Type Parameters:
T- the type of the argumentU- the type of the argument- Parameters:
t- the argument (ignored)u- the argument (ignored)- Returns:
- always
false
-
alwaysFirst
public static <A,B> A alwaysFirst(A a, B b) Returns the first argument of typeA.- Parameters:
a- the first argument of typeAb- the second argument of typeB- Returns:
- the first argument of type
A
-
alwaysSecond
public static <A,B> B alwaysSecond(A a, B b) Returns the second argument of typeB.- Parameters:
a- the first argument of typeAb- the second argument of typeB- Returns:
- the second argument of type
B
-
identity
public static <T> T identity(T t) A function that returns its argument unchanged.- Type Parameters:
T- the type of the argument- Parameters:
t- the argument- Returns:
- the argument
-
negate
public static boolean negate(boolean b) Returns the logical negation of the boolean argument.- Parameters:
b- the boolean to negate- Returns:
- the negation of the boolean argument
-
negate
Returns a composed predicate that represents the logical negation of the given function. The resulting function returns true when the given function returns false and vice versa.- Type Parameters:
T- the type of the input to the function- Parameters:
predicate- the function to negate- Returns:
- a function that represents the logical negation of the given function
-
always1
Returns a function that always returns a constant value. The function takes one argument of typeA, but the value is ignored, and the constant value is returned instead.- Type Parameters:
A- the type of the argument (ignored)R- the type of the constant value- Parameters:
f- the supplier of the constant value- Returns:
- a function that always returns the constant value
-
always2
Returns a function that always returns a constant value. The function takes two arguments of typesAandB, but the values are ignored, and the constant value is returned instead.- Type Parameters:
A- the type of the first argument (ignored)B- the type of the second argument (ignored)R- the type of the constant value- Parameters:
f- the supplier of the constant value- Returns:
- a function that always returns the constant value
-