Package org.apache.thrift
Class Option<T>
- java.lang.Object
-
- org.apache.thrift.Option<T>
-
- Direct Known Subclasses:
Option.None,Option.Some
public abstract class Option<T> extends java.lang.ObjectImplementation of the Option type pattern
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOption.None<T>The None type, representing an absent value (instead of "null")static classOption.Some<T>The Some type, representing an existence of some value
-
Constructor Summary
Constructors Constructor Description Option()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <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 booleanisDefined()Whether the Option is defined or notstatic <T> Option.None<T>none()Tor(T other)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!
-
-
-
Method Detail
-
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
public abstract T get()
Get the value of the Option (if it is defined)- Returns:
- the value
- Throws:
java.lang.IllegalStateException- if called on a None
-
or
public T or(T other)
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
-
fromNullable
public static <T> Option<T> fromNullable(T value)
Wraps value in an Option type, depending on whether or not value is null- Type Parameters:
T- type of value- Parameters:
value-- Returns:
- Some(value) if value is not null, None if value is null
-
some
public static <T> Option.Some<T> some(T value)
Wrap value in a Some type (NB! value must not be null!)- Type Parameters:
T- type of value- Parameters:
value-- Returns:
- a new Some(value)
-
none
public static <T> Option.None<T> none()
-
-