Package org.apache.thrift
Class Option<T>
java.lang.Object
org.apache.thrift.Option<T>
- Direct Known Subclasses:
Option.None,Option.Some
Implementation of the Option type pattern
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe None type, representing an absent value (instead of "null")static classThe Some type, representing an existence of some value -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Option<T>fromNullable(T value) Wraps value in an Option type, depending on whether or not value is nullabstract Tget()Get the value of the Option (if it is defined)abstract booleanWhether the Option is defined or notstatic <T> Option.None<T>none()Get the contained value (if defined) or else return a default valuestatic <T> Option.Some<T>some(T value) Wrap value in a Some type (NB!Turn this Option into Java 8 Optional type
-
Constructor Details
-
Option
public Option()
-
-
Method Details
-
isDefined
public abstract boolean isDefined()Whether the Option is defined or not- Returns:
- true if the Option is defined (of type Some) false if the Option is not defined (of type None)
-
get
Get the value of the Option (if it is defined)- Returns:
- the value
- Throws:
IllegalStateException- if called on a None
-
or
Get the contained value (if defined) or else return a default value- Parameters:
other- what to return if the value is not defined (a None)- Returns:
- either the value, or other if the value is not defined
-
toOptional
Turn this Option into Java 8 Optional type- Returns:
- Java 8+ Optional Type
-
fromNullable
Wraps value in an Option type, depending on whether or not value is null- Type Parameters:
T- the type of value- Parameters:
value- the value to wrap in Option- Returns:
- Some(value) if value is not null, None if value is null
-
some
Wrap value in a Some type (NB! value must not be null!)- Type Parameters:
T- the type of value- Parameters:
value- the value to wrap.- Returns:
- a new Some(value)
-
none
-