Class Either<T,U>

java.lang.Object
org.opendaylight.yangtools.concepts.Either<T,U>
Type Parameters:
T - First alternative type
U - Second alternative type
All Implemented Interfaces:
Immutable
Direct Known Subclasses:
CheckedValue

@Beta @NonNullByDefault public class Either<T,U> extends Object implements Immutable
Utility holder of a two-variant value. The class design treats both variants as equal.
Author:
Robert Varga
  • Constructor Details

    • Either

      protected Either(T first)
    • Either

      protected Either(U second, @Nullable Void dummy)
  • Method Details

    • first

      protected final T first()
    • second

      protected final U second()
    • ofFirst

      public static <T, U> Either<T,U> ofFirst(T value)
      Create a new instance containing specified value.
      Type Parameters:
      T - First alternative type
      U - Second alternative type
      Parameters:
      value - Value
      Returns:
      A new instance
      Throws:
      NullPointerException - if value is null
    • ofSecond

      public static <T, U> Either<T,U> ofSecond(U value)
      Create a new instance containing specified value.
      Type Parameters:
      T - First alternative type
      U - Second alternative type
      Parameters:
      value - Value
      Returns:
      A new instance
      Throws:
      NullPointerException - if value is null
    • isFirst

      public final boolean isFirst()
    • getFirst

      public final T getFirst()
    • tryFirst

      public final Optional<T> tryFirst()
    • isSecond

      public final boolean isSecond()
    • getSecond

      public final U getSecond()
    • trySecond

      public final Optional<U> trySecond()
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public final boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • addToString