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
Base interface of typed converters.
A Converter is a Function with additional properties:
- The class of source/input type.
- The class of target/result type.
- Some configuration parameters.
- Author:
- Damien Carbonne
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault <R,U> Converter<R, U> Returns an adaptation of this converter to a specific source and target classes.static <S,T> Converter<S, T> Returns an adaptation of a converter to specific source and target classes.Returns the composition if this converter applied before another one.andThenRaw(Converter<?, U> after) Returns the composition if this converter applied before another one.default TApplies 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> Returns an adaptation of this converter to other source and target classes.Returns the composition of this converter applied after another one.composeRaw(Converter<R, ?> before) Returns the composition of this converter applied after another one.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.Returns a converter that first tries to convert using this converter, and falls back to other ones in case of failure.singleton(C instance)
-
Field Details
-
SOURCE_CLASS
-
TARGET_CLASS
-
META_FARGS
-
-
Method Details
-
getSourceClass
- Returns:
- The class of source objects.
-
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.
-
getTargetClass
- Returns:
- The class of target objects.
-
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
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
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
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
Returnstruewhen a source and target classes are compliant.- Parameters:
sourceClass- The source class.targetClass- The target class.- Returns:
truewhensourceandtargetclasses are compliant.
-
isMatchingSourceClass
Returnstruewhen a class matches source class.clsand source class are the same (after wrapping).- Parameters:
cls- The class.- Returns:
truewhenclsmatches source class.
-
isMatchingTargetClass
Returnstruewhen a class matches target class.clsand target class are the same (after wrapping).- Parameters:
cls- The class.- Returns:
truewhenclsmatches target class.
-
areMatchingSourceAndTargetClasses
Returnstruewhen a source and target classes are matching.- Parameters:
sourceClass- The source class.targetClass- The target class.- Returns:
truewhensourceandtargetclasses are matching.
-
compose
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
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
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
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
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
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.
-
orElseRaw
-
adapt
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.
-
singleton
-