T - - type of wrapped valuepublic class Option<T> extends Object
null.| Modifier and Type | Method and Description |
|---|---|
static <T> Option<T> |
absent()
Creates a new option that does not hold any value.
|
boolean |
equals(Object o) |
T |
get()
Retrieves wrapped value.
|
int |
hashCode() |
void |
ifPresent(Procedure<T> proc)
Executes
Procedure if this option has value. |
boolean |
isPresent() |
<K> Option<K> |
map(Func<K,T> transform)
If this option is not empty, its value is transformed with the given Function; otherwise, absent() is returned.
|
static <T> Option<T> |
of(T value)
Creates a new option from supplied value.
|
T |
or(T alternative)
Returns wrapped value, if this Option is not absent or supplied alternative otherwise.
|
T |
orGet(Provider<T> provider)
Returns wrapped value if this Option is not absent, otherwise calls supplied
Provider to calculate a new
value. |
T |
orNull() |
String |
toString() |
public static <T> Option<T> absent()
T - Type of optional value.public static <T> Option<T> of(T value)
T - Type of optional value.value - Value to wrap into Optionpublic boolean isPresent()
true if this Option is not absent, or false otherwise.public void ifPresent(Procedure<T> proc)
Procedure if this option has value.proc - Procedure that accepts parameter of the type of the Optionpublic T or(T alternative)
alternative - Alternative value to return if this Option is absent.public T orGet(Provider<T> provider)
Provider to calculate a new
value.provider - Provider to create an alternative value/public T orNull()
public T get()
NullPointerException will be thrown.NullPointerException - if Option is empty.public <K> Option<K> map(Func<K,T> transform)
If function throws exception, absent() will be returned.
K - Type of the new valuetransform - Function Func to transform value from one type to another.Copyright © 2018. All rights reserved.