V - Value type.public class Value<V> extends Object implements Serializable
isPresent() will
return true and get() will return the value.
Additional methods that depend on the presence or absence of a contained value are provided, such as
getValueOrElse() (return a default value if value not present).
| Modifier | Constructor and Description |
|---|---|
protected |
Value()
Serializable constructor. |
protected |
Value(V value) |
| Modifier and Type | Method and Description |
|---|---|
static <V> Value<V> |
empty()
Returns an empty
Value instance. |
boolean |
equals(Object o) |
static <T extends V,V> |
from(Optional<T> optional)
|
static <T extends V,V> |
fromNullable(T value)
Creates a
Value from a value. |
V |
getValue()
If a value is present in this
Value, returns the value, otherwise throws NoSuchElementException. |
V |
getValueOrElse(V other)
Return the value if present, otherwise return
other. |
V |
getValueOrElseGet(Supplier<V> otherSupplier)
Return the value if present, otherwise invoke
other and return the result of that invocation. |
<X extends Throwable> |
getValueOrElseThrow(Supplier<? extends X> exceptionSupplier)
Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
|
int |
hashCode() |
boolean |
hasValue()
Return
true if there is a value present, otherwise false. |
void |
ifEmpty(Runnable runnable)
If no value is present, invoke the specified
Runnable, otherwise do nothing. |
void |
ifHasValue(Consumer<? super V> consumer)
If a value is present, invoke the specified
Consumer with the value, otherwise do nothing. |
static <T extends V,V> |
just(T value)
Creates a
Value from a value. |
<R> Value<R> |
map(Function<? super V,? extends R> mapper)
Returns a
Value consisting of the results of applying the given function to the value of this element. |
Optional<V> |
optional()
Returns an
Optional wrapper for the value. |
Stream<V> |
stream()
Returns a
Stream wrapper for the value. |
String |
toString() |
protected Value()
Serializable constructor.protected Value(V value)
value - the value, may be null.public static <T extends V,V> Value<V> from(Optional<T> optional)
Value from an Optional. The resulting value contains the value from the Optional if a
value is present. Value is empty if the Optional is empty.T - V - optional - the optional. May be empty but never null.Valuepublic static <T extends V,V> Value<V> fromNullable(T value)
T - V - value - the value. May be null.Valuepublic static <V> Value<V> empty()
Value instance. No value is present for this instance.V - Valuepublic static <T extends V,V> Value<V> just(T value)
Value from a value. The resulting value contains the value.T - V - value - the value. Must not be null.Valuepublic V getValue()
Value, returns the value, otherwise throws NoSuchElementException.OptionalNoSuchElementException - if there is no value presenthasValue()public boolean hasValue()
true if there is a value present, otherwise false.true if there is a value present, otherwise falsepublic V getValueOrElseGet(Supplier<V> otherSupplier)
other and return the result of that invocation.otherSupplier - a Supplier whose result is returned if no value is present. Must not be null.other.get()NullPointerException - if value is not present and other is nullpublic V getValueOrElse(V other)
other.other - the value to be returned if there is no value present, may be nullotherpublic <X extends Throwable> V getValueOrElseThrow(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 thrown, must not be null.X - if there is no value presentX extends Throwablepublic <R> Value<R> map(Function<? super V,? extends R> mapper)
Value consisting of the results of applying the given function to the value of this element. Mapping is
performed only if a value is present.R - The element type of the new valuemapper - a stateless function to apply to each elementValuepublic void ifHasValue(Consumer<? super V> consumer)
Consumer with the value, otherwise do nothing.consumer - block to be executed if a value is present, must not be null.public void ifEmpty(Runnable runnable)
Runnable, otherwise do nothing.runnable - block to be executed if no value value is present, must not be null.public Optional<V> optional()
Optional wrapper for the value.Optional wrapper for the value.public Stream<V> stream()
Stream wrapper for the value. The resulting stream contains either the value if a this value
has a value or it is empty if the value is empty.Stream wrapper for the value.Copyright © 2019 lettuce.io. All rights reserved.