S - the source typeR - the result typepublic abstract class TypedTransformer<S,R> extends Object implements Transformer
Transformer for convenient extension.| Constructor and Description |
|---|
TypedTransformer(Class<S> sourceType,
Class<R> resultType)
Constructs a transformer for the specified source and result type.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract R |
safeTransform(Class<? extends R> type,
S value)
Transforms the given value to the provided type.
|
Object |
transform(TypeInformation<?> type,
Object value)
Transforms the provided value to the requested type, if possible.
|
public TypedTransformer(Class<S> sourceType, Class<R> resultType)
safeTransform(Class, Object) will not be called. To define a transformer that converts Strings to
Integers, pass String and Integer. To convert anything to a String, you should pass
Object and String as types.
Note that primitive types are not included, e.g. a TypedTransformer<Boolean, Object> will skip
values where value.getClass() == boolean.class.
sourceType - the type the source object must be of to be considered by this transformerresultType - the type the target type needs to extend or be equal to in order to be considered
by this transformerpublic Object transform(TypeInformation<?> type, Object value)
Transformer
The contract is that a transformer must return an object of type T
for a given type of TypeInformation<T>. This is not forced in the
signature to allow handling primitive types, as well as to avoid casting nightmares.
transform in interface Transformertype - the type to map tovalue - the value to transform from@Nullable protected abstract R safeTransform(Class<? extends R> type, S value)
type is equal to
R or a subclass thereof, and if value is an object of type S. The object is never null.type - the desired type of the conversion resultvalue - the value to convertCopyright © 2016–2018 The AuthMe Team. All rights reserved.