| Modifier and Type | Method and Description |
|---|---|
Optional<T> |
asOptional()
If a value is present in this
NullableOptional, returns the result
of passing the value to Optional.ofNullable(Object). |
static <T> NullableOptional<T> |
empty()
Returns an empty
NullableOptional instance. |
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this NullableOptional.
|
NullableOptional<T> |
filter(Predicate<? super T> predicate)
If a value is present, and the value matches the given predicate,
return an
NullableOptional describing the value, otherwise return an
empty NullableOptional. |
<U> NullableOptional<U> |
flatMap(Function<? super T,NullableOptional<U>> mapper)
If a value is present, apply the provided
NullableOptional-bearing
mapping function to it, return that result, otherwise return an empty
NullableOptional. |
static <T> NullableOptional<T> |
fromOptional(Optional<T> value)
Returns a
NullableOptional describing the specified optional. |
T |
get()
If a value is present in this
NullableOptional, returns the value,
otherwise throws NoSuchElementException. |
int |
hashCode()
Returns the hash code value of the present value, if any, or -1 if
no value is present.
|
void |
ifPresent(Consumer<? super T> consumer)
If a value is present, invoke the specified consumer with the value,
otherwise do nothing.
|
boolean |
isPresent()
Return
true if there is a value present, otherwise false. |
<U> NullableOptional<U> |
map(Function<? super T,? extends U> mapper)
If a value is present, apply the provided mapping function to it,
and return an
NullableOptional describing the
result. |
static <T> NullableOptional<T> |
of(T value)
Returns a
NullableOptional with the specified present 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.
|
String |
toString()
Returns a non-empty string representation of this NullableOptional suitable for
debugging.
|
@Nonnull public static <T> NullableOptional<T> empty()
NullableOptional instance. No value is present for this
NullableOptional.T - Type of the non-existent valueNullableOptional@Nonnull public static <T> NullableOptional<T> of(@Nullable T value)
NullableOptional with the specified present value.T - the class of the valuevalue - the value to be presentNullableOptional with the value present@Nonnull public static <T> NullableOptional<T> fromOptional(@Nonnull Optional<T> value)
NullableOptional describing the specified optional.T - the class of the valuevalue - the possibly-empty value to describeNullableOptional with a present value if the specified value
is present, otherwise an empty NullableOptional@Nullable public T get()
NullableOptional, returns the value,
otherwise throws NoSuchElementException.NullableOptionalNoSuchElementException - if there is no value presentisPresent()@Nonnull public Optional<T> asOptional()
NullableOptional, returns the result
of passing the value to Optional.ofNullable(Object). Otherwise returns
an empty optional.Optional representing the value held by this NullableOptionalOptional.ofNullable(Object)public boolean isPresent()
true if there is a value present, otherwise false.true if there is a value present, otherwise falsepublic void ifPresent(@Nonnull Consumer<? super T> consumer)
consumer - block to be executed if a value is presentNullPointerException - if value is present and consumer is
null@Nonnull public NullableOptional<T> filter(@Nonnull Predicate<? super T> predicate)
NullableOptional describing the value, otherwise return an
empty NullableOptional.predicate - a predicate to apply to the value, if presentNullableOptional describing the value of this NullableOptional
if a value is present and the value matches the given predicate,
otherwise an empty NullableOptionalNullPointerException - if the predicate is null@Nonnull public <U> NullableOptional<U> map(@Nonnull Function<? super T,? extends U> mapper)
NullableOptional describing the
result. Otherwise return an empty NullableOptional.U - The type of the result of the mapping functionmapper - a mapping function to apply to the value, if presentNullableOptional describing the result of applying a mapping
function to the value of this NullableOptional, if a value is present,
otherwise an empty NullableOptionalNullPointerException - if the mapping function is null@Nonnull public <U> NullableOptional<U> flatMap(@Nonnull Function<? super T,NullableOptional<U>> mapper)
NullableOptional-bearing
mapping function to it, return that result, otherwise return an empty
NullableOptional. This method is similar to map(Function),
but the provided mapper is one whose result is already an NullableOptional,
and if invoked, flatMap does not wrap it with an additional
NullableOptional.U - The type parameter to the NullableOptional returned bymapper - a mapping function to apply to the value, if present
the mapping functionNullableOptional-bearing mapping
function to the value of this NullableOptional, if a value is present,
otherwise an empty NullableOptionalNullPointerException - if the mapping function is null or returns
a null result@Nullable public T orElse(@Nullable T other)
other.other - the value to be returned if there is no value present, may
be nullother@Nullable public T orElseGet(@Nonnull Supplier<? extends T> other)
other and return
the result of that invocation.other - a Supplier whose result is returned if no value
is presentother.get()NullPointerException - if value is not present and other is
null@Nullable public <X extends Throwable> T orElseThrow(@Nonnull Supplier<? extends X> exceptionSupplier) throws X extends Throwable
X - Type of the exception to be thrownexceptionSupplier - The supplier which will return the exception to
be thrownX - if there is no value presentNullPointerException - if no value is present and
exceptionSupplier is nullX extends Throwablepublic boolean equals(Object obj)
NullableOptional and;
equals().
public int hashCode()
hashCode in class ObjectObjects.hashCode(Object)Copyright © 2022. All rights reserved.