Top Description Constructors Methods
com.univocity.parsers.conversions

public abstract Class ObjectConversion<T>

extends NullConversion<String, T>
Class Inheritance
Known Direct Subclasses
com.univocity.parsers.conversions.ShortConversion, com.univocity.parsers.conversions.BigDecimalConversion, com.univocity.parsers.conversions.BigIntegerConversion, com.univocity.parsers.conversions.BooleanConversion, com.univocity.parsers.conversions.ByteConversion, com.univocity.parsers.conversions.CalendarConversion, com.univocity.parsers.conversions.CharacterConversion, com.univocity.parsers.conversions.DateConversion, com.univocity.parsers.conversions.DoubleConversion, com.univocity.parsers.conversions.EnumConversion, com.univocity.parsers.conversions.FloatConversion, com.univocity.parsers.conversions.IntegerConversion, com.univocity.parsers.conversions.LongConversion, com.univocity.parsers.conversions.NumericConversion
Type Parameters
<T>
The object type resulting from conversions of String values.

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 ObjectConversion#fromString(String)

This abstract class provides default results for conversions when the input is null.

It also provides a default implementation of ObjectConversion#revert(Object) that returns the result of input.toString()

Author
Univocity Software Pty Ltd - [email protected]

Constructor Summary

AccessConstructor and Description
public
ObjectConversion()

Creates a Conversion from String to an Object with default values to return when the input is null.

public
ObjectConversion(T
default value of type T to be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.
valueIfStringIsNull
,
String
default String value to be returned when an input of type T is null. Used when ObjectConversion#revert(Object) is invoked.
valueIfObjectIsNull
)

Creates a Conversion from String to an Object with default values to return when the input is null.

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

the conversion result, or the value of ObjectConversion#getValueIfStringIsNull() if the input String is null.
execute
(String
the input String to be converted to an object of type T
input
)

Overrides com.univocity.parsers.conversions.NullConversion.execute.

Implements com.univocity.parsers.conversions.Conversion.execute.

Converts the given String to an instance of T
protected final T

Returns:

an instance of T, converted from the String input.
fromInput
(String
The String to be converted to T
input
)

Implements abstract com.univocity.parsers.conversions.NullConversion.fromInput.

Creates an instance of T from a String representation.
protected abstract T

Returns:

an instance of T, converted from the String input.
fromString
(String
The String to be converted to T
input
)

Creates an instance of T from a String representation.

public String

Returns:

the default String value used when converting from a null input
getValueIfObjectIsNull
()

returns default String value to be returned when an input of type T is null.

public T

Returns:

the default value of type T used when converting from a null input
getValueIfStringIsNull
()

returns a default value of type T to be returned when the input String is null.

public String

Returns:

the conversion result, or the value of ObjectConversion#getValueIfObjectIsNull() if the input object is null.
revert
(T
the input of type T to be converted to a String
input
)

Overrides com.univocity.parsers.conversions.NullConversion.revert.

Implements com.univocity.parsers.conversions.Conversion.revert.

Converts a value of type T back to a String

This is a general implementation that simply returns the result of input.toString()

public void
setValueIfObjectIsNull(String
a default value of type T when converting from a null input
valueIfObjectIsNull
)

returns default value of type T which should be returned when the input String is null.

public void
setValueIfStringIsNull(T
the default value of type T when converting from a null input
valueIfStringIsNull
)

defines a default value of type T which should be returned when the input String is null.

protected final String
undo(T
the input object to be converted to I
input
)

Implements abstract com.univocity.parsers.conversions.NullConversion.undo.

Converts a value of type O back to I.
Inherited from com.univocity.parsers.conversions.NullConversion:
getValueOnNullInputgetValueOnNullOutputsetValueOnNullInputsetValueOnNullOutput

Constructor Detail

ObjectConversionback to summary
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

ObjectConversionback to summary
public ObjectConversion(T valueIfStringIsNull, String valueIfObjectIsNull)

Creates a Conversion from String to an Object with default values to return when the input is null.

Parameters
valueIfStringIsNull:T

default value of type T to be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.

valueIfObjectIsNull:String

default String value to be returned when an input of type T is null. Used when ObjectConversion#revert(Object) is invoked.

Method Detail

executeback to summary
public T execute(String input)

Overrides com.univocity.parsers.conversions.NullConversion.execute.

Implements com.univocity.parsers.conversions.Conversion.execute.

Converts the given String to an instance of T

Parameters
input:String

the input String to be converted to an object of type T

Returns:T

the conversion result, or the value of ObjectConversion#getValueIfStringIsNull() if the input String is null.

Annotations
@Override
fromInputback to summary
protected final T fromInput(String input)

Implements abstract com.univocity.parsers.conversions.NullConversion.fromInput.

Creates an instance of T from a String representation.

Parameters
input:String

The String to be converted to T

Returns:T

an instance of T, converted from the String input.

fromStringback to summary
protected abstract T fromString(String input)

Creates an instance of T from a String representation.

Parameters
input:String

The String to be converted to T

Returns:T

an instance of T, converted from the String input.

getValueIfObjectIsNullback to summary
public String getValueIfObjectIsNull()

returns default String value to be returned when an input of type T is null. Used when ObjectConversion#revert(Object) is invoked.

Returns:String

the default String value used when converting from a null input

getValueIfStringIsNullback to summary
public T getValueIfStringIsNull()

returns a default value of type T to be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.

Returns:T

the default value of type T used when converting from a null input

revertback to summary
public String revert(T input)

Overrides com.univocity.parsers.conversions.NullConversion.revert.

Implements com.univocity.parsers.conversions.Conversion.revert.

Converts a value of type T back to a String

This is a general implementation that simply returns the result of input.toString()

Parameters
input:T

the input of type T to be converted to a String

Returns:String

the conversion result, or the value of ObjectConversion#getValueIfObjectIsNull() if the input object is null.

Annotations
@Override
setValueIfObjectIsNullback to summary
public void setValueIfObjectIsNull(String valueIfObjectIsNull)

returns default value of type T which should be returned when the input String is null. Used when ObjectConversion#revert(Object) is invoked.

Parameters
valueIfObjectIsNull:String

a default value of type T when converting from a null input

setValueIfStringIsNullback to summary
public void setValueIfStringIsNull(T valueIfStringIsNull)

defines a default value of type T which should be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.

Parameters
valueIfStringIsNull:T

the default value of type T when converting from a null input

undoback to summary
protected final String undo(T input)

Implements abstract com.univocity.parsers.conversions.NullConversion.undo.

Doc from com.univocity.parsers.conversions.NullConversion.undo.

Converts a value of type O back to I.

Parameters
input:T

the input object to be converted to I

Returns:String

the conversion result

Annotations
@Override