Modifier and Type | Method and Description |
---|---|
default <C> ConverterNullable<A,C> |
andThen(ConverterNullable<B,C> andThen)
Returns a converter whose
convert method applies secondConverter to the result of this converter. |
B |
convert(A a)
Returns a representation of
a as an instance of type B . |
default Iterable<B> |
convertAll(Iterable<? extends A> fromIterable)
Returns an iterable that applies
convert to each element of fromIterable . |
static <A,B> ConverterNullable<A,B> |
from(Function<? super A,? extends B> forwardFunction,
Function<? super B,? extends A> backwardFunction)
Delegates to
from(Function, Function, String) , passing forwardFunction.toString() as the name parameter. |
static <A,B> ConverterNullable<A,B> |
from(Function<? super A,? extends B> forwardFunction,
Function<? super B,? extends A> backwardFunction,
String name)
Returns a converter based on existing forward and backward functions.
|
default ConverterNullable<B,A> |
reverse()
Returns the reversed view of this converter, where the
convert(Object) and revert(Object) methods are swapped. |
A |
revert(B b)
Returns a representation of
b as an instance of type A . |
static <A,B> ConverterNullable<A,B> from(Function<? super A,? extends B> forwardFunction, Function<? super B,? extends A> backwardFunction)
Delegates to from(Function, Function, String)
, passing forwardFunction.toString()
as the name
parameter.
static <A,B> ConverterNullable<A,B> from(Function<? super A,? extends B> forwardFunction, Function<? super B,? extends A> backwardFunction, String name)
Returns a converter based on existing forward and backward functions. Note that it is unnecessary to create new classes implementing Function
just to pass them in here. Instead, simply subclass ConverterNullable
and implement its convert(A)
and revert(B)
methods directly.
The name
parameter will be returned as the toString
of the created object.
The returned converter is serializable if both provided functions are.
@Nullable B convert(@Nullable A a)
Returns a representation of a
as an instance of type B
. If a
cannot be converted, an unchecked exception (such as IllegalArgumentException
) should be thrown.
a
- the instance to convert; possibly null@Nullable A revert(@Nullable B b)
Returns a representation of b
as an instance of type A
. If b
cannot be converted, an unchecked exception (such as IllegalArgumentException
) should be thrown.
b
- the instance to convert; possibly nullUnsupportedOperationException
- if backward conversion is not implemented; this should be very rare. Note that if backward conversion is not only unimplemented but unimplementable (for example, consider a Converter<Chicken, ChickenNugget>
), then this is not logically a Converter
at all, and should just implement Function
.default <C> ConverterNullable<A,C> andThen(ConverterNullable<B,C> andThen)
Returns a converter whose convert
method applies secondConverter
to the result of this converter. Its reverse
method applies the converters in reverse order.
The returned converter is serializable if this
converter and secondConverter
are.
default ConverterNullable<B,A> reverse()
Returns the reversed view of this converter, where the convert(Object)
and revert(Object)
methods are swapped.
default Iterable<B> convertAll(Iterable<? extends A> fromIterable)
Returns an iterable that applies convert
to each element of fromIterable
. The conversion is done lazily.
The returned iterable’s iterator supports remove()
if the input iterator does. After a successful remove()
call, fromIterable
no longer contains the corresponding element.