public final class OptionalByte
extends java.lang.Object
byte
value.
If a value is present, isPresent()
will return true
and getAsByte()
will return the value.
Additional methods that depend on the presence or absence of a contained value are provided, such as orElse(byte)
(return a default value if value not present) and ifPresent(ByteConsumer)
(execute
a block of code if the value is present).
This is a value-based class; use of identity-sensitive operations (including reference equality (==
), identity hash code, or synchronization) on instances of OptionalByte
may have unpredictable results
and should be avoided.
Modifier and Type | Method and Description |
---|---|
static OptionalByte |
empty()
Returns an empty
OptionalByte instance. |
boolean |
equals(java.lang.Object object)
Indicates whether some other
Object is "equal to" this OptionalByte . |
byte |
getAsByte()
If a value is present in this
OptionalByte , returns the value, otherwise throws NoSuchElementException . |
int |
hashCode()
Returns the hash code value of the present value, if any, or
0 (zero) if no value is present. |
void |
ifPresent(ByteConsumer consumer)
Have the specified
consumer accept the value if a value is present, otherwise do nothing. |
boolean |
isPresent()
Returns
true if there is a value present, otherwise false . |
static OptionalByte |
of(byte value)
Returns an
OptionalByte with the specified value present. |
byte |
orElse(byte other)
Returns the value if present, otherwise returns
other . |
byte |
orElseGet(ByteSupplier other)
Returns the value if present, otherwise invokes
other and returns the result of that invocation. |
<X extends java.lang.Throwable> |
orElseThrow(java.util.function.Supplier<X> exceptionSupplier)
Returns the contained value, if present, otherwise throws a
Throwable to be created by the provided Supplier . |
public boolean equals(java.lang.Object object)
Object
is "equal to" this OptionalByte
.
The other Object
is considered equal if:
OptionalByte
and;equals
in class java.lang.Object
object
- an Object
to be tested for equalitytrue
if the other Object
is "equal to" this OptionalByte
otherwise false
public boolean isPresent()
true
if there is a value present, otherwise false
.true
if there is a value present, otherwise false
public byte getAsByte()
OptionalByte
, returns the value, otherwise throws NoSuchElementException
.OptionalByte
java.util.NoSuchElementException
- if there is no value presentpublic byte orElse(byte other)
other
.other
- the value to be returned if there is no value presentother
public byte orElseGet(ByteSupplier other)
other
and returns the result of that invocation.other
- a ByteSupplier
whose result is returned if no value is presentother
and returns the result of that invocationjava.lang.NullPointerException
- if value is not present and other
is null
public <X extends java.lang.Throwable> byte orElseThrow(java.util.function.Supplier<X> exceptionSupplier) throws X extends java.lang.Throwable
Throwable
to be created by the provided Supplier
.X
- the type of the Throwable
to be thrownexceptionSupplier
- the Supplier
which will return the Throwable
to be thrownjava.lang.NullPointerException
- if no value is present and exceptionSupplier
is null
X
- if there is no value presentX extends java.lang.Throwable
public int hashCode()
0
(zero) if no value is present.hashCode
in class java.lang.Object
0
(zero) if no value is presentpublic void ifPresent(ByteConsumer consumer)
consumer
accept the value if a value is present, otherwise do nothing.consumer
- block to be executed if a value is presentjava.lang.NullPointerException
- if value is present and consumer
is null
public static OptionalByte empty()
OptionalByte
instance.
No value is present for this OptionalByte
.
OptionalByte
instancepublic static OptionalByte of(byte value)
OptionalByte
with the specified value present.value
- the value to be presentOptionalByte
with the specified value present