public final class OptionalLongExtensions extends Object
OptionalLong
.
import static extension de.fhg.fokus.xtenders.optional.OptionalLongExtensions.*
OptionalExtensions
,
OptionalIntExtensions
,
OptionalDoubleExtensions
Modifier and Type | Method and Description |
---|---|
static @NonNull OptionalDouble |
asDouble(@NonNull OptionalLong self)
Returns
OptionalDouble that holds the value from self casted to double , or
an empty OptionalDouble if self is empty. |
static @NonNull LongIterable |
asIterable(@NonNull OptionalLong self)
Returns a
LongIterable that either provides the one value present in self ,
or an IntIterable providing no value if self is empty. |
static @NonNull Optional<Long> |
boxed(@NonNull OptionalLong self)
Returns an
Optional<Long> holding the value of self , or returns
an empty optional, if the given OptionalLong is empty. |
static @NonNull OptionalLong |
filter(@NonNull OptionalLong self,
@NonNull LongPredicate predicate)
If the given
OptionalLong self holds a value and the value tests positive with the given
LongPredicate predicate , returns self , otherwise returns an empty OptionalLong . |
static @NonNull OptionalLong |
flatMapLong(@NonNull OptionalLong self,
@NonNull LongFunction<OptionalLong> mapFunc)
Maps the value of
self to an OptionalLong using mapFunc , if self has a present
value. |
static void |
ifNotPresent(@NonNull OptionalLong self,
@NonNull Procedures.Procedure0 then)
Calls the procedure
then if the optional self holds no
value. |
static void |
ifPresentOrElse(OptionalLong self,
LongConsumer action,
Runnable emptyAction)
Will call
action with the value held by self if it is not
empty. |
static @NonNull PrimitiveIterator.OfLong |
iterator(@NonNull OptionalLong self)
Returns an
PrimitiveIterable.OfLong that either provides the one value present in self ,
or an PrimitiveIterable.OfLong providing no value if self is empty. |
static <V> @NonNull Optional<V> |
map(@NonNull OptionalLong self,
@NonNull LongFunction<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 OptionalLong self,
@NonNull LongToDoubleFunction mapFunc)
Maps the value of
self to a double value wrapped into an OptionalDouble , if self holds a value. |
static @NonNull OptionalInt |
mapInt(@NonNull OptionalLong self,
@NonNull LongToIntFunction mapFunc)
Maps the value of
self to an int value wrapped into an OptionalInt , if self holds a value. |
static @NonNull OptionalLong |
mapLong(@NonNull OptionalLong self,
@NonNull LongUnaryOperator mapFunc)
Maps the value of
self to a long value wrapped into an OptionalLong , if self holds a value. |
static @NonNull OptionalLong |
maybe(@Nullable Long l)
This method is a shortcut for the following expression:
|
static @NonNull OptionalLong |
noLong()
Alias for
OptionalLong.empty() . |
static long |
operator_elvis(@NonNull OptionalLong o,
long alternative)
This operator is an alias for:
|
static long |
operator_elvis(@NonNull OptionalLong o,
LongSupplier getter)
Alias for
OptionalLong.orElseGet(LongSupplier) . |
static @NonNull OptionalLong |
operator_or(@NonNull OptionalLong self,
@NonNull Supplier<? extends OptionalLong> alternativeSupplier)
Operator that will be de-sugared to call to
OptionalIntExtensions.or(self,alternative) . |
static @NonNull OptionalLong |
or(@NonNull OptionalLong self,
@NonNull Supplier<? extends OptionalLong> alternativeSupplier)
This method will either return
self if it is not empty, or
otherwise the value supplied by alternativeSupplier . |
static @NonNull OptionalLong |
some(long l)
This method is an alias for
OptionalLong.of(long) . |
static OptionalLong |
someOf(long l)
This method returns an OptionalLong instance wrapping the given long
l . |
static @NonNull LongStream |
stream(@NonNull OptionalLong 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<Long> |
toSet(@NonNull OptionalLong 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 OptionalLong self,
@NonNull LongConsumer onPresent)
This extension method will check if a value is present in
self and if so will call onPresent
with that value. |
public static @NonNull OptionalLong some(long l)
OptionalLong.of(long)
.l
- long to wrap in an OptionalLong
OptionalLong
, having present value l
.public static OptionalLong someOf(long l)
l
.
The returned value might be cached to achieve object re-use and therefore
less garbage collection.OptionalLong.of(long)
or a
new factory method adds caching of instances itself.l
- long to be wrapped in OptionalLongl
.@Pure public static @NonNull OptionalLong maybe(@Nullable Long l)
l == null ? OptionalLong.empty() : OptionalLong.of(i)
l
- a Long
that is checked for null
. If l == null
, then
returns an empty OptionalLong
. If l != null
returns an OptionalLong
holding the long value.OptionalLong
holding i
, if l != null
, an empty OptionalLong
otherwise.public static @NonNull OptionalLong noLong()
OptionalLong.empty()
.OptionalLong
with no value present.@Pure public static @NonNull Optional<Long> boxed(@NonNull OptionalLong self)
Optional<Long>
holding the value of self
, or returns
an empty optional, if the given OptionalLong
is empty.self
- value will be extracted from this OptionalLong
, if value is present
and wrapped into an Long
which will be returned in an Optional
from
this method.Optional<Long>
holding the value of self
if present, empty
Optional
otherwisepublic static Else whenPresent(@NonNull OptionalLong self, @NonNull LongConsumer 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 OptionalLong o = OptionalLong.of(42L)
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 OptionalLong 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.public static long operator_elvis(@NonNull OptionalLong o, long alternative)
o.orElse
(alternative)
o
- OptionalLong
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
.public static long operator_elvis(@NonNull OptionalLong o, LongSupplier getter)
OptionalLong.orElseGet(LongSupplier)
.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.public static @NonNull OptionalLong filter(@NonNull OptionalLong self, @NonNull LongPredicate predicate)
OptionalLong self
holds a value and the value tests positive with the given
LongPredicate predicate
, returns self
, otherwise returns an empty OptionalLong
.self
- the optional value that will be filtered using predicate
predicate
- the test that will be used to filter self
.OptionalLong
, empty optional if self
is empty or it's content
tests negative with predicate
. Otherwise returns self
.public static @NonNull OptionalDouble asDouble(@NonNull OptionalLong self)
OptionalDouble
that holds the value from self
casted to double
, or
an empty OptionalDouble
if self
is empty.self
- the value to be converted to an OptionalDouble
.self
wrapped in OptionalDouble
if present,
an empty OptionalDouble
otherwise.public static <V> @NonNull Optional<V> map(@NonNull OptionalLong self, @NonNull LongFunction<V> mapFunc)
self
to an object wrapped in Optional
if present,
returns an empty Optional
otherwise.V
- Type the given op
mapping function will map to from long
values.
The returned optional might hold a value of this type if self
actually holds a value.self
- 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 mapFunc
applied to the value held by self
.public static @NonNull OptionalInt mapInt(@NonNull OptionalLong self, @NonNull LongToIntFunction 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 OptionalLong self, @NonNull LongUnaryOperator mapFunc)
self
to a long
value wrapped into an OptionalLong
, if self
holds a value.
Returns an empty OptionalLong
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 OptionalLong flatMapLong(@NonNull OptionalLong self, @NonNull LongFunction<OptionalLong> mapFunc)
self
to an OptionalLong
using mapFunc
, if self
has a present
value. If self
is empty, this method returns an empty OptionalLong
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 OptionalDouble mapDouble(@NonNull OptionalLong self, @NonNull LongToDoubleFunction 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.@Pure public static @NonNull LongIterable asIterable(@NonNull OptionalLong self)
LongIterable
that either provides the one value present in self
,
or an IntIterable
providing no value if self
is empty.self
- optional that's value (if present) will be provided via the returned iterable.IntIterable
providing one value taken from self
or no value, if self
is empty.public static @NonNull PrimitiveIterator.OfLong iterator(@NonNull OptionalLong self)
PrimitiveIterable.OfLong
that either provides the one value present in self
,
or an PrimitiveIterable.OfLong
providing no value if self
is empty.self
- optional that's value (if present) will be provided via the returned iterator.PrimitiveIterable.OfLong
providing one value taken from self
or no value, if self
is empty.@Pure public static @NonNull Set<Long> toSet(@NonNull OptionalLong self)
self
- Optional value is read frompublic static @NonNull LongStream stream(@NonNull OptionalLong 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(OptionalLong self, LongConsumer 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 OptionalLong operator_or(@NonNull OptionalLong self, @NonNull Supplier<? extends OptionalLong> 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 OptionalLong or(@NonNull OptionalLong self, @NonNull Supplier<? extends OptionalLong> alternativeSupplier)
self
if it is not empty, or
otherwise the value supplied by alternativeSupplier
.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.