java.util.Optional .
Option is a monadic container type which
represents an optional value. Instances of Option are either an instance of Some or the
singleton None.
Most of the API is taken from java.. A similar type can be found in Haskell and Scala.
| Modifier and Type | Class and Description |
|---|---|
| public static class | Option.
The type of the optional value. T>None is a singleton representation of the undefined |
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| public static final long |
| Modifier and Type | Method and Description |
|---|---|
| public default < The new value type R> Option | Returns: A newOption instance containing value of type RA function that is not necessarily defined on value of this option. partialFunction)Collects value that is in the domain of the given |
| public boolean | equals(Object
An object o)Redeclares io. Clarifies that values have a proper equals() method implemented. |
| public default Option | |
| public default < Component type of the resulting Option U> Option | |
| public default < type of the folded value U> U | |
| public T | Returns: the valueRedeclares io. Gets the value if this is a |
| public default T | Returns: This value, if this Option is defined or theother value, if this Option is empty.An alternative value other)Overrides default io. Returns the value if this is a |
| public default T | Returns: This value, if this Option is defined or theother value, if this Option is empty.An alternative value supplier supplier)Overrides default io. Returns the value if this is a |
| public default < A throwable X extends Throwable> T | Returns: This value, if this Option is defined, otherwise throws XAn exception supplier exceptionSupplier)Overrides default io. Returns the value if this is a |
| public int | hashCode()
Redeclares io. Clarifies that values have a proper hashCode() method implemented. |
| public default boolean | Returns: falseImplements io. An |
| public default boolean | Returns: true, if thisOption has a defined value, false otherwiseReturns true, if this is |
| public boolean | Returns: true, if thisOption is empty, false otherwiseRedeclares io. Returns true, if this is |
| public default boolean | |
| public default boolean | |
| public default Iterator | |
| public default < The new value type U> Option | Returns: a newSome containing the mapped value if this Option is defined, otherwise None, if this is empty.A value mapper mapper)Implements io. Maps the value and wraps it in a new |
| public static < Component type of the T> OptionOption. | |
| public static < component type T> Option | |
| public static < type of the value T> Option | Returns: Some(value) if value is not null, None otherwiseA value value)Creates a new |
| public static < type of the value T> Option | Returns: Some(optional.get()) if value is Java Optional is present, None otherwisea given optional to wrap in optional)OptionWraps a Java Optional to a new Option |
| public default Option | |
| public default Option | |
| public default Option | |
| public default Option | Returns: thisOptionAn action which can be applied to an optional value action)Implements io. Applies an action to this value, if this option is defined, otherwise does nothing. |
| public static < type of the Options T> Option | |
| public static < type of the value T> Option | |
| public String | toString()
Redeclares io. Clarifies that values have a proper toString() method implemented. |
| public default < Type of transformation result U> U | |
| public static < The type of the given values. T, The mapped value type. U> Option | |
| public static < type of the optional value T> Option | |
| public static < type of the optional value T> Option | Returns: returnSome of value if condition is true, or None in other caseA boolean value condition, T An optional value, may be value)nullCreates |
| serialVersionUID | back to summary |
|---|---|
| public static final long serialVersionUID | |
| collect | back to summary |
|---|---|
| public default <R> Option Collects value that is in the domain of the given
If the element makes it through that filter, the mapped instance is wrapped in Option
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Redeclares io. Doc from io. Clarifies that values have a proper equals() method implemented. | |
| filter | back to summary |
|---|---|
| public default Option Returns | |
| flatMap | back to summary |
|---|---|
| public default <U> Option Maps the value to a new
| |
| fold | back to summary |
|---|---|
| public default <U> U fold(Supplier<? extends U> ifNone, Function<? super T, ? extends U> f) Folds either the | |
| get | back to summary |
|---|---|
| public T get() Redeclares io. Gets the value if this is a
| |
| getOrElse | back to summary |
|---|---|
| public default T getOrElse(T other) Overrides default io. Returns the value if this is a Please note, that the other value is eagerly evaluated.
| |
| getOrElse | back to summary |
|---|---|
| public default T getOrElse(Supplier<? extends T> supplier) Overrides default io. Returns the value if this is a Please note, that the other value is lazily evaluated. | |
| getOrElseThrow | back to summary |
|---|---|
| public default <X extends Throwable> T getOrElseThrow(Supplier<X> exceptionSupplier) throws Supplier-:X Overrides default io. Returns the value if this is a
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Redeclares io. Doc from io. Clarifies that values have a proper hashCode() method implemented. See Object.hashCode().
| |
| isAsync | back to summary |
|---|---|
| public default boolean isAsync() Implements io. An
| |
| isDefined | back to summary |
|---|---|
| public default boolean isDefined() Returns true, if this is
Please note that it is possible to create
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Redeclares io. Returns true, if this is
| |
| isLazy | back to summary |
|---|---|
| public default boolean isLazy() Implements io. An
| |
| isSingleValued | back to summary |
|---|---|
| public default boolean isSingleValued() Implements io. An
| |
| iterator | back to summary |
|---|---|
| public default Iterator Implements io. Doc from io. Returns a rich | |
| map | back to summary |
|---|---|
| public default <U> Option Implements io. Maps the value and wraps it in a new | |
| narrow | back to summary |
|---|---|
| public static <T> Option Narrows a widened
| |
| none | back to summary |
|---|---|
| public static <T> Option Returns the single instance of
| |
| of | back to summary |
|---|---|
| public static <T> Option Creates a new
| |
| ofOptional | back to summary |
|---|---|
| public static <T> Option Wraps a Java Optional to a new Option
| |
| onEmpty | back to summary |
|---|---|
| public default Option Runs a Java Runnable passed as parameter if this | |
| orElse | back to summary |
|---|---|
| public default Option Returns this
| |
| orElse | back to summary |
|---|---|
| public default Option Returns this
| |
| peek | back to summary |
|---|---|
| public default Option Implements io. Applies an action to this value, if this option is defined, otherwise does nothing. | |
| sequence | back to summary |
|---|---|
| public static <T> Option Reduces many | |
| some | back to summary |
|---|---|
| public static <T> Option Creates a new
The only difference to
| |
| toString | back to summary |
|---|---|
| public String toString() Redeclares io. Doc from io. Clarifies that values have a proper toString() method implemented. See Object.toString(). | |
| transform | back to summary |
|---|---|
| public default <U> U transform(Function<? super Option<T>, ? extends U> f) Transforms this
| |
| traverse | back to summary |
|---|---|
| public static <T, U> Option Maps the values of an iterable to a sequence of mapped values into a single
| |
| when | back to summary |
|---|---|
| public static <T> Option Creates
| |
| when | back to summary |
|---|---|
| public static <T> Option Creates
| |
Option.
| Modifier and Type | Field and Description |
|---|---|
| private static final Option. | INSTANCE
The singleton instance of None. |
| private static final long |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
An object o)Overrides java. Implements io. Clarifies that values have a proper equals() method implemented. |
| public T | get()
Implements io. Gets the value if this is a |
| public int | hashCode()
Overrides java. Implements io. Clarifies that values have a proper hashCode() method implemented. |
| public boolean | isEmpty()
Implements io. Returns true, if this is |
| private Object | |
| public String | stringPrefix()
Implements io. Returns the name of this Value type, which is used by toString(). |
| public String | toString()
Overrides java. Implements io. Clarifies that values have a proper toString() method implemented. |
| INSTANCE | back to summary |
|---|---|
| private static final Option. The singleton instance of None. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| None | back to summary |
|---|---|
| private None() Hidden constructor. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Implements io. Doc from io. Clarifies that values have a proper equals() method implemented. | |
| get | back to summary |
|---|---|
| public T get() Implements io. Doc from io. Gets the value if this is a
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements io. Doc from io. Clarifies that values have a proper hashCode() method implemented. See Object.hashCode().
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements io. Doc from io. Returns true, if this is
| |
| readResolve | back to summary |
|---|---|
| private Object readResolve() Instance control for object serialization.
| |
| stringPrefix | back to summary |
|---|---|
| public String stringPrefix() Implements io. Doc from io. Returns the name of this Value type, which is used by toString(). | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Implements io. Doc from io. Clarifies that values have a proper toString() method implemented. See Object.toString(). | |
Option. It contains a value which may be null. However, to
create an Option containing null, new Some(null) has to be called. In all other cases
Option#of(Object) is sufficient.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | |
| private final T |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
An object obj)Overrides java. Implements io. Clarifies that values have a proper equals() method implemented. |
| public T | get()
Implements io. Gets the value if this is a |
| public int | hashCode()
Overrides java. Implements io. Clarifies that values have a proper hashCode() method implemented. |
| public boolean | isEmpty()
Implements io. Returns true, if this is |
| public String | stringPrefix()
Implements io. Returns the name of this Value type, which is used by toString(). |
| public String | toString()
Overrides java. Implements io. Clarifies that values have a proper toString() method implemented. |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| value | back to summary |
|---|---|
private final T value
| |
| Some | back to summary |
|---|---|
| private Some(T value) Creates a new Some containing the given value.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Implements io. Doc from io. Clarifies that values have a proper equals() method implemented. | |
| get | back to summary |
|---|---|
| public T get() Implements io. Doc from io. Gets the value if this is a
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements io. Doc from io. Clarifies that values have a proper hashCode() method implemented. See Object.hashCode().
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements io. Doc from io. Returns true, if this is
| |
| stringPrefix | back to summary |
|---|---|
| public String stringPrefix() Implements io. Doc from io. Returns the name of this Value type, which is used by toString(). | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Implements io. Doc from io. Clarifies that values have a proper toString() method implemented. See Object.toString(). | |