| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear the value contained by this
Nullable. |
static <T> Nullable<T> |
empty()
Returns an empty
Nullable instance. |
boolean |
equals(Object other) |
Nullable<T> |
filter(Predicate<? super T> predicate)
If a value is present and it matches the given
predicate,
return a Nullable containing the value, otherwise return an
empty Nullable. |
<U> Nullable<U> |
flatMap(Function<? super T,Nullable<U>> mapper)
If a value is present, apply the
Nullable-bearing function to it,
return that result, otherwise return an empty Nullable. |
T |
get()
If a value is present in this
Nullable, returns the value,
otherwise throws NoSuchElementException. |
int |
hashCode() |
void |
ifPresent(Consumer<? super T> consumer)
Return true if a value is present, otherwise false.
|
boolean |
isPresent()
Return true if there is a value present, otherwise false.
|
<U> Nullable<U> |
map(Function<? super T,? extends U> mapper)
If a value is present, apply the provided mapping function to it and
return a
Nullable describing the result. |
static <T> Nullable<T> |
of(Optional<T> value)
Returns a
Nullable with the value of the specified
Optional if any or an empty Nullable otherwise. |
static <T> Nullable<T> |
of(T value)
Returns a
Nullable with the specified value. |
T |
orElse(T other)
Return the value if present, otherwise return
other. |
T |
orElseGet(Supplier<? extends T> other)
Return the value if present, otherwise invoke
other and return
the result of that invocation. |
<X extends Throwable> |
orElseThrow(Supplier<? extends X> exceptionSupplier)
Return the contained value, if present, otherwise throw an exception to
be created by the provided supplier.
|
void |
set(T elem)
Set a value to this
Nullable. |
String |
toString() |
public boolean isPresent()
public T get()
Nullable, returns the value,
otherwise throws NoSuchElementException.Nullable.NoSuchElementException - if there is no value present.Nullablepublic void set(T elem)
Nullable.elem - value to set.Nullablepublic void clear()
Nullable.Nullablepublic T orElse(T other)
other.other - the value to be returned if there is no value present.other.public T orElseGet(Supplier<? extends T> other)
other and return
the result of that invocation.other - a Supplier whose result is returned if no value is
present.other.get().NullPointerException - if value is not present and other
is null.public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X extends Throwable
X - type of exception to be thrown.exceptionSupplier - the supplier which will return the exception to
be thrown.X - if there is no value present.X extends Throwablepublic static <T> Nullable<T> empty()
Nullable instance. No value is present for this
Nullable.T - type of the non-existent value.Nullable.public static <T> Nullable<T> of(T value)
Nullable with the specified value.T - the class of value.value - the value to be present.Nullable with the value present.public static <T> Nullable<T> of(Optional<T> value)
Nullable with the value of the specified
Optional if any or an empty Nullable otherwise.public Nullable<T> filter(Predicate<? super T> predicate)
predicate,
return a Nullable containing the value, otherwise return an
empty Nullable.predicate - a predicate to apply to the value, if present.Nullable describing the value of this Nullable
if present and it matches the given predicate, otherwise an
empty Nullable.public <U> Nullable<U> flatMap(Function<? super T,Nullable<U>> mapper)
Nullable-bearing function to it,
return that result, otherwise return an empty Nullable.public void ifPresent(Consumer<? super T> consumer)
consumer - block to be executed if a value is present.Copyright © 2016. All rights reserved.