Class Option<T>
- java.lang.Object
-
- org.magicwerk.brownies.collections.helper.Option<T>
-
- Type Parameters:
T
- element type
public class Option<T> extends java.lang.Object
ClassOption
stores a single value which may also be null. This is different fromOptional
which does not support null values.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <EE> Option<EE>
empty()
boolean
equals(java.lang.Object obj)
T
getValue()
Returns stored value.T
getValueOrNull()
Returns stored value of null if no value is stored.int
hashCode()
boolean
hasValue()
Returns true if a value is stored, false otherwisestatic <T> Option<T>
of(T value)
java.lang.String
toString()
-
-
-
Constructor Detail
-
Option
private Option()
Prevent construction (use EMPTY)
-
Option
public Option(T value)
Construct option with specified value.- Parameters:
value
- value
-
-
Method Detail
-
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:
java.lang.IllegalArgumentException
- if no value is stored
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-