Class Option<T>

java.lang.Object
org.apache.thrift.Option<T>
Direct Known Subclasses:
Option.None, Option.Some

public abstract class Option<T> extends Object
Implementation of the Option type pattern
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The None type, representing an absent value (instead of "null")
    static class 
    The Some type, representing an existence of some value
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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 null
    abstract T
    get()
    Get the value of the Option (if it is defined)
    abstract boolean
    Whether the Option is defined or not
    static <T> Option.None<T>
     
    or(T other)
    Get the contained value (if defined) or else return a default value
    static <T> Option.Some<T>
    some(T value)
    Wrap value in a Some type (NB!
    Turn this Option into Java 8 Optional type

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public abstract T get()
      Get the value of the Option (if it is defined)
      Returns:
      the value
      Throws:
      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
    • toOptional

      public Optional<T> toOptional()
      Turn this Option into Java 8 Optional type
      Returns:
      Java 8+ Optional Type
    • 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 - 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

      public static <T> Option.Some<T> some(T value)
      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

      public static <T> Option.None<T> none()