public final class Option<T> extends Object implements Serializable
| Modifier and Type | Method and Description |
|---|---|
static <T> Option<T> |
empty() |
boolean |
equals(Object o) |
<U> Option<U> |
flatMap(Function<? super T,Option<U>> mapper) |
static <T> Option<T> |
fromJavaOptional(Optional<T> v)
Convert from java.util.Optional.
|
T |
get() |
int |
hashCode() |
void |
ifPresent(Consumer<? super T> consumer) |
boolean |
isEmpty() |
boolean |
isPresent() |
<U> Option<U> |
map(Function<? super T,? extends U> mapper) |
static <T> Option<T> |
of(T value) |
static <T> Option<T> |
ofNullable(T value) |
Option<T> |
or(Option<T> other)
Returns this
Option if not empty, otherwise returns an alternative |
Option<T> |
or(Supplier<? extends Option<T>> other)
Returns this
Option if not empty, otherwise evaluates provided supplier
and returns its result |
T |
orElse(T other)
Identical to
Optional.orElse |
T |
orElseGet(Supplier<? extends T> other)
Identical to
Optional.orElseGet |
<X extends Throwable> |
orElseThrow(Supplier<? extends X> exceptionSupplier)
Identical to
Optional.orElseThrow |
Optional<T> |
toJavaOptional()
Convert to java Optional.
|
String |
toString() |
public static <T> Option<T> fromJavaOptional(Optional<T> v)
T - type of the value stored in java.util.Optional objectv - java.util.Optional objectpublic static <T> Option<T> empty()
public static <T> Option<T> of(T value)
public static <T> Option<T> ofNullable(T value)
public boolean isPresent()
public boolean isEmpty()
public T get()
public Option<T> or(Option<T> other)
Option if not empty, otherwise returns an alternativepublic Option<T> or(Supplier<? extends Option<T>> other)
Option if not empty, otherwise evaluates provided supplier
and returns its resultpublic <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X extends Throwable
Optional.orElseThrowX extends ThrowableCopyright © 2024 The Apache Software Foundation. All rights reserved.