T - Type of the content to be boxedpublic class Box<T> extends Object implements AutoCloseable
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
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 <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> |
set(Fx01<T> setFn)
Regardless of the box's state (whether full or not), set the content of the box.
|
Box<T> |
skip(Fx11b<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(Fx11<T,T> modFn)
Replace the box content.
|
String |
toString() |
<X extends Throwable> |
validate(Fx11b<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 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(Fx11b<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(Fx11<T,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(Fx11b<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 Box<T> set(Fx01<T> setFn)
setFn - A function returning new valuepublic <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.public void close()
close in interface AutoCloseableCopyright © 2023. All rights reserved.