Class ObjectConversion<T>
java.lang.Object
com.univocity.parsers.conversions.NullConversion<String,T>
com.univocity.parsers.conversions.ObjectConversion<T>
- Type Parameters:
T- The object type resulting from conversions of String values.
- All Implemented Interfaces:
Conversion<String,T>
- Direct Known Subclasses:
BigDecimalConversion,BigIntegerConversion,BooleanConversion,ByteConversion,CalendarConversion,CharacterConversion,DateConversion,DoubleConversion,EnumConversion,FloatConversion,IntegerConversion,LongConversion,NumericConversion,ShortConversion
Default implementation for conversions from an input String to Objects of a given type T
Extending classes must implement a proper String to T conversion in fromString(String)
This abstract class provides default results for conversions when the input is null.
It also provides a default implementation of revert(Object) that returns the result of input.toString()
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a Conversion from String to an Object with default values to return when the input is null.ObjectConversion(T valueIfStringIsNull, String valueIfObjectIsNull) Creates a Conversion from String to an Object with default values to return when the input is null. -
Method Summary
Modifier and TypeMethodDescriptionConverts the given String to an instance of Tprotected final TCreates an instance of T from a String representation.protected abstract TfromString(String input) Creates an instance of T from a String representation.returns default String value to be returned when an input of type T is null.returns a default value of type T to be returned when the input String is null.Converts a value of type T back to a StringvoidsetValueIfObjectIsNull(String valueIfObjectIsNull) returns default value of type T which should be returned when the input String is null.voidsetValueIfStringIsNull(T valueIfStringIsNull) defines a default value of type T which should be returned when the input String is null.protected final StringConverts a value of type O back to I.Methods inherited from class com.univocity.parsers.conversions.NullConversion
getValueOnNullInput, getValueOnNullOutput, setValueOnNullInput, setValueOnNullOutput
-
Constructor Details
-
ObjectConversion
public ObjectConversion()Creates a Conversion from String to an Object with default values to return when the input is null. The default constructor assumes the output of a conversion should be null when input is null -
ObjectConversion
Creates a Conversion from String to an Object with default values to return when the input is null.- Parameters:
valueIfStringIsNull- default value of type T to be returned when the input String is null. Used whenexecute(String)is invoked.valueIfObjectIsNull- default String value to be returned when an input of type T is null. Used whenrevert(Object)is invoked.
-
-
Method Details
-
execute
Converts the given String to an instance of T- Specified by:
executein interfaceConversion<String,T> - Overrides:
executein classNullConversion<String,T> - Parameters:
input- the input String to be converted to an object of type T- Returns:
- the conversion result, or the value of
getValueIfStringIsNull()if the input String is null.
-
fromInput
Creates an instance of T from a String representation.- Specified by:
fromInputin classNullConversion<String,T> - Parameters:
input- The String to be converted to T- Returns:
- an instance of T, converted from the String input.
-
fromString
Creates an instance of T from a String representation.- Parameters:
input- The String to be converted to T- Returns:
- an instance of T, converted from the String input.
-
revert
Converts a value of type T back to a StringThis is a general implementation that simply returns the result of input.toString()
- Specified by:
revertin interfaceConversion<String,T> - Overrides:
revertin classNullConversion<String,T> - Parameters:
input- the input of type T to be converted to a String- Returns:
- the conversion result, or the value of
getValueIfObjectIsNull()if the input object is null.
-
undo
Description copied from class:NullConversionConverts a value of type O back to I.- Specified by:
undoin classNullConversion<String,T> - Parameters:
input- the input object to be converted to I- Returns:
- the conversion result
-
getValueIfStringIsNull
returns a default value of type T to be returned when the input String is null. Used whenexecute(String)is invoked.- Returns:
- the default value of type T used when converting from a null input
-
getValueIfObjectIsNull
returns default String value to be returned when an input of type T is null. Used whenrevert(Object)is invoked.- Returns:
- the default String value used when converting from a null input
-
setValueIfStringIsNull
defines a default value of type T which should be returned when the input String is null. Used whenexecute(String)is invoked.- Parameters:
valueIfStringIsNull- the default value of type T when converting from a null input
-
setValueIfObjectIsNull
returns default value of type T which should be returned when the input String is null. Used whenrevert(Object)is invoked.- Parameters:
valueIfObjectIsNull- a default value of type T when converting from a null input
-