Class Either<L,R>
java.lang.Object
org.apache.druid.java.util.common.Either<L,R>
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 Summary
Modifier and TypeMethodDescriptionbooleanerror()Returns the error object.static <L,R> Either<L, R> error(L error) inthashCode()booleanisError()booleanisValue()Applies a function to this value, if present.toString()static <L,R> Either<L, R> value(R value) If this Either represents a value, returns it.
-
Method Details
-
error
-
value
-
isValue
public boolean isValue() -
isError
public boolean isError() -
error
Returns the error object.- Throws:
IllegalStateException- if this instance is not an error
-
valueOrThrow
If this Either represents a value, returns it. If this Either represents an error, throw an error. If the error is aDruidException, it is thrown. If it is some otherThrowable, it is wrapped in aDruidExceptionand thrown. If it is not a throwable, a genericDruidExceptionis thrown containing the string representation of the error object. To retrieve the error as-is, useisError()anderror()instead. -
map
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
-
hashCode
public int hashCode() -
toString
-