PRESENTATION
- The presentation type.MODEL
- The model type.public interface Converter<PRESENTATION,MODEL> extends Serializable
Converters must not have any side effects (never update UI from inside a converter).
Modifier and Type | Method and Description |
---|---|
default <T> Converter<PRESENTATION,T> |
chain(Converter<MODEL,T> other)
Returns a converter that chains together this converter with the given
type-compatible converter.
|
Result<MODEL> |
convertToModel(PRESENTATION value,
ValueContext context)
Converts the given value from model type to presentation type.
|
PRESENTATION |
convertToPresentation(MODEL value,
ValueContext context)
Converts the given value from presentation type to model type.
|
static <P,M> Converter<P,M> |
from(SerializableFunction<P,M> toModel,
SerializableFunction<M,P> toPresentation,
SerializableFunction<Exception,String> onError)
Constructs a converter from two functions.
|
static <P,M> Converter<P,M> |
from(SerializableFunction<P,Result<M>> toModel,
SerializableFunction<M,P> toPresentation)
Constructs a converter from a filter and a function.
|
static <T> Converter<T,T> |
identity()
Returns a converter that returns its input as-is in both directions.
|
Result<MODEL> convertToModel(PRESENTATION value, ValueContext context)
A converter can optionally use locale to do the conversion.
value
- The value to convert. Can be nullcontext
- The value context for the conversion.PRESENTATION convertToPresentation(MODEL value, ValueContext context)
A converter can optionally use locale to do the conversion.
value
- The value to convert. Can be nullcontext
- The value context for the conversion.static <T> Converter<T,T> identity()
T
- the input and output typestatic <P,M> Converter<P,M> from(SerializableFunction<P,M> toModel, SerializableFunction<M,P> toPresentation, SerializableFunction<Exception,String> onError)
Exception
instances thrown from the toModel
function are converted into
error-bearing Result
objects using the given onError
function.static <P,M> Converter<P,M> from(SerializableFunction<P,Result<M>> toModel, SerializableFunction<M,P> toPresentation)
P
- the presentation typeM
- the model typetoModel
- the function to convert to modeltoPresentation
- the function to convert to presentationFunction
default <T> Converter<PRESENTATION,T> chain(Converter<MODEL,T> other)
The chained converters will form a new converter capable of converting from the presentation type of this converter to the model type of the other converter.
In most typical cases you should not need this method but instead only
need to define one converter for a binding using
Binder.BindingBuilder.withConverter(Converter)
.
T
- the model type of the resulting converterother
- the converter to chain, not nullCopyright © 2019. All rights reserved.