Package cdc.converters
Interface Converter<S,T>
-
- Type Parameters:
S- The source/input type.T- The target/result type.
- All Superinterfaces:
Function<S,T>
- All Known Implementing Classes:
AbstractConverter,AbstractNoArgsConverter,AbstractNumberToString,AbstractSequenceConverter,AbstractSequenceToString,AbstractStringToNumber,AbstractStringToSequence,AbstractStringToTemporal,AbstractTemporalToString,AndThenConverter,ArrayToString,BigDecimalToString,BigIntegerToString,BooleanArrayToString,BooleanListToString,BooleanToString,ByteArrayToString,ByteListToString,ByteToString,CharToString,ClassToString,ConverterAdapter,DateToString,DoubleArrayToString,DoubleListToString,DoubleToString,EnumToString,FileToString,FloatArrayToString,FloatListToString,FloatToString,Identity,IntegerArrayToString,IntegerListToString,IntegerToString,ListToString,LocalDateTimeToString,LocalDateToString,LocaleToString,LocalTimeToString,LongArrayToString,LongListToString,LongToString,ObjectToString,OrElseConverter,RawRefConverter,ShortArrayToString,ShortListToString,ShortToString,StringFiller,StringRandomizer,StringToArray,StringToBigDecimal,StringToBigInteger,StringToBoolean,StringToBooleanArray,StringToBooleanList,StringToByte,StringToByteArray,StringToByteList,StringToChar,StringToClass,StringToConverter,StringToDate,StringToDouble,StringToDoubleArray,StringToDoubleList,StringToEnum,StringToFile,StringToFloat,StringToFloatArray,StringToFloatList,StringToInteger,StringToIntegerArray,StringToIntegerList,StringToList,StringToLocalDate,StringToLocalDateTime,StringToLocale,StringToLocalTime,StringToLong,StringToLongArray,StringToLongList,StringToShort,StringToShortArray,StringToShortList,ToLowerCase,ToUpperCase
public interface Converter<S,T> extends Function<S,T>
Base interface of typed converters.A Converter is a
Functionwith additional properties:- The class of source/input type.
- The class of target/result type.
- Some configuration parameters.
- Author:
- Damien Carbonne
-
-
Field Summary
Fields Modifier and Type Field Description static FormalArgsMETA_FARGSstatic FormalArg<Class<?>>SOURCE_CLASSstatic FormalArg<Class<?>>TARGET_CLASS
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <R,U>
Converter<R,U>adapt(Class<R> sourceClass, Class<U> targetClass)Returns an adaptation of this converter to a specific source and target classes.static <S,T>
Converter<S,T>adapt(Class<S> sourceClass, Class<T> targetClass, Converter<?,?> delegate)Returns an adaptation of a converter to specific source and target classes.default <U> Converter<S,U>andThen(Converter<? super T,U> after)Returns the composition if this converter applied before another one.default <U> Converter<S,U>andThenRaw(Converter<?,U> after)Returns the composition if this converter applied before another one.default TapplyRaw(Object source)Applies this converter to a raw value.default booleanareCompliantSourceAndTargetClasses(Class<?> sourceClass, Class<?> targetClass)Returnstruewhen a source and target classes are compliant.default booleanareMatchingSourceAndTargetClasses(Class<?> sourceClass, Class<?> targetClass)Returnstruewhen a source and target classes are matching.default <R,U>
Converter<R,U>cast(Class<R> sourceClass, Class<U> targetClass)Returns an adaptation of this converter to other source and target classes.default <R> Converter<R,T>compose(Converter<R,? extends S> before)Returns the composition of this converter applied after another one.default <R> Converter<R,T>composeRaw(Converter<R,?> before)Returns the composition of this converter applied after another one.ArgsgetParams()Class<S>getSourceClass()Class<T>getTargetClass()default Class<S>getWrappedSourceClass()default Class<T>getWrappedTargetClass()default booleanisCompliantSourceClass(Class<?> cls)Returnstruewhen a class is a compliant source class.default booleanisCompliantTargetClass(Class<?> cls)Returnstruewhen a class is a compliant target class.default booleanisMatchingSourceClass(Class<?> cls)Returnstruewhen a class matches source class.default booleanisMatchingTargetClass(Class<?> cls)Returnstruewhen a class matches target class.default Converter<S,T>orElse(Converter<? super S,? extends T>... others)Returns a converter that first tries to convert using this converter, and falls back to other ones in case of failure.default Converter<S,T>orElseRaw(Converter<?,?>... others)static <C extends Converter<S,T>,S,T>
Factory<C>singleton(C instance)
-
-
-
Field Detail
-
META_FARGS
static final FormalArgs META_FARGS
-
-
Method Detail
-
getWrappedSourceClass
default Class<S> getWrappedSourceClass()
- Returns:
- The wrapped type of source class.
If source class is the class of a primitive type, returns the class of corresponding boxing type.
-
getWrappedTargetClass
default Class<T> getWrappedTargetClass()
- Returns:
- The wrapped type of target class. If target class is the class of a primitive type, returns the class of corresponding boxing type.
-
getParams
Args getParams()
- Returns:
- The parameters used to configure this converter.
-
applyRaw
default T applyRaw(Object source)
Applies this converter to a raw value.- Parameters:
source- The source value.- Returns:
- The converted value.
- Throws:
ClassCastException- Whensourceis notnulland can not be cast to source class.
-
isCompliantSourceClass
default boolean isCompliantSourceClass(Class<?> cls)
Returnstruewhen a class is a compliant source class.clsmust be descendant of source class.- Parameters:
cls- The class.- Returns:
truewhenclsis a compliant source class.
-
isCompliantTargetClass
default boolean isCompliantTargetClass(Class<?> cls)
Returnstruewhen a class is a compliant target class.clsmust be ancestor of target class.- Parameters:
cls- The class.- Returns:
truewhenclsis a compliant target class.
-
areCompliantSourceAndTargetClasses
default boolean areCompliantSourceAndTargetClasses(Class<?> sourceClass, Class<?> targetClass)
Returnstruewhen a source and target classes are compliant.- Parameters:
sourceClass- The source class.targetClass- The target class.- Returns:
truewhensourceandtargetclasses are compliant.
-
isMatchingSourceClass
default boolean isMatchingSourceClass(Class<?> cls)
Returnstruewhen a class matches source class.clsand source class are the same (after wrapping).- Parameters:
cls- The class.- Returns:
truewhenclsmatches source class.
-
isMatchingTargetClass
default boolean isMatchingTargetClass(Class<?> cls)
Returnstruewhen a class matches target class.clsand target class are the same (after wrapping).- Parameters:
cls- The class.- Returns:
truewhenclsmatches target class.
-
areMatchingSourceAndTargetClasses
default boolean areMatchingSourceAndTargetClasses(Class<?> sourceClass, Class<?> targetClass)
Returnstruewhen a source and target classes are matching.- Parameters:
sourceClass- The source class.targetClass- The target class.- Returns:
truewhensourceandtargetclasses are matching.
-
compose
default <R> Converter<R,T> compose(Converter<R,? extends S> before)
Returns the composition of this converter applied after another one.- Type Parameters:
R- The source type of the other converter.- Parameters:
before- The other converter, applied before this one.- Returns:
- The composition of this converter applied after
before.
-
andThen
default <U> Converter<S,U> andThen(Converter<? super T,U> after)
Returns the composition if this converter applied before another one.- Type Parameters:
U- The target type of the other converter.- Parameters:
after- The other converter, applied after this one.- Returns:
- The composition of this converter applied before
after.
-
orElse
default Converter<S,T> orElse(Converter<? super S,? extends T>... others)
Returns a converter that first tries to convert using this converter, and falls back to other ones in case of failure.The result of the first successful converter is used. If no converter succeeds, an exception is thrown.
- Parameters:
others- The fallback converters, used if this one fails.- Returns:
- A converter that first tries to convert using this converter,
and falls back to
othersin case of failure.
-
cast
default <R,U> Converter<R,U> cast(Class<R> sourceClass, Class<U> targetClass)
Returns an adaptation of this converter to other source and target classes.- Type Parameters:
R- The result source type.U- The result target type.- Parameters:
sourceClass- The source class.targetClass- The target class.- Returns:
- An adaptation of this converter to
sourceClassandtargetClass. - Throws:
IllegalArgumentException- When no adaptation is possible.
-
composeRaw
default <R> Converter<R,T> composeRaw(Converter<R,?> before)
Returns the composition of this converter applied after another one.- Type Parameters:
R- The source type of the other converter.- Parameters:
before- The other converter, applied before this one.- Returns:
- The composition of this converter applied after
before. - Throws:
IllegalArgumentException- Whenbeforeisnullor no adaptation ofbeforeis possible.
-
andThenRaw
default <U> Converter<S,U> andThenRaw(Converter<?,U> after)
Returns the composition if this converter applied before another one.- Type Parameters:
U- The target type of the other converter.- Parameters:
after- The other converter, applied after this one.- Returns:
- The composition of this converter applied before
after. - Throws:
IllegalArgumentException- Whenafterisnullor no adaptation ofafteris possible.
-
adapt
default <R,U> Converter<R,U> adapt(Class<R> sourceClass, Class<U> targetClass)
Returns an adaptation of this converter to a specific source and target classes.- Type Parameters:
R- The source type.U- The target type.- Parameters:
sourceClass- The source class.targetClass- The target class.- Returns:
- An adaptation of this converter that matches
sourceClassandtargetClass. - Throws:
IllegalArgumentException- When no adaptation is possible.
-
adapt
static <S,T> Converter<S,T> adapt(Class<S> sourceClass, Class<T> targetClass, Converter<?,?> delegate)
Returns an adaptation of a converter to specific source and target classes.- Type Parameters:
S- The source type.T- The target type.- Parameters:
sourceClass- The source class.targetClass- The target class.delegate- The converter to adapt.- Returns:
- An adaptation of
delegatethat matchessourceClassandtargetClass. - Throws:
IllegalArgumentException- When no adaptation is possible.
-
-