java.lang.Object
org.magicwerk.brownies.collections.helper.Option<T>
Type Parameters:
T - element type

public class Option<T> extends Object
Class Option stores a single value which may also be null. This is different from Optional which does not support null values.
  • Field Details

    • EMPTY

      private static final Option EMPTY
    • hasValue

      private boolean hasValue
    • value

      private T value
  • Constructor Details

    • Option

      private Option()
      Prevent construction (use EMPTY)
    • Option

      public Option(T value)
      Construct option with specified value.
      Parameters:
      value - value
  • Method Details

    • empty

      public static <EE> Option<EE> empty()
      Returns:
      unmodifiable empty instance
    • of

      public static <T> Option<T> of(T value)
    • hasValue

      public boolean hasValue()
      Returns true if a value is stored, false otherwise
    • getValueOrNull

      public T getValueOrNull()
      Returns stored value of null if no value is stored. It is therefore not possible to distinguish between a null value stored or no value stored.
    • getValue

      public T getValue()
      Returns stored value. If no value is stored, an exception is thrown.
      Returns:
      stored value
      Throws:
      IllegalArgumentException - if no value is stored
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object