public final class OptionalDoubleExtensions extends Object
OptionalDouble
.
import static extension de.fhg.fokus.xtenders.optional.OptionalDoubleExtensions.*
OptionalExtensions
,
OptionalIntExtensions
,
OptionalLongExtensions
Modifier and Type | Method and Description |
---|---|
static @NonNull DoubleIterable |
asIterable(@NonNull OptionalDouble self)
Returns a
DoubleIterable that either provides the one value present in self ,
or an DoubleIterable providing no value if self is empty. |
static @NonNull Optional<Double> |
boxed(@NonNull OptionalDouble self)
Returns an
Optional<Double> holding the value of self , or returns
an empty optional, if the given OptionalDouble is empty. |
static @NonNull OptionalDouble |
filter(@NonNull OptionalDouble self,
@NonNull DoublePredicate predicate)
If the given
OptionalDouble self holds a value and the value tests positive with the given
DoublePredicate predicate , returns self , otherwise returns an empty OptionalDouble . |
static @NonNull OptionalDouble |
flatMapDouble(@NonNull OptionalDouble self,
@NonNull DoubleFunction<OptionalDouble> mapFunc)
Maps the value of
self to an OptionalDouble using mapFunc , if self has a present
value. |
static void |
ifNotPresent(@NonNull OptionalDouble self,
@NonNull Procedures.Procedure0 then)
Calls the procedure
then if the optional self holds no
value. |
static void |
ifPresentOrElse(OptionalDouble self,
DoubleConsumer action,
Runnable emptyAction)
Will call
action with the value held by self if it is not
empty. |
static @NonNull PrimitiveIterator.OfDouble |
iterator(@NonNull OptionalDouble self)
Returns an
PrimitiveIterable.OfDouble that either provides the one value present in self ,
or an PrimitiveIterable.OfDouble providing no value if self is empty. |
static <V> @NonNull Optional<V> |
map(@NonNull OptionalDouble self,
@NonNull DoubleFunction<V> mapFunc)
Maps the value held by
self to an object wrapped in Optional if present,
returns an empty Optional otherwise. |
static @NonNull OptionalDouble |
mapDouble(@NonNull OptionalDouble self,
@NonNull DoubleUnaryOperator mapFunc)
Maps the value of
self to a double value wrapped into an OptionalDouble , if self holds a value. |
static @NonNull OptionalInt |
mapInt(@NonNull OptionalDouble self,
@NonNull DoubleToIntFunction mapFunc)
Maps the value of
self to an int value wrapped into an OptionalInt , if self holds a value. |
static @NonNull OptionalLong |
mapLong(@NonNull OptionalDouble self,
@NonNull DoubleToLongFunction mapFunc)
Maps the value of
self to a long value wrapped into an OptionalLong , if self holds a value. |
static @NonNull OptionalDouble |
maybe(@Nullable Double i)
This method is a shortcut for the following expression:
|
static @NonNull OptionalDouble |
noDouble()
Alias for
OptionalDouble.empty() . |
static double |
operator_elvis(@NonNull OptionalDouble o,
double alternative)
This operator is an alias for:
|
static double |
operator_elvis(@NonNull OptionalDouble o,
DoubleSupplier getter)
Alias for
OptionalDouble.orElseGet(DoubleSupplier) . |
static @NonNull OptionalDouble |
operator_or(@NonNull OptionalDouble self,
@NonNull Supplier<? extends OptionalDouble> alternativeSupplier)
Operator that will be de-sugared to call to
OptionalIntExtensions.or(self,alternative) . |
static @NonNull OptionalDouble |
or(@NonNull OptionalDouble self,
@NonNull Supplier<? extends OptionalDouble> alternativeSupplier)
This method will either return
self if it is not empty, or
otherwise the value supplied by alternative . |
static @NonNull OptionalDouble |
some(double d)
This method is an alias for
OptionalDouble.of(double) . |
static @NonNull DoubleStream |
stream(@NonNull OptionalDouble self)
This extension function returns a stream of a single element if the given
optional
self contains a value, or no element if the optional is
empty. |
static @NonNull Set<Double> |
toSet(@NonNull OptionalDouble self)
Returns an immutable set that either contains the value, held by the
optional, or an empty set, if the optional is empty.
|
static Else |
whenPresent(@NonNull OptionalDouble self,
@NonNull DoubleConsumer onPresent)
This extension method will check if a value is present in
self and if so will call onPresent
with that value. |
public static Else whenPresent(@NonNull OptionalDouble self, @NonNull DoubleConsumer onPresent)
self
and if so will call onPresent
with that value. The returned Else
will allows to perform a block of code if the optional does
not hold a value. Example usage:
val OptionalDouble o = OptionalDouble.of(42.0d)
o.whenPresent [
println(it)
].elseDo [
println("no val")
]
self
- if holds value, onPresent
will be executed with the value held by self
.onPresent
- will be executed with value of self
, if present.Else
that either execute an else block if self
has no value present,
or ignore the else block if the value is present.public static void ifNotPresent(@NonNull OptionalDouble self, @NonNull Procedures.Procedure0 then)
then
if the optional self
holds no
value. This method is equivalent to the following code:
if (!self.isPresent()) {
then.apply();
}
self
- if optional is empty, then
will be called.then
- procedure to be called if self
does not hold a value.@Pure public static double operator_elvis(@NonNull OptionalDouble o, double alternative)
o.orElse
(alternative)
o
- OptionalDouble
checked for a present valuealternative
- value to be returned by this extension function, oif o
is empty.o
, or alternative
if there is no
value present in o
.@Pure public static double operator_elvis(@NonNull OptionalDouble o, DoubleSupplier getter)
OptionalDouble.orElseGet(DoubleSupplier)
.o
- optional to be queried for valuegetter
- will be called to get return value if parameter o
is empty.o
has a value present, will return this value.
Otherwise returns getter
will be called to get return value.@Pure public static @NonNull OptionalDouble some(double d)
OptionalDouble.of(double)
.d
- double to wrap in an OptionalDouble
OptionalDouble
, having present value d
.@Pure public static @NonNull OptionalDouble noDouble()
OptionalDouble.empty()
.OptionalDouble
with no value present.@Pure public static @NonNull OptionalDouble maybe(@Nullable Double i)
i == null ? OptionalDouble.empty() : OptionalDouble.of(i)
i
- an Integer that is checked for null
. If i == null
, then
returns an empty OptionalInt
. If i != null
returns an OptionalInt
holding the integer value.OptionalInt
holding i
, if i != null
, an empty OptionalInt
otherwise.@Pure public static @NonNull Optional<Double> boxed(@NonNull OptionalDouble self)
Optional<Double>
holding the value of self
, or returns
an empty optional, if the given OptionalDouble
is empty.self
- value will be extracted from this OptionalDouble
, if value is present
and wrapped into an Double
which will be returned in an Optional
from
this method.Optional<Double>
holding the value of self
if present, empty
Optional
otherwisepublic static @NonNull OptionalDouble filter(@NonNull OptionalDouble self, @NonNull DoublePredicate predicate)
OptionalDouble self
holds a value and the value tests positive with the given
DoublePredicate predicate
, returns self
, otherwise returns an empty OptionalDouble
.self
- the optional value that will be filtered using predicate
predicate
- the test that will be used to filter self
.OptionalDouble
, empty optional if self
is empty or it's content
tests negative with predicate
. Otherwise returns self
.public static <V> @NonNull Optional<V> map(@NonNull OptionalDouble self, @NonNull DoubleFunction<V> mapFunc)
self
to an object wrapped in Optional
if present,
returns an empty Optional
otherwise.V
- type of value the mapFunc
mapps to and is then held in the returned optionalself
- the optional, that's value should be mapped if presentmapFunc
- mapping function mapping the value held by self
to an objectOptional
, if self
is empty, otherwise an Optional
holding the result of op
applied to the value held by self
.public static @NonNull OptionalInt mapInt(@NonNull OptionalDouble self, @NonNull DoubleToIntFunction mapFunc)
self
to an int
value wrapped into an OptionalInt
, if self
holds a value.
Returns an empty OptionalInt
otherwise.self
- optional, that's held value will be mapped with mapFunc
, if presentmapFunc
- mapping function, to be applied to value of self
, if presentself
, mapped to int using mapFunc
if value present. Empty
optional otherwise.public static @NonNull OptionalLong mapLong(@NonNull OptionalDouble self, @NonNull DoubleToLongFunction mapFunc)
self
to a long
value wrapped into an OptionalLong
, if self
holds a value.
Returns an empty OptionalInt
otherwise.self
- optional, that's held value will be mapped with mapFunc
, if presentmapFunc
- mapping function, to be applied to value of self
, if presentself
, mapped to long
using mapFunc
if value present. Empty
optional otherwise.public static @NonNull OptionalDouble mapDouble(@NonNull OptionalDouble self, @NonNull DoubleUnaryOperator mapFunc)
self
to a double
value wrapped into an OptionalDouble
, if self
holds a value.
Returns an empty OptionalDouble
otherwise.self
- optional, that's held value will be mapped with mapFunc
, if presentmapFunc
- mapping function, to be applied to value of self
, if presentself
, mapped to long
using mapFunc
if value present. Empty
optional otherwise.public static @NonNull OptionalDouble flatMapDouble(@NonNull OptionalDouble self, @NonNull DoubleFunction<OptionalDouble> mapFunc)
self
to an OptionalDouble
using mapFunc
, if self
has a present
value. If self
is empty, this method returns an empty OptionalDouble
self
- possibly holding value to be mapped with mapFunc
mapFunc
- mapping function, used on value of self
if a value is present.mapFunc
applied to value of self
if
value is present, otherwise returning empty optional.public static @NonNull DoubleIterable asIterable(@NonNull OptionalDouble self)
DoubleIterable
that either provides the one value present in self
,
or an DoubleIterable
providing no value if self
is empty.self
- optional that's value (if present) will be provided via the returned iterable.DoubleIterable
providing one value taken from self
or no value, if self
is empty.public static @NonNull PrimitiveIterator.OfDouble iterator(@NonNull OptionalDouble self)
PrimitiveIterable.OfDouble
that either provides the one value present in self
,
or an PrimitiveIterable.OfDouble
providing no value if self
is empty.self
- optional that's value (if present) will be provided via the returned iterator.PrimitiveIterable.OfDouble
providing one value taken from self
or no value, if self
is empty.@Pure public static @NonNull Set<Double> toSet(@NonNull OptionalDouble self)
self
- Optional value is read frompublic static @NonNull DoubleStream stream(@NonNull OptionalDouble self)
self
contains a value, or no element if the optional is
empty.self
- the optional providing the value for the Stream providedself
public static void ifPresentOrElse(OptionalDouble self, DoubleConsumer action, Runnable emptyAction)
action
with the value held by self
if it is not
empty. Otherwise will call emptyAction
.self
- optional to be checked for value.action
- to be called with value of opt
if it is not empty.emptyAction
- to be called if opt
is empty.public static @NonNull OptionalDouble operator_or(@NonNull OptionalDouble self, @NonNull Supplier<? extends OptionalDouble> alternativeSupplier)
OptionalIntExtensions.or(self,alternative)
.self
- optional to be checked if empty. If not, this value will be
returned from operator.alternativeSupplier
- will be called to get return value if self
is empty.self
, if it is not empty, otherwise returns value
supplied by alternativeSupplier
.public static @NonNull OptionalDouble or(@NonNull OptionalDouble self, @NonNull Supplier<? extends OptionalDouble> alternativeSupplier)
self
if it is not empty, or
otherwise the value supplied by alternative
.self
- optional to be checked if empty. If not, this value will be
returned from operator.alternativeSupplier
- will be called to get return value if self
is empty.self
, if it is not empty, otherwise returns value
supplied by alternativeSupplier
.Copyright © 2019. All rights reserved.