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

public Class Conversions

extends Object
Class Inheritance
Imports
java.math.*, java.text.*, java.util.*

This class provides default instances of common implementations if com.univocity.parsers.conversions.Conversion, as well as useful methods for obtaining new instances of these.
Author
Univocity Software Pty Ltd - [email protected]

Field Summary

Modifier and TypeField and Description
private static final LowerCaseConversion
private static final ToStringConversion
private static final TrimConversion
private static final UpperCaseConversion

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static FormattedBigDecimalConversion

Returns:

a new instance of FormattedBigDecimalConversion that supports the given number formats
formatToBigDecimal
(String...
list of acceptable numeric patterns. The first pattern in this sequence will be used to convert a BigDecimal into a String in NumericConversion#revert(Number).
numberFormats
)

Returns a new instance of FormattedBigDecimalConversion

public static FormattedBigDecimalConversion

Returns:

a new instance of FormattedBigDecimalConversion that supports the given number formats
formatToBigDecimal
(BigDecimal
default BigDecimal to be returned when the input String is null. Used when FormattedBigDecimalConversion#execute(String) is invoked.
defaultValueForNullString
,
String...
list of acceptable numeric patterns. The first pattern in this sequence will be used to convert a BigDecimal into a String in NumericConversion#revert(Number).
numberFormats
)

Returns a new instance of FormattedBigDecimalConversion

public static FormattedBigDecimalConversion

Returns:

a new instance of FormattedBigDecimalConversion that supports the given number formats
formatToBigDecimal
(BigDecimal
default BigDecimal to be returned when the input String is null. Used when FormattedBigDecimalConversion#execute(String) is invoked.
defaultValueForNullString
,
String
default String value to be returned when a BigDecimal input is null. Used when FormattedBigDecimalConversion#revert(BigDecimal) is invoked.
stringIfNull
,
String...
list of acceptable numeric patterns. The first pattern in this sequence will be used to convert a BigDecimal into a String in NumericConversion#revert(Number).
numberFormats
)

Returns a new instance of FormattedBigDecimalConversion

public static NumericConversion<Number>

Returns:

a new instance of NumericConversion that supports the given number formats
formatToNumber
(String...
list of acceptable numeric patterns. The first pattern in this sequence will be used to convert a Number into a String in NumericConversion#revert(Number).
numberFormats
)

Returns a new instance of NumericConversion

public static <
type of number
T extends Number
>
NumericConversion<T>

Returns:

a new instance of NumericConversion that supports the given number formats
formatToNumber
(Class<T>
type of number to be returned. The resulting instance of Number will be cast to the expected type.
numberType
,
String...
list of acceptable numeric patterns. The first pattern in this sequence will be used to convert a Number into a String in NumericConversion#revert(Number).
numberFormats
)

Returns a new instance of NumericConversion

public static ValidatedConversion

Returns:

new instance of ValidatedConversion configured with the given parameters
noneOf
(String...
list of values that are not allowed.
noneOf
)

Returns a new instance of ValidatedConversion to validate values of a record Nulls and blanks are not be allowed by default.

public static ValidatedConversion

Returns:

a not-blank validator
notBlank
()

Returns a ValidatedConversion that doesn't allow null or blank values

public static ValidatedConversion

Returns:

a value format validator
notBlank
(String
regular expression to match and ensure the value has a given format
regexToMatch
)

Returns a ValidatedConversion that verifies the format of a given value

public static ValidatedConversion

Returns:

a not-null validator
notNull
()

Returns a ValidatedConversion that doesn't allow null values

public static ValidatedConversion

Returns:

new instance of ValidatedConversion configured with the given parameters
oneOf
(String...
list of accepted values.
oneOf
)

Returns a new instance of ValidatedConversion to validate values of a record Nulls and blanks are not be allowed by default.

public static RegexConversion

Returns:

the new instance of RegexConversion created with the given parameters.
replace
(String
the regular expression used to match contents of a given input String
replaceRegex
,
String
the replacement content to replace any contents matched by the given regular expression
replacement
)

Returns a new instance of RegexConversion

public static ToStringConversion

Returns:

a singleton instance of ToStringConversion
string
()

Returns a singleton instance of ToStringConversion

public static BigDecimalConversion

Returns:

a new instance of BigDecimalConversion
toBigDecimal
()

Returns a new instance of BigDecimalConversion

public static BigIntegerConversion

Returns:

a new instance of BigIntegerConversion
toBigInteger
()

Returns a new instance of BigIntegerConversion

public static BooleanConversion

Returns:

