| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
T |
get()
Get underlying value of the box.
|
T |
get(T fallback)
Get underlying value of the box.
|
int |
hashCode() |
boolean |
isEmpty()
If the box's underlying value is NULL.
|
boolean |
isFull()
If the box's underlying value is NOT NULL.
|
<R> Box<R> |
map(java.util.function.Function<T,R> valueFunction)
Map current underlying value of T into value of Box of R.
|
<R> Box<R> |
map(java.util.function.Function<T,R> valueFunction,
java.util.function.Supplier<R> fallbackSupplier)
When valueFunction failed during map(), use output from fallbackSupplier()
|
static <T> Box<T> |
of(T obj)
Static constructor.
|
Box<T> |
or(java.util.function.Supplier<T> fallbackSupplier)
If not exists, function mod's value will be set for the value.
|
<X extends Throwable> |
orThrow(java.util.function.Supplier<? extends X> exceptionSupplier)
If the Box is empty, throw an exception.
|
Box<T> |
then(java.util.function.Consumer<T> valueConsumer)
Run consumer mod.
|
Box<T> |
update(java.util.function.UnaryOperator<T> valueOperator)
Update will replace underlying T value.
|
public Box(T t)
public static <T> Box<T> of(T obj)
Box.of("1123").map(v->v.length()).get()
T - obj - public boolean isEmpty()
public boolean isFull()
public T get()
public T get(T fallback)
fallback - public Box<T> then(java.util.function.Consumer<T> valueConsumer)
valueConsumer - public Box<T> update(java.util.function.UnaryOperator<T> valueOperator)
valueOperator - public Box<T> or(java.util.function.Supplier<T> fallbackSupplier)
Box.of(new StringBuilder()).with(sb->sb.append("Hello")).map(sb->sb.size()).get()
fallbackSupplier - public <X extends Throwable> Box<T> orThrow(java.util.function.Supplier<? extends X> exceptionSupplier) throws X extends Throwable
X - exceptionSupplier - X - extends ThrowableX extends Throwablepublic <R> Box<R> map(java.util.function.Function<T,R> valueFunction)
R - new typevalueFunction - modification functionpublic <R> Box<R> map(java.util.function.Function<T,R> valueFunction, java.util.function.Supplier<R> fallbackSupplier)
R - new typevalueFunction - fallbackSupplier - Copyright © 2023. All rights reserved.