Class Either<L,R>

java.lang.Object
org.apache.druid.java.util.common.Either<L,R>

public class Either<L,R> extends Object
Encapsulates either an "error" or a "value". Similar to the Either class in Scala or Haskell, except the possibilities are named "error" and "value" instead of "left" and "right".
  • Method Details

    • error

      public static <L, R> Either<L,R> error(L error)
    • value

      public static <L, R> Either<L,R> value(@Nullable R value)
    • isValue

      public boolean isValue()
    • isError

      public boolean isError()
    • error

      public L error()
      Returns the error object.
      Throws:
      IllegalStateException - if this instance is not an error
    • valueOrThrow

      @Nullable public R valueOrThrow()
      If this Either represents a value, returns it. If this Either represents an error, throw an error. If the error is a DruidException, it is thrown. If it is some other Throwable, it is wrapped in a DruidException and thrown. If it is not a throwable, a generic DruidException is thrown containing the string representation of the error object. To retrieve the error as-is, use isError() and error() instead.
    • map

      public <T> Either<L,T> map(Function<R,T> fn)
      Applies a function to this value, if present. If the mapping function throws an exception, it is thrown by this method instead of being packed up into the returned Either. If this Either represents an error, the mapping function is not applied.
      Throws:
      NullPointerException - if the mapping function returns null
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object