Class Choice<V1,V2>

java.lang.Object
org.forgerock.openig.util.Choice<V1,V2>
Type Parameters:
V1 - type of the first choice
V2 - type of the second choice

public final class Choice<V1,V2> extends Object
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 Details

    • withValue1

      public static <V1, V2> Choice<V1,V2> withValue1(V1 value)
      Choose a value with type V1.
      Type Parameters:
      V1 - type of first choice
      V2 - type of second choice, whose value will remain unset in this case
      Parameters:
      value - The value chosen
      Returns:
      a Choice instance with value of type V1 chosen
    • withValue2

      public static <V1, V2> Choice<V1,V2> withValue2(V2 value)
      Choose a value with type V2.
      Type Parameters:
      V1 - type of first choice, whose value will remain unset in this case
      V2 - type of second choice
      Parameters:
      value - The value chosen
      Returns:
      a Choice instance with value of type V2 chosen
    • apply

      public <R, E extends Exception> R apply(Function<V1,R,E> v1Function, Function<V2,R,E> v2Function) throws E
      Apply a function to the chosen value. If the chosen value is of type V1 then v1Function is applied, or if the chosen value is of type V2 then v2Function is applied instead.
      Type Parameters:
      R - the expected return type
      E - possible exception type
      Parameters:
      v1Function - function to apply if chosen value is of type V1
      v2Function - function to apply if chosen value is of type V2
      Returns:
      R resulting from applying the respective function
      Throws:
      E - in accordance with Function.apply(Object)
    • applyAsync

      public <R, E extends Exception> Promise<R,E> applyAsync(AsyncFunction<V1,R,E> v1AsyncFunction, AsyncFunction<V2,R,E> v2AsyncFunction) throws E
      Apply an asynchronous function to the chosen value. If the chosen value is of type V1 then v1AsyncFunction is applied, or if the chosen value is of type V2 then v2AsyncFunction is applied instead.
      Type Parameters:
      R - the expected return type
      E - possible exception type
      Parameters:
      v1AsyncFunction - function to apply if chosen value is of type V1
      v2AsyncFunction - function to apply if chosen value is of type V2
      Returns:
      Promise of type R resulting from applying the respective function
      Throws:
      E - in accordance with AsyncFunction.apply(Object)