public interface Box<T> extends Supplier<T>, Consumer<T>
Modifier and Type | Interface and Description |
---|---|
static interface |
Box.Dbl
A Box for primitive doubles.
|
static class |
Box.Default<T>
A simple implementation of Box.
|
static interface |
Box.Int
A Box for primitive ints.
|
static interface |
Box.Nullable<T>
Provides get/set access to a mutable nullable value.
|
Modifier and Type | Method and Description |
---|---|
default void |
accept(T value)
Delegates to set().
|
static <T> Box<T> |
from(Supplier<T> getter,
Consumer<T> setter)
Creates a Box from a Supplier and a Consumer.
|
static <T,V> Box<T> |
from(V target,
Function<V,T> getter,
BiConsumer<V,T> setter)
Creates a Box from an argument and two functions which operate on that argument.
|
default <R> Box<R> |
map(Function<? super T,? extends R> getMapper,
Function<? super R,? extends T> setMapper)
Maps one
Box to another Box . |
default T |
modify(Function<? super T,? extends T> mutator)
Shortcut for doing a set() on the result of a get().
|
static <T> Box<T> |
of(T value)
Creates a Box holding the given value.
|
void |
set(T value)
Sets the value which will later be returned by get().
|
void set(T value)
default void accept(T value)
default T modify(Function<? super T,? extends T> mutator)
default <R> Box<R> map(Function<? super T,? extends R> getMapper, Function<? super R,? extends T> setMapper)
Box
to another Box
.static <T> Box<T> of(T value)
static <T> Box<T> from(Supplier<T> getter, Consumer<T> setter)
static <T,V> Box<T> from(V target, Function<V,T> getter, BiConsumer<V,T> setter)