| 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(Object obj) |
OptionalLong |
executeIfAbsent(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,
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(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 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. |
String |
toString() |
public static OptionalLong empty()
OptionalLong instance.OptionalLongpublic static OptionalLong of(long value)
OptionalLong with the specified value present.value - the value to be presentOptionalLong with the value presentpublic static OptionalLong ofNullable(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.OptionalLongNoSuchElementException - 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(LongConsumer consumer)
consumer - the consumer function to be executed if a value is presentNullPointerException - if value is present and consumer is nullpublic void ifPresentOrElse(LongConsumer consumer, 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 presentNullPointerException - 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 OptionalLong executeIfPresent(LongConsumer consumer)
ifPresent, but does not breaks chainingconsumer - consumer functionOptionalLongifPresent(com.annimon.stream.function.LongConsumer)public OptionalLong executeIfAbsent(Runnable action)
action - action that invokes if value absentOptionalLongpublic <R> R custom(Function<OptionalLong,R> function)
OptionalLong.R - the type of the resultfunction - a transforming functionNullPointerException - if function is nullpublic OptionalLong filter(LongPredicate predicate)
predicate - a predicate functionOptionalLong if the value is present and matches predicate,
otherwise an empty OptionalLongpublic OptionalLong filterNot(LongPredicate predicate)
predicate - a predicate functionOptionalLong if the value is present and doesn't matches predicate,
otherwise an empty OptionalLongpublic OptionalLong map(LongUnaryOperator mapper)
mapper - mapping functionOptionalLong with transformed value if present,
otherwise an empty OptionalLongNullPointerException - if value is present and
mapper is nullpublic <U> Optional<U> mapToObj(LongFunction<U> mapper)
U - the type of result valuemapper - mapping functionOptional with transformed value if present,
otherwise an empty OptionalNullPointerException - if value is present and
mapper is nullpublic OptionalInt mapToInt(LongToIntFunction mapper)
mapper - mapping functionOptionalInt with transformed value if present,
otherwise an empty OptionalIntNullPointerException - if value is present and
mapper is nullpublic LongStream stream()
LongStream if present,
otherwise returns an empty LongStream.LongStreampublic OptionalLong or(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 functionNullPointerException - 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(LongSupplier other)
other - supplier function that produces value if inner value is not presentother.getAsLong()NullPointerException - if value is not present and other is nullpublic long orElseThrow()
NoSuchElementException.NoSuchElementException - if inner value is not presentpublic <X extends Throwable> long orElseThrow(Supplier<X> exceptionSupplier) throws X extends 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 ThrowableCopyright © 2018. All rights reserved.