public final class OptionalBoolean
extends java.lang.Object
boolean value.Optional| Modifier and Type | Method and Description |
|---|---|
<R> R |
custom(Function<OptionalBoolean,R> function)
Applies custom operator on
OptionalBoolean. |
static OptionalBoolean |
empty()
Returns an empty
OptionalBoolean instance. |
boolean |
equals(java.lang.Object obj) |
OptionalBoolean |
executeIfAbsent(java.lang.Runnable action)
Invokes action function if value is absent.
|
OptionalBoolean |
executeIfPresent(BooleanConsumer consumer)
Invokes consumer function with the value if present.
|
OptionalBoolean |
filter(BooleanPredicate predicate)
Performs filtering on inner value if it is present.
|
OptionalBoolean |
filterNot(BooleanPredicate predicate)
Performs negated filtering on inner value if it is present.
|
boolean |
getAsBoolean()
Returns an inner value if present, otherwise throws
NoSuchElementException. |
int |
hashCode() |
void |
ifPresent(BooleanConsumer consumer)
Invokes consumer function with value if present, otherwise does nothing.
|
void |
ifPresentOrElse(BooleanConsumer 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.
|
OptionalBoolean |
map(BooleanPredicate mapper)
Invokes the given mapping function on inner value if present.
|
<U> Optional<U> |
mapToObj(BooleanFunction<U> mapper)
Invokes the given mapping function on inner value if present.
|
static OptionalBoolean |
of(boolean value)
Returns an
OptionalBoolean with the specified value present. |
static OptionalBoolean |
ofNullable(java.lang.Boolean value)
Returns an
OptionalBoolean with the specified value, or empty OptionalBoolean if value is null. |
OptionalBoolean |
or(Supplier<OptionalBoolean> supplier)
Returns current
OptionalBoolean if value is present, otherwise
returns an OptionalBoolean produced by supplier function. |
boolean |
orElse(boolean other)
Returns inner value if present, otherwise returns
other. |
boolean |
orElseGet(BooleanSupplier other)
Returns the value if present, otherwise returns value produced by supplier function.
|
boolean |
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.
|
java.lang.String |
toString() |
@NotNull public static OptionalBoolean empty()
OptionalBoolean instance.OptionalBoolean@NotNull public static OptionalBoolean of(boolean value)
OptionalBoolean with the specified value present.value - the value to be presentOptionalBoolean with the value present@NotNull public static OptionalBoolean ofNullable(@Nullable java.lang.Boolean value)
OptionalBoolean with the specified value, or empty OptionalBoolean if value is null.value - the value which can be nullOptionalBooleanpublic boolean getAsBoolean()
NoSuchElementException.
Since 1.2.0 prefer orElseThrow() method as it has readable name.OptionalBooleanjava.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
BooleanConsumer 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
BooleanConsumer 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 OptionalBoolean executeIfPresent(@NotNull BooleanConsumer consumer)
ifPresent, but does not breaks chainingconsumer - consumer functionOptionalBooleanifPresent(BooleanConsumer)@NotNull public OptionalBoolean executeIfAbsent(@NotNull java.lang.Runnable action)
action - action that invokes if value absentOptionalBoolean@Nullable
public <R> R custom(@NotNull
Function<OptionalBoolean,R> function)
OptionalBoolean.R - the type of the resultfunction - a transforming functionjava.lang.NullPointerException - if function is null@NotNull public OptionalBoolean filter(@NotNull BooleanPredicate predicate)
predicate - a predicate functionOptionalBoolean if the value is present and matches predicate,
otherwise an empty OptionalBoolean@NotNull public OptionalBoolean filterNot(@NotNull BooleanPredicate predicate)
predicate - a predicate functionOptionalBoolean if the value is present and doesn't matches predicate,
otherwise an empty OptionalBoolean@NotNull public OptionalBoolean map(@NotNull BooleanPredicate mapper)
mapper - mapping functionOptionalBoolean with transformed value if present,
otherwise an empty OptionalBooleanjava.lang.NullPointerException - if value is present and
mapper is null@NotNull public <U> Optional<U> mapToObj(@NotNull BooleanFunction<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 OptionalBoolean or(@NotNull Supplier<OptionalBoolean> supplier)
OptionalBoolean if value is present, otherwise
returns an OptionalBoolean produced by supplier function.supplier - supplier function that produces an OptionalBoolean to be returnedOptionalBoolean if value is present, otherwise
an OptionalBoolean produced by supplier functionjava.lang.NullPointerException - if value is not present and
supplier or value produced by it is nullpublic boolean orElse(boolean other)
other.other - the value to be returned if there is no value presentotherpublic boolean orElseGet(@NotNull
BooleanSupplier other)
other - supplier function that produces value if inner value is not presentother.getAsBoolean()java.lang.NullPointerException - if value is not present and other is nullpublic boolean orElseThrow()
NoSuchElementException.java.util.NoSuchElementException - if inner value is not presentpublic <X extends java.lang.Throwable> boolean 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