public final class OptionalLong
extends java.lang.Object
long value.Optional| Modifier and Type | Method and Description |
|---|---|
<R> R |
custom(Function<OptionalLong,R> function)
Applies custom operator on
OptionalLong. |
static OptionalLong |
empty()
Returns an empty
OptionalLong instance. |
boolean |
equals(java.lang.Object obj) |
OptionalLong |
executeIfAbsent(java.lang.Runnable action)
Invokes action function if value is absent.
|
OptionalLong |
executeIfPresent(LongConsumer consumer)
Invokes consumer function with the value if present.
|
OptionalLong |
filter(LongPredicate predicate)
Performs filtering on inner value if it is present.
|
OptionalLong |
filterNot(LongPredicate predicate)
Performs negated filtering on inner value if it is present.
|
long |
getAsLong()
Returns an inner value if present, otherwise throws
NoSuchElementException. |
int |
hashCode() |
void |
ifPresent(LongConsumer consumer)
Invokes consumer function with value if present, otherwise does nothing.
|
void |
ifPresentOrElse(LongConsumer 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.
|
OptionalLong |
map(LongUnaryOperator mapper)
Invokes the given mapping function on inner value if present.
|
OptionalInt |
mapToInt(LongToIntFunction mapper)
Invokes the given mapping function on inner value if present.
|
<U> Optional<U> |
mapToObj(LongFunction<U> mapper)
Invokes the given mapping function on inner value if present.
|
static OptionalLong |
of(long value)
Returns an
OptionalLong with the specified value present. |
static OptionalLong |
ofNullable(java.lang.Long value)
Returns an
OptionalLong with the specified value, or empty OptionalLong if value is null. |
OptionalLong |
or(Supplier<OptionalLong> supplier)
Returns current
OptionalLong if value is present, otherwise
returns an OptionalLong produced by supplier function. |
long |
orElse(long other)
Returns inner value if present, otherwise returns
other. |
long |
orElseGet(LongSupplier other)
Returns the value if present, otherwise returns value produced by supplier function.
|
long |
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.
|
LongStream |
stream()
Wraps a value into
LongStream if present,
otherwise returns an empty LongStream. |
java.lang.String |
toString() |
@NotNull public static OptionalLong empty()
OptionalLong instance.OptionalLong@NotNull public static OptionalLong of(long value)
OptionalLong with the specified value present.value - the value to be presentOptionalLong with the value present@NotNull public static OptionalLong ofNullable(@Nullable java.lang.Long value)
OptionalLong with the specified value, or empty OptionalLong if value is null.value - the value which can be nullOptionalLongpublic long getAsLong()
NoSuchElementException.
Since 1.2.0 prefer orElseThrow() method as it has readable name.OptionalLongjava.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
LongConsumer 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
LongConsumer 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 OptionalLong executeIfPresent(@NotNull LongConsumer consumer)
ifPresent, but does not breaks chainingconsumer - consumer functionOptionalLongifPresent(com.annimon.stream.function.LongConsumer)@NotNull public OptionalLong executeIfAbsent(@NotNull java.lang.Runnable action)
action - action that invokes if value absentOptionalLong@Nullable
public <R> R custom(@NotNull
Function<OptionalLong,R> function)
OptionalLong.R - the type of the resultfunction - a transforming functionjava.lang.NullPointerException - if function is null@NotNull public OptionalLong filter(@NotNull LongPredicate predicate)
predicate - a predicate functionOptionalLong if the value is present and matches predicate,
otherwise an empty OptionalLong@NotNull public OptionalLong filterNot(@NotNull LongPredicate predicate)
predicate - a predicate functionOptionalLong if the value is present and doesn't matches predicate,
otherwise an empty OptionalLong@NotNull public OptionalLong map(@NotNull LongUnaryOperator 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 <U> Optional<U> mapToObj(@NotNull LongFunction<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 LongToIntFunction 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 LongStream stream()
LongStream if present,
otherwise returns an empty LongStream.LongStream@NotNull public OptionalLong or(@NotNull Supplier<OptionalLong> supplier)
OptionalLong if value is present, otherwise
returns an OptionalLong produced by supplier function.supplier - supplier function that produces an OptionalLong to be returnedOptionalLong if value is present, otherwise
an OptionalLong produced by supplier functionjava.lang.NullPointerException - if value is not present and
supplier or value produced by it is nullpublic long orElse(long other)
other.other - the value to be returned if there is no value presentotherpublic long orElseGet(@NotNull
LongSupplier other)
other - supplier function that produces value if inner value is not presentother.getAsLong()java.lang.NullPointerException - if value is not present and other is nullpublic long orElseThrow()
NoSuchElementException.java.util.NoSuchElementException - if inner value is not presentpublic <X extends java.lang.Throwable> long 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