Class Either<L,R>

java.lang.Object
org.fulib.fx.data.Either<L,R>

public class Either<L,R> extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    Either(L left, R right)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Returns the value of the present side.
    <T> T
    get(Class<T> type)
    Returns the value of the present side cast to the given type.
    @NotNull Optional<L>
    Returns the left value if present, otherwise null.
    @NotNull Optional<R>
    Returns the right value if present, otherwise null.
    boolean
    Returns whether the left value is present.
    boolean
    Returns whether the right value is present.
    static <L, R> Either<L,R>
    left(L left)
    Creates a new Either with the left value set.
    static <L, R> Either<L,R>
    right(R right)
    Creates a new Either with the right value set.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Either

      public Either(@Nullable L left, @Nullable R right)
  • Method Details

    • left

      public static <L, R> Either<L,R> left(L left)
      Creates a new Either with the left value set.
      Type Parameters:
      L - the type of the left value
      R - the type of the right value
      Parameters:
      left - the left value
      Returns:
      the new Either
    • right

      public static <L, R> Either<L,R> right(R right)
      Creates a new Either with the right value set.
      Type Parameters:
      L - the type of the left value
      R - the type of the right value
      Parameters:
      right - the right value
      Returns:
      the new Either
    • isLeft

      public boolean isLeft()
      Returns whether the left value is present.
      Returns:
      whether the left value is present
    • isRight

      public boolean isRight()
      Returns whether the right value is present.
      Returns:
      whether the right value is present
    • getLeft

      @NotNull public @NotNull Optional<L> getLeft()
      Returns the left value if present, otherwise null.
      Returns:
      the left value if present, otherwise null
    • getRight

      @NotNull public @NotNull Optional<R> getRight()
      Returns the right value if present, otherwise null.
      Returns:
      the right value if present, otherwise null
    • get

      public Object get()
      Returns the value of the present side.
      Returns:
      the value of the present side
    • get

      public <T> T get(Class<T> type)
      Returns the value of the present side cast to the given type.
      Type Parameters:
      T - the type of the value
      Parameters:
      type - the type of the value
      Returns:
      the value of the present side
      Throws:
      ClassCastException - if the value is not of the given type
    • toString

      public String toString()
      Overrides:
      toString in class Object