Class NullStringConversion
- java.lang.Object
-
- com.univocity.parsers.conversions.NullStringConversion
-
- All Implemented Interfaces:
Conversion<java.lang.Object,java.lang.Object>
public class NullStringConversion extends java.lang.Object implements Conversion<java.lang.Object,java.lang.Object>
Converts Strings to null and vice versaThis class supports multiple representations of null values. For example, you can define conversions from different Strings such as "N/A, ?, -" to null.
The reverse conversion from a null to String (in
revert(Object)
will return the first String provided in this class constructor if the object is null.Using the previous example, a call to
revert(Object)
will produce "N/A".
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
defaultNullString
private java.util.Set<java.lang.String>
nullStrings
-
Constructor Summary
Constructors Constructor Description NullStringConversion(java.lang.String... nullRepresentations)
Creates conversions from Strings to null.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
execute(java.lang.Object input)
Converts an Object to null.java.lang.Object
revert(java.lang.Object input)
Converts a null input to a String representation.
-
-
-
Constructor Detail
-
NullStringConversion
public NullStringConversion(java.lang.String... nullRepresentations)
Creates conversions from Strings to null.The list of Strings that identify nulls are mandatory.
- Parameters:
nullRepresentations
- Strings that identify a true value. The first element will be returned when executingrevert(Object)
-
-
Method Detail
-
execute
public java.lang.Object execute(java.lang.Object input)
Converts an Object to null. The string representation of the object will be used to match the string elements provided in the constructor.- Specified by:
execute
in interfaceConversion<java.lang.Object,java.lang.Object>
- Parameters:
input
- an Object to be converted to null.- Returns:
- null if the string representation of the object matches any one of the Strings provided in the constructor of this class. Otherwise, the original object will be returned.
-
revert
public java.lang.Object revert(java.lang.Object input)
Converts a null input to a String representation. The String returned will be the first element provided in the constructor of this class.- Specified by:
revert
in interfaceConversion<java.lang.Object,java.lang.Object>
- Parameters:
input
- an Object that, if null, will be transformed to a String.- Returns:
- If the input is null, the string representation for null objects. Otherwise, the original object will be returned.
-
-