Class If<I,O>
- java.lang.Object
-
- uk.gov.gchq.koryphe.function.KorypheFunction<I,O>
-
- uk.gov.gchq.koryphe.impl.function.If<I,O>
-
- Type Parameters:
I
- the type of input to be validated
- All Implemented Interfaces:
Function<I,O>
public class If<I,O> extends KorypheFunction<I,O>
AnIf
is aFunction
that conditionally applies one of two functions to a provided input.Note that the
If
has both a number of constructors as well as aSelectedBuilder
. The use case for constructors would generally be for testing a single input.The use case for the Builder allows greater flexibility, mainly for allowing multiple inputs such as an Array of objects, and control over which of these objects is tested by each function.
For example, Given an input array of 3 objects, one may wish to test the first object in the array against the initial predicate, then pass both the second and third objects to the resulting function, based on the outcome of the initial test. This would require use of the
This would look something like:Builder
, passing a selection of 0 along with the first predicate, and a selection of 1, 2 with the function.final If this = new If() .predicate(0, firstPredicate) .then(1, thenFunction, 2) .otherwise([1,2], otherwiseFunction, [2]);
-
-
Constructor Summary
Constructors Constructor Description If()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description O
apply(I input)
If the condition is not being used or has not been set, then the provided predicate will test the input (assuming it is also not null).If<I,O>
condition(boolean condition)
boolean
equals(Object obj)
Boolean
getCondition()
Function<? super I,O>
getOtherwise()
Predicate<? super I>
getPredicate()
Function<? super I,O>
getThen()
int
hashCode()
If<I,O>
otherwise(Integer[] selectionProjection, Function<?,?> then)
If<I,O>
otherwise(Integer[] selection, Function<?,?> then, Integer[] projection)
If<I,O>
otherwise(Integer selectionProjection, Function<?,?> then)
If<I,O>
otherwise(Integer selection, Function<?,?> then, Integer projection)
If<I,O>
otherwise(Function<?,?> otherwise)
If<I,O>
predicate(Integer[] selection, Predicate<?> predicate)
If<I,O>
predicate(Integer selection, Predicate<?> predicate)
If<I,O>
predicate(Predicate<?> predicate)
void
setCondition(boolean condition)
void
setOtherwise(Function<?,?> otherwise)
void
setPredicate(Predicate<?> predicate)
void
setThen(Function<?,?> then)
If<I,O>
then(Integer[] selectionProjection, Function<?,?> then)
If<I,O>
then(Integer[] selection, Function<?,?> then, Integer[] projection)
If<I,O>
then(Integer selectionProjection, Function<?,?> then)
If<I,O>
then(Integer selection, Function<?,?> then, Integer projection)
If<I,O>
then(Function<?,?> then)
String
toString()
-
-
-
Method Detail
-
apply
public O apply(I input)
If the condition is not being used or has not been set, then the provided predicate will test the input (assuming it is also not null). If this resolves to true, thethen
function will be applied the input, else theotherwise
function will be applied. The result of either of these being applied to the input is finally returned.- Parameters:
input
- the input to be tested- Returns:
- the result from the conditional functions
-
getCondition
public Boolean getCondition()
-
setCondition
public void setCondition(boolean condition)
-
setPredicate
public void setPredicate(Predicate<?> predicate)
-
setThen
public void setThen(Function<?,?> then)
-
setOtherwise
public void setOtherwise(Function<?,?> otherwise)
-
otherwise
public If<I,O> otherwise(Integer[] selection, Function<?,?> then, Integer[] projection)
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classKorypheFunction<I,O>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classKorypheFunction<I,O>
-
-