T - Type of the content to be boxedpublic class Box<T> extends Object
| Modifier and Type | Method and Description |
|---|---|
Box<T> |
eval(Fx10<T> evalFn)
Evaluate the value regardless of whether the box is empty or not.
|
T |
get()
Get the box content.
|
T |
get(T fallback)
Get the box content.
|
boolean |
isEmpty()
Check if the box content is NULL.
|
boolean |
isFull()
Check if the box content is NOT NULL.
|
<R> Box<R> |
map(Fx11<T,R> mapFn)
Converts box content to a new content in a box.
|
static <R> Box<R> |
of(Fx01<R> fx)
Static constructor:
|
static <T> Box<T> |
of(T obj)
Static constructor:
|
Box<T> |
or(Runnable r)
If the box is empty, execute the Runnable.
|
Box<T> |
orSet(Fx01<T> valueFn)
If the box is empty, returns the box with a new value
|
Box<T> |
reset(T newValue)
Regardless of the box's state (whether full or not), set the content of the box.
|
<R> Box<R> |
set(Fx01<R> setFn)
Regardless of the box's state (whether full or not), set the content of the box.
|
Box<T> |
skip(FxBool<T> skipFn)
If the condition function returns true, empty the box.
|
Box<T> |
then(Fx10<T> modFn)
View or modifying the box content.
|
Box<T> |
thenSet(FxUnary<T> modFn)
Replace the box content.
|
String |
toString() |
<X extends Throwable> |
validate(FxBool<T> validationFn,
X throwable)
Validate the box with validation function.
|
public Box(T t)
t - Boxed T.public static <T> Box<T> of(T obj)
T - Type of the target object.obj - A target object to be boxed.public static <R> Box<R> of(Fx01<R> fx)
R - Type of the target object.fx - A lambda to create a target object to be boxed.public boolean isEmpty()
public boolean isFull()
public T get()
public T get(T fallback)
fallback - A value to be returned when the box is empty.public Box<T> skip(FxBool<T> skipFn)
skipFn - A lambda function returning true means empty the box.public Box<T> then(Fx10<T> modFn)
modFn - A function that can view or modify the content.public Box<T> thenSet(FxUnary<T> modFn)
modFn - A function that takes and returns type T data.public Box<T> or(Runnable r)
r - A runnable to be executed. Since the box is empty, it won't do anything to the box.
To modify the box, use orSet instead.public Box<T> orSet(Fx01<T> valueFn)
valueFn - A function that returns new value for the box.public Box<T> eval(Fx10<T> evalFn)
evalFn - A lambda function to evaluate the value. This does not return anything.public <X extends Throwable> Box<T> validate(FxBool<T> validationFn, X throwable) throws X extends Throwable
X - Any throwable typesvalidationFn - A function validating the value. Returns true if validated.throwable - A throwable or an exception to be thrown if didn't get validated.X - Throwable if didn't get validatedX extends Throwablepublic <R> Box<R> set(Fx01<R> setFn)
R - return box typesetFn - A function returning new valuepublic Box<T> reset(T newValue)
newValue - New value to be used. This has to be the same type with current.public <R> Box<R> map(Fx11<T,R> mapFn)
R - New return typemapFn - Lambda function which takes current content, and returns a Box with new type of content.Copyright © 2023. All rights reserved.