Optional that allows to change its value. This class is thread-safe. For an implementation that is not thread-safe, the class OutParameter is provided. It has the similar features as this mutable optional but without synchronized code.
| Modifier and type | Action and description |
|---|---|
| static MutableOptional<T> | empty
Returns an empty MutableOptional instance. |
| boolean | equals(Object)
Indicates whether some other object is "equal to" this Optional. |
| MutableOptional<T> | filter(Predicate<T>)
If a value is present, and the value matches the given predicate, returns an Optional describing the value, otherwise returns an empty MutableOptional. |
| MutableOptional<T> | flatMap(Function<T,R>)
If a value is present, returns the result of applying the given Optional-bearing mapping function to the value, otherwise returns an empty Optional. |
| T | get
If a value is present, returns the value, otherwise throws NoSuchElementException. |
| int | hashCode
Returns the hash code of the value, if present, otherwise 0 (zero) if no value is present. |
| void | ifPresent(Consumer<T>)
If a value is present, performs the given action with the value, otherwise does nothing. |
| void | ifPresentOrElse(Consumer<T>,Runnable)
If a value is present, performs the given action with the value, otherwise performs the given empty-based action. |
| boolean | isEmpty
If a value is not present, returns true, otherwise false. |
| boolean | isPresent
If a value is present, returns true, otherwise false. |
| MutableOptional<T> | map(Function<T,R>)
If a value is present, returns an MutableOptional describing the result of applying the given mapping function to the value, otherwise returns an empty Optional. |
| static MutableOptional<T> | of(T)
Returns an empty MutableOptional instance. |
| MutableOptional<T> | or(Supplier<T>)
If a value is present, returns an Optional describing the value, otherwise returns an Optional produced by the supplying function. |
| T | orElse(T)
If a value is present, returns the value, otherwise returns other. |
| T | orElseGet(Supplier<T>)
If a value is present, returns the value, otherwise returns the result produced by the supplying function. |
| T | orElseThrow
If a value is present, returns the value, otherwise throws NoSuchElementException. |
| T | orElseThrow(Supplier<T>)
If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function. |
| void | set(T)
Change the value stored in this MutableOptional. |
| java.lang.String | toString
Returns a non-empty string representation of this Optional suitable for debugging. |
def empty : MutableOptional<T>with T
MutableOptional instance. No value is present for this MutableOptional.
Though it may be tempting to do so, avoid testing if an object is empty by comparing with == or != against instances returned by Optional.empty(). There is no guarantee that it is a singleton. Instead, use isEmpty() or isPresent().
def equals(Object) : boolean
Optional. The other object is considered equal if:
def filter(Predicate<T>) : MutableOptional<T>
Optional describing the value, otherwise returns an empty MutableOptional.
def flatMap(Function<T,R>) : MutableOptional<T>with U
Optional-bearing mapping function to the value, otherwise returns an empty Optional.
This method is similar to map(Function), but the mapping function is one whose result is already an Optional, and if invoked, flatMap does not wrap it within an additional Optional.
def get : T
NoSuchElementException.
The preferred alternative to this method is orElseThrow().
def hashCode : int
0 (zero) if no value is present.
def ifPresent(Consumer<T>)
def ifPresentOrElse(Consumer<T>,Runnable)
def isEmpty : boolean
true, otherwise false.
def isPresent : boolean
true, otherwise false.
def map(Function<T,R>) : MutableOptional<T>with U
MutableOptional describing the result of applying the given mapping function to the value, otherwise returns an empty Optional.
If the mapping function returns a null result then this method returns an empty Optional.
This method supports post-processing on Optional values, without the need to explicitly check for a return status. For example, the following code traverses a stream of URIs, selects one that has not yet been processed, and creates a path from that URI, returning an MutableOptional<Path>:
br MutableOptional<Path> p =br uris.stream().filter(uri -> !isProcessedYet(uri))br .findFirst()br .map(Paths::get);br
Here, findFirst returns an MutableOptional<URI>, and then map returns an MutableOptional<Path> for the desired URI if one exists.
def of(T) : MutableOptional<T>with T
MutableOptional instance. No value is present for this MutableOptional.
Though it may be tempting to do so, avoid testing if an object is empty by comparing with == or != against instances returned by Optional.empty(). There is no guarantee that it is a singleton. Instead, use isEmpty() or isPresent().
def or(Supplier<T>) : MutableOptional<T>
Optional describing the value, otherwise returns an Optional produced by the supplying function.
def orElse(T) : T
other.
def orElseGet(Supplier<T>) : T
def orElseThrow : T
NoSuchElementException.
def orElseThrow(Supplier<T>) : Twith X extends java.lang.Throwable
throws X
IllegalStateException::new
def set(T)
MutableOptional.
def toString : java.lang.String
Optional suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions. If a value is present the result must include its string representation in the result. Empty and present Optionals must be unambiguously differentiable.