T - Type of the content to be boxedpublic class Box<T> extends Object
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
T |
get()
Get the box content.
|
T |
get(T fallback)
Get the box content.
|
int |
hashCode() |
boolean |
isEmpty()
Check if the box content is NULL.
|
boolean |
isFull()
Check if the box content is NOT NULL.
|
<R> Box<R> |
map(FnTR<T,R> mapFn)
Converts box content to a new content in a box.
|
<R> Box<R> |
map(FnTR<T,R> mapFn,
R fallback)
Converts box content to a new content in a box.
|
static <T> Box<T> |
of(T obj)
Static constructor:
|
Box<T> |
or(T fallback)
If the box is empty, returns the box with the fallback value
|
Box<T> |
orElse(FnR<T> fallbackFn)
If the box is empty, returns the box with the fallback value
|
<E extends Throwable> |
orThrow(E exception)
If the box is empty (content is null), throw an exception.
|
Box<T> |
then(FnT<T> modFn)
View or modifying the box content.
|
Box<T> |
thenSet(FnTR<T,T> modFn)
Replace the box content.
|
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> then(FnT<T> modFn)
modFn - A function that can view or modify the content.public Box<T> thenSet(FnTR<T,T> modFn)
modFn - A function that takes and returns type T data.public Box<T> or(T fallback)
fallback - A fallback T when the box is empty.public Box<T> orElse(FnR<T> fallbackFn)
fallbackFn - A function that returns fallback value T.public <E extends Throwable> Box<T> orThrow(E exception) throws E extends Throwable
E - Any throwable object.exception - Exception to be thrown when the box is empty.E - Any Throwable exceptionE extends Throwablepublic <R> Box<R> map(FnTR<T,R> mapFn)
R - New return typemapFn - Lambda function which takes current content, and returns a Box with new type of content.public <R> Box<R> map(FnTR<T,R> mapFn, R fallback)
R - New return typemapFn - Lambda function which takes current content, and returns a Box with new type of content.fallback - Fallback value that will be boxed when mapFn throws an exception.
Note that if mapFn returns null, this fallback won't be called.Copyright © 2023. All rights reserved.