public final class OptionalBoolean
extends java.lang.Object
boolean
value.Optional
Modifier and Type | Method and Description |
---|---|
static OptionalBoolean |
empty()
Returns an empty
OptionalBoolean instance. |
boolean |
equals(java.lang.Object obj) |
boolean |
get()
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 |
isPresent()
Checks value present.
|
static OptionalBoolean |
of(boolean value)
Returns an
OptionalBoolean with the specified value present. |
boolean |
or(boolean other)
Returns inner value if present, otherwise returns
other . |
boolean |
orGet(BooleanSupplier other)
Returns the value if present, otherwise returns value produced by supplier function.
|
<X extends java.lang.Throwable> |
orThrow(Supplier<X> exceptionSupplier)
Returns the value if present, otherwise throws an exception provided by supplier function.
|
java.lang.String |
toString() |
public static OptionalBoolean empty()
OptionalBoolean
instance.OptionalBoolean
public static OptionalBoolean of(boolean value)
OptionalBoolean
with the specified value present.value
- the value to be presentOptionalBoolean
with the value presentpublic boolean get()
NoSuchElementException
.OptionalBoolean
java.util.NoSuchElementException
- if there is no value presentisPresent()
public boolean isPresent()
true
if a value present, false
otherwisepublic void ifPresent(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(BooleanConsumer consumer, 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.public boolean or(boolean other)
other
.other
- the value to be returned if there is no value presentother
public boolean orGet(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 <X extends java.lang.Throwable> boolean orThrow(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.Throwable
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object