a new instance of BooleanConversion with support for multiple representations of true and false
toBoolean
(Boolean
default Boolean value to be returned when the input String is null. Used when BooleanConversion#execute(String) is invoked.
defaultValueForNullString
,
String
default String value to be returned when a Boolean input is null. Used when BooleanConversion#revert(Boolean) is invoked.
defaultValueForNullBoolean
,
String[]
Strings that identify the boolean value true. The first element will be returned when executing BooleanConversion.revert(true)
valuesForTrue
,
String[]
Strings that identify the boolean value false. The first element will be returned when executing BooleanConversion.revert(false)
valuesForFalse
)

Returns a new instance of BooleanConversion

public static BooleanConversion

Returns:

a new instance of BooleanConversion with support for multiple representations of true and false
toBoolean
(Boolean
default Boolean value to be returned when the input String is null. Used when BooleanConversion#execute(String) is invoked.
defaultValueForNullString
,
String
default String value to be returned when a Boolean input is null. Used when BooleanConversion#revert(Boolean) is invoked.
defaultValueForNullBoolean
,
String
String that identify the boolean value true.
valueForTrue
,
String
String that identify the boolean value false.
valueForFalse
)

Returns a new instance of BooleanConversion

public static BooleanConversion

Returns:

a new instance of BooleanConversion with support for multiple representations of true and false
toBoolean
(String[]
Strings that identify the boolean value true. The first element will be returned when executing BooleanConversion.revert(true)
valuesForTrue
,
String[]
Strings that identify the boolean value false. The first element will be returned when executing BooleanConversion.revert(false)
valuesForFalse
)

Returns a new instance of BooleanConversion

public static BooleanConversion

Returns:

a new instance of BooleanConversion with support for multiple representations of true and false
toBoolean
()

Returns a new instance of BooleanConversion that converts the string "true" to true, and the String "false" to false.

public static BooleanConversion

Returns:

a new instance of BooleanConversion with support for multiple representations of true and false
toBoolean
(String
String that identifies the boolean value true.
valueForTrue
,
String
String that identifies the boolean value false.
valueForFalse
)

Returns a new instance of BooleanConversion

public static ByteConversion

Returns:

a new instance of ByteConversion
toByte
()

Returns a new instance of ByteConversion

public static CalendarConversion

Returns:

