public final class OptionalDouble
extends java.lang.Object
double value.Optional| Modifier and Type | Method and Description |
|---|---|
<R> R |
custom(Function<OptionalDouble,R> function)
Applies custom operator on
OptionalDouble. |
static OptionalDouble |
empty()
Returns an empty
OptionalDouble instance. |
boolean |
equals(java.lang.Object obj) |
OptionalDouble |
executeIfAbsent(java.lang.Runnable action)
Invokes action function if value is absent.
|
OptionalDouble |
executeIfPresent(DoubleConsumer consumer)
Invokes consumer function with the value if present.
|
OptionalDouble |
filter(DoublePredicate predicate)
Performs filtering on inner value if it is present.
|
OptionalDouble |
filterNot(DoublePredicate predicate)
Performs negated filtering on inner value if it is present.
|
double |
getAsDouble()
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 |
isEmpty()
Checks the value is not present.
|
boolean |
isPresent()
Checks value present.
|
OptionalDouble |
map(DoubleUnaryOperator mapper)
Invokes the given mapping function on inner value if present.
|
OptionalInt |
mapToInt(DoubleToIntFunction mapper)
Invokes the given mapping function on inner value if present.
|
OptionalLong |
mapToLong(DoubleToLongFunction mapper)
Invokes the given mapping function on inner value if present.
|
<U> Optional<U> |
mapToObj(DoubleFunction<U> mapper)
Invokes the given mapping function on inner value if present.
|
static OptionalDouble |
of(double value)
Returns an
OptionalDouble with the specified value present. |
static OptionalDouble |
ofNullable(java.lang.Double value)
Returns an
OptionalDouble with the specified value, or empty OptionalDouble if value is null. |
OptionalDouble |
or(Supplier<OptionalDouble> supplier)
Returns current
OptionalDouble if value is present, otherwise
returns an OptionalDouble produced by supplier function. |
double |
orElse(double other)
Returns inner value if present, otherwise returns
other. |
double |
orElseGet(DoubleSupplier other)
Returns the value if present, otherwise returns value produced by supplier function.
|
double |
orElseThrow()
Returns inner value if present, otherwise throws
NoSuchElementException. |
<X extends java.lang.Throwable> |
orElseThrow(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() |
@NotNull public static OptionalDouble empty()
OptionalDouble instance.OptionalDouble@NotNull public static OptionalDouble of(double value)
OptionalDouble with the specified value present.value - the value to be presentOptionalDouble with the value present@NotNull public static OptionalDouble ofNullable(@Nullable java.lang.Double value)
OptionalDouble with the specified value, or empty OptionalDouble if value is null.value - the value which can be nullOptionalDoublepublic double getAsDouble()
NoSuchElementException.
Since 1.2.0 prefer orElseThrow() method as it has readable name.OptionalDoublejava.util.NoSuchElementException - if there is no value presentisPresent(),
orElseThrow()public boolean isPresent()
true if a value present, false otherwisepublic boolean isEmpty()
true if a value is not present, false otherwisepublic void ifPresent(@NotNull
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(@NotNull
DoubleConsumer consumer,
@NotNull
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.@NotNull public OptionalDouble executeIfPresent(@NotNull DoubleConsumer consumer)
ifPresent, but does not breaks chainingconsumer - consumer functionOptionalDoubleifPresent(com.annimon.stream.function.DoubleConsumer)@NotNull public OptionalDouble executeIfAbsent(@NotNull java.lang.Runnable action)
action - action that invokes if value absentOptionalDouble@Nullable
public <R> R custom(@NotNull
Function<OptionalDouble,R> function)
OptionalDouble.R - the type of the resultfunction - a transforming functionjava.lang.NullPointerException - if function is null@NotNull public OptionalDouble filter(@NotNull DoublePredicate predicate)
predicate - a predicate functionOptionalDouble if the value is present and matches predicate,
otherwise an empty OptionalDouble@NotNull public OptionalDouble filterNot(@NotNull DoublePredicate predicate)
predicate - a predicate functionOptionalDouble if the value is present and doesn't matches predicate,
otherwise an empty OptionalDouble@NotNull public OptionalDouble map(@NotNull DoubleUnaryOperator mapper)
mapper - mapping functionOptionalDouble with transformed value if present,
otherwise an empty OptionalDoublejava.lang.NullPointerException - if value is present and
mapper is null@NotNull public <U> Optional<U> mapToObj(@NotNull DoubleFunction<U> mapper)
U - the type of result valuemapper - mapping functionOptional with transformed value if present,
otherwise an empty Optionaljava.lang.NullPointerException - if value is present and
mapper is null@NotNull public OptionalInt mapToInt(@NotNull DoubleToIntFunction mapper)
mapper - mapping functionOptionalInt with transformed value if present,
otherwise an empty OptionalIntjava.lang.NullPointerException - if value is present and
mapper is null@NotNull public OptionalLong mapToLong(@NotNull DoubleToLongFunction mapper)
mapper - mapping functionOptionalLong with transformed value if present,
otherwise an empty OptionalLongjava.lang.NullPointerException - if value is present and
mapper is null@NotNull public DoubleStream stream()
DoubleStream if present,
otherwise returns an empty DoubleStream.DoubleStream@NotNull public OptionalDouble or(@NotNull Supplier<OptionalDouble> supplier)
OptionalDouble if value is present, otherwise
returns an OptionalDouble produced by supplier function.supplier - supplier function that produces an OptionalDouble to be returnedOptionalDouble if value is present, otherwise
an OptionalDouble produced by supplier functionjava.lang.NullPointerException - if value is not present and
supplier or value produced by it is nullpublic double orElse(double other)
other.other - the value to be returned if there is no value presentotherpublic double orElseGet(@NotNull
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 double orElseThrow()
NoSuchElementException.java.util.NoSuchElementException - if inner value is not presentpublic <X extends java.lang.Throwable> double orElseThrow(@NotNull
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.Throwablepublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object@NotNull public java.lang.String toString()
toString in class java.lang.Object