Package org.forgerock.openig.util
Class Choice<V1,V2>
java.lang.Object
org.forgerock.openig.util.Choice<V1,V2>
- Type Parameters:
V1- type of the first choiceV2- type of the second choice
Class enabling clients to choose (set) a value from a choice of two possible types, and conduct later processing
based on the chosen type.
-
Method Summary
Modifier and TypeMethodDescription<R,E extends Exception>
RApply a function to the chosen value.applyAsync(AsyncFunction<V1, R, E> v1AsyncFunction, AsyncFunction<V2, R, E> v2AsyncFunction) Apply an asynchronous function to the chosen value.static <V1,V2> Choice<V1, V2> withValue1(V1 value) Choose a value with typeV1.static <V1,V2> Choice<V1, V2> withValue2(V2 value) Choose a value with typeV2.
-
Method Details
-
withValue1
Choose a value with typeV1.- Type Parameters:
V1- type of first choiceV2- type of second choice, whose value will remain unset in this case- Parameters:
value- The value chosen- Returns:
- a
Choiceinstance with value of typeV1chosen
-
withValue2
Choose a value with typeV2.- Type Parameters:
V1- type of first choice, whose value will remain unset in this caseV2- type of second choice- Parameters:
value- The value chosen- Returns:
- a
Choiceinstance with value of typeV2chosen
-
apply
public <R,E extends Exception> R apply(Function<V1, R, throws EE> v1Function, Function<V2, R, E> v2Function) Apply a function to the chosen value. If the chosen value is of typeV1thenv1Functionis applied, or if the chosen value is of typeV2thenv2Functionis applied instead.- Type Parameters:
R- the expected return typeE- possible exception type- Parameters:
v1Function- function to apply if chosen value is of typeV1v2Function- function to apply if chosen value is of typeV2- Returns:
Rresulting from applying the respective function- Throws:
E- in accordance withFunction.apply(Object)
-
applyAsync
public <R,E extends Exception> Promise<R,E> applyAsync(AsyncFunction<V1, R, throws EE> v1AsyncFunction, AsyncFunction<V2, R, E> v2AsyncFunction) Apply an asynchronous function to the chosen value. If the chosen value is of typeV1thenv1AsyncFunctionis applied, or if the chosen value is of typeV2thenv2AsyncFunctionis applied instead.- Type Parameters:
R- the expected return typeE- possible exception type- Parameters:
v1AsyncFunction- function to apply if chosen value is of typeV1v2AsyncFunction- function to apply if chosen value is of typeV2- Returns:
Promiseof typeRresulting from applying the respective function- Throws:
E- in accordance withAsyncFunction.apply(Object)
-