Top Description Fields Constructors Methods
com.univocity.parsers.conversions

public Class NullStringConversion

extends Object
implements Conversion<Object, Object>
Class Inheritance
All Implemented Interfaces
com.univocity.parsers.conversions.Conversion
Imports
com.univocity.parsers.common.*, java.util.*

Converts Strings to null and vice versa

This 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 NullStringConversion#revert(Object) will return the first String provided in this class constructor if the object is null.

Using the previous example, a call to NullStringConversion#revert(Object) will produce "N/A".

Author
Univocity Software Pty Ltd - [email protected]

Field Summary

Modifier and TypeField and Description
private final String
private final Set<String>

Constructor Summary

AccessConstructor and Description
public
NullStringConversion(String...
Strings that identify a true value. The first element will be returned when executing NullStringConversion#revert(Object)
nullRepresentations
)

Creates conversions from Strings to null.

Method Summary

Modifier and TypeMethod and Description
public Object

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.
execute
(Object
an Object to be converted to null.
input
)

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

Converts an Object to null.
public Object

Returns:

If the input is null, the string representation for null objects. Otherwise, the original object will be returned.
revert
(Object
an Object that, if null, will be transformed to a String.
input
)

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

Converts a null input to a String representation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultNullStringback to summary
private final String defaultNullString
nullStringsback to summary
private final Set<String> nullStrings

Constructor Detail

NullStringConversionback to summary
public NullStringConversion(String... nullRepresentations)

Creates conversions from Strings to null.

The list of Strings that identify nulls are mandatory.

Parameters
nullRepresentations:String[]

Strings that identify a true value. The first element will be returned when executing NullStringConversion#revert(Object)

Method Detail

executeback to summary
public Object execute(Object input)

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

Converts an Object to null. The string representation of the object will be used to match the string elements provided in the constructor.

Parameters
input:Object

an Object to be converted to null.

Returns:Object

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.

Annotations
@Override
revertback to summary
public Object revert(Object input)

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

Converts a null input to a String representation. The String returned will be the first element provided in the constructor of this class.

Parameters
input:Object

an Object that, if null, will be transformed to a String.

Returns:Object

If the input is null, the string representation for null objects. Otherwise, the original object will be returned.

Annotations
@Override