the new instance of CalendarConversion created with the given parameters.
toCalendar
(Locale
the Locale that determines how the date mask should be formatted.
locale
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Returns a new instance of CalendarConversion

public static CalendarConversion

Returns:

the new instance of CalendarConversion created with the given parameters.
toCalendar
(String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Returns a new instance of CalendarConversion

public static CalendarConversion

Returns:

the new instance of CalendarConversion created with the given parameters.
toCalendar
(Locale
the Locale that determines how the date mask should be formatted.
locale
,
Calendar
default Calendar value to be returned when the input String is null. Used when CalendarConversion#execute(String) is invoked.
dateIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Returns a new instance of CalendarConversion

public static CalendarConversion

Returns:

the new instance of CalendarConversion created with the given parameters.
toCalendar
(Calendar
default Calendar value to be returned when the input String is null. Used when CalendarConversion#execute(String) is invoked.
dateIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Returns a new instance of CalendarConversion

public static CalendarConversion

Returns:

the new instance of CalendarConversion created with the given parameters.
toCalendar
(Locale
the Locale that determines how the date mask should be formatted.
locale
,
Calendar
default Calendar value to be returned when the input String is null. Used when CalendarConversion#execute(String) is invoked.
dateIfNull
,
String
default String value to be returned when a Date input is null. Used when CalendarConversion#revert(Calendar) is invoked.
stringIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Returns a new instance of CalendarConversion

public static CalendarConversion

Returns:

the new instance of CalendarConversion created with the given parameters.
toCalendar
(TimeZone
the TimeZone to be considered
timeZone
,
Locale
the Locale that determines how the date mask should be formatted.
locale
,
Calendar
default Calendar value to be returned when the input String is null. Used when CalendarConversion#execute(String) is invoked.
dateIfNull
,
String
default String value to be returned when a Date input is null. Used when CalendarConversion#revert(Calendar) is invoked.
stringIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Returns a new instance of CalendarConversion

public static CalendarConversion

Returns:

the new instance of CalendarConversion created with the given parameters.
toCalendar
(Calendar
default Calendar value to be returned when the input String is null. Used when CalendarConversion#execute(String) is invoked.
dateIfNull
,
String
default String value to be returned when a Date input is null. Used when CalendarConversion#revert(Calendar) is invoked.
stringIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Returns a new instance of CalendarConversion

public static CharacterConversion

Returns:

a new instance of CharacterConversion
toChar
()

Returns a new instance of CharacterConversion

public static CharacterConversion

Returns:

a new instance of CharacterConversion
toChar
(Character
default Character value to be returned when the input String is null. Used when CharacterConversion#execute(String) is invoked.
defaultValueForNullString
,
String
default String value to be returned when a Character input is null. Used when CharacterConversion#revert(Character) is invoked.
defaultValueForNullChar
)

Returns a new instance of CharacterConversion

public static CharacterConversion

Returns:

a new instance of CharacterConversion
toChar
(Character
default Character value to be returned when the input String is null. Used when CharacterConversion#execute(String) is invoked.
defaultValueForNullString
)

Returns a new instance of CharacterConversion

public static DateConversion

Returns:

the new instance of DateConversion created with the given parameters.
toDate
(Locale
the Locale that determines how the date mask should be formatted.
locale
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Date into a String in DateConversion#revert(Date).
dateFormats
)

Returns a new instance of DateConversion

public static DateConversion

Returns:

the new instance of DateConversion created with the given parameters.
toDate
(String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Date into a String in DateConversion#revert(Date).
dateFormats
)

Returns a new instance of DateConversion

public static DateConversion

Returns:

the new instance of DateConversion created with the given parameters.
toDate
(Locale
the Locale that determines how the date mask should be formatted.
locale
,
Date
default Date value to be returned when the input String is null. Used when DateConversion#execute(String) is invoked.
dateIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Date into a String in DateConversion#revert(Date).
dateFormats
)

Returns a new instance of DateConversion

public static DateConversion

Returns:

the new instance of DateConversion created with the given parameters.
toDate
(Date
default Date value to be returned when the input String is null. Used when DateConversion#execute(String) is invoked.
dateIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Date into a String in DateConversion#revert(Date).
dateFormats
)

Returns a new instance of DateConversion

public static DateConversion

Returns:

the new instance of DateConversion created with the given parameters.
toDate
(TimeZone
the TimeZone of the date to be formatted
timeZone
,
Locale
the Locale that determines how the date mask should be formatted.
locale
,
Date
default Date value to be returned when the input String is null. Used when DateConversion#execute(String) is invoked.
dateIfNull
,
String
default String value to be returned when a Date input is null. Used when DateConversion#revert(Date) is invoked.
stringIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Date into a String in DateConversion#revert(Date).
dateFormats
)

Returns a new instance of DateConversion

public static DateConversion

Returns:

the new instance of DateConversion created with the given parameters.
toDate
(Locale
the Locale that determines how the date mask should be formatted.
locale
,
Date
default Date value to be returned when the input String is null. Used when DateConversion#execute(String) is invoked.
dateIfNull
,
String
default String value to be returned when a Date input is null. Used when DateConversion#revert(Date) is invoked.
stringIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Date into a String in DateConversion#revert(Date).
dateFormats
)

Returns a new instance of DateConversion

public static DateConversion

Returns:

the new instance of DateConversion created with the given parameters.
toDate
(Date
default Date value to be returned when the input String is null. Used when DateConversion#execute(String) is invoked.
dateIfNull
,
String
default String value to be returned when a Date input is null. Used when DateConversion#revert(Date) is invoked.
stringIfNull
,
String...
list of acceptable date patterns. The first pattern in this sequence will be used to convert a Date into a String in DateConversion#revert(Date).
dateFormats
)

Returns a new instance of DateConversion

public static DoubleConversion

Returns:

a new instance of DoubleConversion
toDouble
()

Returns a new instance of DoubleConversion

public static <
the enum type
T extends Enum<T>
>
EnumConversion<T>

Returns:

new instance of EnumConversion
toEnum
(Class<T>
the enumeration type to be converted from/to String
enumType
)

Returns a new instance of EnumConversion

public static <
the enum type
T extends Enum<T>
>
EnumConversion<T>

Returns:

new instance of EnumConversion
toEnum
(Class<T>
the enumeration type to be converted from/to String
enumType
,
EnumSelector...
the selection elements of the enumeration to use for matching Strings.
selectors
)

Returns a new instance of EnumConversion

public static <
the enum type
T extends Enum<T>
>
EnumConversion<T>

Returns:

new instance of EnumConversion
toEnum
(Class<T>
the enumeration type to be converted from/to String
enumType
,
String
name of custom element of the enumeration (attribute or method) whose values should be used to match equivalent Strings.
customEnumElement
,
EnumSelector...
the selection elements of the enumeration to use for matching Strings.
selectors
)

Returns a new instance of EnumConversion

public static <
the enum type
T extends Enum<T>
>
EnumConversion<T>

Returns:

new instance of EnumConversion
toEnum
(Class<T>
the enumeration type to be converted from/to String
enumType
,
T
the default enumeration constant to use if the input String is null
valueIfStringIsNull
,
String
the default String value to use if the input enum constant is null
valueIfEnumIsNull
,
String
name of custom element of the enumeration (attribute or method) whose values should be used to match equivalent Strings.
customEnumElement
,
EnumSelector...
the selection elements of the enumeration to use for matching Strings.
selectors
)

Returns a new instance of EnumConversion

public static FloatConversion

Returns:

a new instance of FloatConversion
toFloat
()

Returns a new instance of FloatConversion

public static FormattedDateConversion

Returns:

new instance of FormattedDateConversion configured with the given parameters
toFormattedDate
(String
Date mask to be be used to convert a date object (i.e. Date or Calendar) into a String.
pattern
)

Returns a new instance of FormattedDateConversion

public static FormattedDateConversion

Returns:

new instance of FormattedDateConversion configured with the given parameters
toFormattedDate
(String
Date mask to be be used to convert a date object (i.e. Date or Calendar) into a String.
pattern
,
String
Default string value to be returned when the input object is null.
valueIfObjectIsNull
)

Returns a new instance of FormattedDateConversion

public static FormattedDateConversion

Returns:

new instance of FormattedDateConversion configured with the given parameters
toFormattedDate
(String
Date mask to be be used to convert a date object (i.e. Date or Calendar) into a String.
pattern
,
Locale
The Locale that determines how the date pattern should be formatted.
locale
)

Returns a new instance of FormattedDateConversion

public static FormattedDateConversion

Returns:

new instance of FormattedDateConversion configured with the given parameters
toFormattedDate
(String
Date mask to be be used to convert a date object (i.e. Date or Calendar) into a String.
pattern
,
Locale
The Locale that determines how the date pattern should be formatted.
locale
,
String
Default string value to be returned when the input object is null.
valueIfObjectIsNull
)

Returns a new instance of FormattedDateConversion

public static IntegerConversion

Returns:

a new instance of IntegerConversion
toInteger
()

Returns a new instance of IntegerConversion

public static LongConversion

Returns:

a new instance of LongConversion
toLong
()

Returns a new instance of LongConversion

public static LowerCaseConversion

Returns:

a singleton instance of LowerCaseConversion
toLowerCase
()

Returns a singleton instance of LowerCaseConversion

public static NullStringConversion

Returns:

the new instance of NullStringConversion created with the given parameters.
toNull
(String...
the sequence of Strings that represent a null value.
nullRepresentations
)

Returns a new instance of NullStringConversion

public static ShortConversion

Returns:

a new instance of ShortConversion
toShort
()

Returns a new instance of ShortConversion

public static UpperCaseConversion

Returns:

a singleton instance of UpperCaseConversion
toUpperCase
()

Returns a singleton instance of UpperCaseConversion

public static TrimConversion

Returns:

a singleton instance of TrimConversion
trim
()

Returns a singleton instance of TrimConversion

public static TrimConversion

Returns:

a trim-to-length conversion
trim
(int
the maximum length a value can contain. Characters after this limit will be discarded.
length
)

Returns a TrimConversion that limits the output to a fixed length

public static ValidatedConversion

Returns:

new instance of ValidatedConversion configured with the given parameters
validate
(boolean
flag to indicate whether values can be null
nullable
,
boolean
flag to indicate whether values can be blank
allowBlanks
)

Returns a ValidatedConversion that checks for nulls or blank values.

public static ValidatedConversion

Returns:

new instance of ValidatedConversion configured with the given parameters
validate
(boolean
flag to indicate whether values can be null
nullable
,
boolean
flag to indicate whether values can be blank
allowBlanks
,
String[]
list of accepted values.
oneOf
,
String[]
list of unacceptable values
noneOf
)

Returns a new instance of ValidatedConversion to validate values of a record

public static ValidatedConversion

Returns:

new instance of ValidatedConversion configured with the given parameters
validate
(boolean
flag to indicate whether values can be null
nullable
,
boolean
flag to indicate whether values can be blank
allowBlanks
,
String
regular expression to match and ensure the value has a given format
regexToMatch
)

Returns a ValidatedConversion that checks for nulls or blank values.

public static ValidatedConversion

Returns:

new instance of ValidatedConversion configured with the given parameters
validate
(boolean
flag to indicate whether values can be null
nullable
,
boolean
flag to indicate whether values can be blank
allowBlanks
,
String[]
list of accepted values.
oneOf
,
String[]
list of unacceptable values
noneOf
,
String
regular expression to match and ensure the value has a given format
regexToMatch
)

Returns a new instance of ValidatedConversion to validate values of a record

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait