Class NullConversion<I,O>
- java.lang.Object
-
- com.univocity.parsers.conversions.NullConversion<I,O>
-
- Type Parameters:
I
- The object type resulting from conversions of values of type O.O
- The object type resulting from conversions of values of type I.
- All Implemented Interfaces:
Conversion<I,O>
- Direct Known Subclasses:
ObjectConversion
,ToStringConversion
public abstract class NullConversion<I,O> extends java.lang.Object implements Conversion<I,O>
Default implementation for conversions from input Objects of type I to output Objects of type OExtending 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.
-
-
Field Summary
Fields Modifier and Type Field Description private O
valueOnNullInput
private I
valueOnNullOutput
-
Constructor Summary
Constructors Constructor Description NullConversion()
Creates a Conversion from an object to another object of a different type, with default values to return when the input is null.NullConversion(O valueOnNullInput, I valueOnNullOutput)
Creates a Conversion from an object to another object of a different type, with default values to return when the input is null.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description O
execute(I input)
Converts the given instance of type I to an instance of Oprotected abstract O
fromInput(I input)
Creates an instance of O from a I objectO
getValueOnNullInput()
returns a default value of type O to be returned when the input of type I is null.I
getValueOnNullOutput()
returns default instance of I to be returned when an input of type O is null.I
revert(O input)
Converts a value of type O back to a value of type Ivoid
setValueOnNullInput(O valueOnNullInput)
defines the default value of type O which should be returned whenexecute(Object)
is invoked with a null I..void
setValueOnNullOutput(I valueOnNullOutput)
defines the default value of type I which should be returned whenrevert(Object)
is invoked with a null O.protected abstract I
undo(O input)
Converts a value of type O back to I.
-
-
-
Constructor Detail
-
NullConversion
public NullConversion()
Creates a Conversion from an object to another object of a different type, 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
-
NullConversion
public NullConversion(O valueOnNullInput, I valueOnNullOutput)
Creates a Conversion from an object to another object of a different type, with default values to return when the input is null.- Parameters:
valueOnNullInput
- default value of type O to be returned when the input object I is null. Used whenexecute(Object)
is invoked.valueOnNullOutput
- default value of type I to be returned when an input of type I is null. Used whenrevert(Object)
is invoked.
-
-
Method Detail
-
execute
public O execute(I input)
Converts the given instance of type I to an instance of O- Specified by:
execute
in interfaceConversion<I,O>
- Parameters:
input
- the input value of type I to be converted to an object of type O- Returns:
- the conversion result, or the value of
valueOnNullInput
if the input object is null.
-
fromInput
protected abstract O fromInput(I input)
Creates an instance of O from a I object- Parameters:
input
- The object of type I to be converted to O- Returns:
- an instance of O, converted from the I input.
-
revert
public I revert(O input)
Converts a value of type O back to a value of type I- Specified by:
revert
in interfaceConversion<I,O>
- Parameters:
input
- the input of type O to be converted to an output I- Returns:
- the conversion result, or the value of
valueOnNullOutput
if the input object is null.
-
undo
protected abstract I undo(O input)
Converts a value of type O back to I.- Parameters:
input
- the input object to be converted to I- Returns:
- the conversion result
-
getValueOnNullInput
public O getValueOnNullInput()
returns a default value of type O to be returned when the input of type I is null. Used whenexecute(Object)
is invoked.- Returns:
- the default value of type O used when converting from a null I
-
getValueOnNullOutput
public I getValueOnNullOutput()
returns default instance of I to be returned when an input of type O is null. Used whenrevert(Object)
is invoked.- Returns:
- the default I instance used when converting from a null O
-
setValueOnNullInput
public void setValueOnNullInput(O valueOnNullInput)
defines the default value of type O which should be returned whenexecute(Object)
is invoked with a null I..- Parameters:
valueOnNullInput
- the default value of type T when converting from a null input
-
setValueOnNullOutput
public void setValueOnNullOutput(I valueOnNullOutput)
defines the default value of type I which should be returned whenrevert(Object)
is invoked with a null O.- Parameters:
valueOnNullOutput
- a default value of type I when converting from a null input
-
-