Class ChainedConverter<S,T>
- java.lang.Object
-
- io.axoniq.dataprotection.serialization.ChainedConverter<S,T>
-
- Type Parameters:
S- The source type of the converterT- The target type of the converter
- All Implemented Interfaces:
ContentTypeConverter<S,T>
public class ChainedConverter<S,T> extends Object implements ContentTypeConverter<S,T>
A converter that delegates to a chain of other ContentTypeConverters to convert from a source to a target for which there is not necessarily a single converter available.- Since:
- 2.0
- Author:
- Allard Buijze
-
-
Constructor Summary
Constructors Constructor Description ChainedConverter(List<ContentTypeConverter<?,?>> delegates)Creates a new instance that uses the givendelegatesto form a chain of converters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <S,T>
ChainedConverter<S,T>calculateChain(Class<S> sourceType, Class<T> targetType, Collection<ContentTypeConverter<?,?>> candidates)Returns a converter that can convert an IntermediateRepresentation from the givensourceTypeto the giventargetTypeusing a chain formed with givencandidates.static <S,T>
booleancanConvert(Class<S> sourceContentType, Class<T> targetContentType, List<ContentTypeConverter<?,?>> converters)Indicates whether this converter is capable of converting the givensourceContentTypeintotargetContentType, using the givenconverters.Tconvert(S original)Converts the given object into another.Class<S>expectedSourceType()The expected type of input data.Class<T>targetType()The returned type of IntermediateRepresentation
-
-
-
Constructor Detail
-
ChainedConverter
public ChainedConverter(List<ContentTypeConverter<?,?>> delegates)
Creates a new instance that uses the givendelegatesto form a chain of converters. Note that thedelegatesmust for a Continuous chain, meaning that each item must produce an IntermediateRepresentation of a type that can be consumed by the next delegate. To automatically calculate a route between converters, seecalculateChain(source, target, candidates)- Parameters:
delegates- the chain of delegates to perform the conversion
-
-
Method Detail
-
calculateChain
public static <S,T> ChainedConverter<S,T> calculateChain(Class<S> sourceType, Class<T> targetType, Collection<ContentTypeConverter<?,?>> candidates)
Returns a converter that can convert an IntermediateRepresentation from the givensourceTypeto the giventargetTypeusing a chain formed with givencandidates. The returned converter uses some (or all) of the givencandidatesas delegates.- Type Parameters:
S- The source type of the converterT- The target type of the converter- Parameters:
sourceType- The source type of the convertertargetType- The target type of the convertercandidates- The candidates to form a chain with- Returns:
- A converter for the given source and target types
- Throws:
CannotConvertBetweenTypesException- if no converter can be created using given candidates
-
canConvert
public static <S,T> boolean canConvert(Class<S> sourceContentType, Class<T> targetContentType, List<ContentTypeConverter<?,?>> converters)
Indicates whether this converter is capable of converting the givensourceContentTypeintotargetContentType, using the givenconverters. Whentrue, it may use any number of the givenconvertersto form a chain.- Type Parameters:
S- The content type of the source objectT- The content type of the target object- Parameters:
sourceContentType- The content type of the source objecttargetContentType- The content type of the target objectconverters- The converters eligible for use- Returns:
trueif this Converter can convert between the given types, using the given converters. Otherwisefalse.
-
convert
public T convert(S original)
Description copied from interface:ContentTypeConverterConverts the given object into another. Typically, these values are contained by aSerializedObjectinstance.- Specified by:
convertin interfaceContentTypeConverter<S,T>- Parameters:
original- the value to convert- Returns:
- the converted value
-
expectedSourceType
public Class<S> expectedSourceType()
Description copied from interface:ContentTypeConverterThe expected type of input data.- Specified by:
expectedSourceTypein interfaceContentTypeConverter<S,T>- Returns:
- the expected data format in IntermediateRepresentation
-
targetType
public Class<T> targetType()
Description copied from interface:ContentTypeConverterThe returned type of IntermediateRepresentation- Specified by:
targetTypein interfaceContentTypeConverter<S,T>- Returns:
- the output data format in IntermediateRepresentation
-
-