public final class OptionalDouble
extends java.lang.Object
double
value.Optional
Modifier and Type | Method and Description |
---|---|
static OptionalDouble |
empty()
Returns an empty
OptionalDouble instance. |
boolean |
equals(java.lang.Object obj) |
double |
get()
Returns an inner value if present, otherwise throws
NoSuchElementException . |
int |
hashCode() |
void |
ifPresent(DoubleConsumer consumer)
Invokes consumer function with value if present, otherwise does nothing.
|
void |
ifPresentOrElse(DoubleConsumer consumer,
java.lang.Runnable emptyAction)
If a value is present, performs the given action with the value,
otherwise performs the empty-based action.
|
boolean |
isPresent()
Checks value present.
|
static OptionalDouble |
of(double value)
Returns an
OptionalDouble with the specified value present. |
double |
or(double other)
Returns inner value if present, otherwise returns
other . |
double |
orGet(DoubleSupplier other)
Returns the value if present, otherwise returns value produced by supplier function.
|
<X extends java.lang.Throwable> |
orThrow(Supplier<X> exceptionSupplier)
Returns the value if present, otherwise throws an exception provided by supplier function.
|
DoubleStream |
stream()
Wraps a value into
DoubleStream if present,
otherwise returns an empty DoubleStream . |
java.lang.String |
toString() |
public static OptionalDouble empty()
OptionalDouble
instance.OptionalDouble
public static OptionalDouble of(double value)
OptionalDouble
with the specified value present.value
- the value to be presentOptionalDouble
with the value presentpublic double get()
NoSuchElementException
.OptionalDouble
java.util.NoSuchElementException
- if there is no value presentisPresent()
public boolean isPresent()
true
if a value present, false
otherwisepublic void ifPresent(DoubleConsumer consumer)
consumer
- the consumer function to be executed if a value is presentjava.lang.NullPointerException
- if value is present and consumer
is nullpublic void ifPresentOrElse(DoubleConsumer consumer, java.lang.Runnable emptyAction)
consumer
- the consumer function to be executed, if a value is presentemptyAction
- the empty-based action to be performed, if no value is presentjava.lang.NullPointerException
- if a value is present and the given consumer function is null,
or no value is present and the given empty-based action is null.public DoubleStream stream()
DoubleStream
if present,
otherwise returns an empty DoubleStream
.DoubleStream
public double or(double other)
other
.other
- the value to be returned if there is no value presentother
public double orGet(DoubleSupplier other)
other
- supplier function that produces value if inner value is not presentother.getAsDouble()
java.lang.NullPointerException
- if value is not present and other
is nullpublic <X extends java.lang.Throwable> double orThrow(Supplier<X> exceptionSupplier) throws X extends java.lang.Throwable
X
- the type of exception to be thrownexceptionSupplier
- supplier function that produces an exception to be thrownX
- if inner value is not presentX extends java.lang.Throwable
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object