com.univocity.parsers.conversions
Class Conversions

java.lang.Object
  extended by com.univocity.parsers.conversions.Conversions

public class Conversions
extends Object

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]

Method Summary
static FormattedBigDecimalConversion formatToBigDecimal(BigDecimal defaultValueForNullString, String... numberFormats)
          Returns a new instance of FormattedBigDecimalConversion
static FormattedBigDecimalConversion formatToBigDecimal(BigDecimal defaultValueForNullString, String stringIfNull, String... numberFormats)
          Returns a new instance of FormattedBigDecimalConversion
static FormattedBigDecimalConversion formatToBigDecimal(String... numberFormats)
          Returns a new instance of FormattedBigDecimalConversion
static NumericConversion<Number> formatToNumber(String... numberFormats)
          Returns a new instance of NumericConversion
static RegexConversion replace(String replaceRegex, String replacement)
          Returns a new instance of RegexConversion
static BigDecimalConversion toBigDecimal()
          Returns a new instance of BigDecimalConversion
static BigIntegerConversion toBigInteger()
          Returns a new instance of BigIntegerConversion
static BooleanConversion toBoolean()
          Returns a new instance of BooleanConversion that converts the string "true" to true, and the String "false" to false.
static BooleanConversion toBoolean(Boolean defaultValueForNullString, String defaultValueForNullBoolean, String[] valuesForTrue, String[] valuesForFalse)
          Returns a new instance of BooleanConversion
static BooleanConversion toBoolean(String[] valuesForTrue, String[] valuesForFalse)
          Returns a new instance of BooleanConversion
static BooleanConversion toBoolean(String valueForTrue, String valueForFalse)
          Returns a new instance of BooleanConversion
static ByteConversion toByte()
          Returns a new instance of ByteConversion
static CalendarConversion toCalendar(Calendar dateIfNull, String... dateFormats)
          Returns a new instance of CalendarConversion
static CalendarConversion toCalendar(Calendar dateIfNull, String stringIfNull, String... dateFormats)
          Returns a new instance of CalendarConversion
static CalendarConversion toCalendar(String... dateFormats)
          Returns a new instance of CalendarConversion
static CharacterConversion toChar()
          Returns a new instance of CharacterConversion
static CharacterConversion toChar(Character defaultValueForNullString)
          Returns a new instance of CharacterConversion
static CharacterConversion toChar(Character defaultValueForNullString, String defaultValueForNullChar)
          Returns a new instance of CharacterConversion
static DateConversion toDate(Date dateIfNull, String... dateFormats)
          Returns a new instance of DateConversion
static DateConversion toDate(Date dateIfNull, String stringIfNull, String... dateFormats)
          Returns a new instance of DateConversion
static DateConversion toDate(String... dateFormats)
          Returns a new instance of DateConversion
static DoubleConversion toDouble()
          Returns a new instance of DoubleConversion
static FloatConversion toFloat()
          Returns a new instance of FloatConversion
static IntegerConversion toInteger()
          Returns a new instance of IntegerConversion
static LongConversion toLong()
          Returns a new instance of LongConversion
static LowerCaseConversion toLowerCase()
          Returns a singleton instance of LowerCaseConversion
static NullStringConversion toNull(String... nullRepresentations)
          Returns a new instance of NullStringConversion
static ShortConversion toShort()
          Returns a new instance of ShortConversion
static UpperCaseConversion toUpperCase()
          Returns a singleton instance of UpperCaseConversion
static TrimConversion trim()
          Returns a singleton instance of TrimConversion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toUpperCase

public static UpperCaseConversion toUpperCase()
Returns a singleton instance of UpperCaseConversion

Returns:
a singleton instance of UpperCaseConversion

toLowerCase

public static LowerCaseConversion toLowerCase()
Returns a singleton instance of LowerCaseConversion

Returns:
a singleton instance of LowerCaseConversion

trim

public static TrimConversion trim()
Returns a singleton instance of TrimConversion

Returns:
a singleton instance of TrimConversion

replace

public static RegexConversion replace(String replaceRegex,
                                      String replacement)
Returns a new instance of RegexConversion

Parameters:
replaceRegex - the regular expression used to match contents in a given input String
replacement - the replacement content to replace any contents matched by the given regular expression
Returns:
the new instance of RegexConversion created with the given parameters.

toNull

public static NullStringConversion toNull(String... nullRepresentations)
Returns a new instance of NullStringConversion

Parameters:
nullRepresentations - the sequence of Strings that represent a null value.
Returns:
the new instance of NullStringConversion created with the given parameters.

toDate

public static DateConversion toDate(String... dateFormats)
Returns a new instance of DateConversion

Parameters:
dateFormats - 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).
Returns:
the new instance of DateConversion created with the given parameters.

toDate

public static DateConversion toDate(Date dateIfNull,
                                    String... dateFormats)
Returns a new instance of DateConversion

Parameters:
dateIfNull - default Date value to be returned when the input String is null. Used when ObjectConversion.execute(String) is invoked.
dateFormats - 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).
Returns:
the new instance of DateConversion created with the given parameters.

toDate

public static DateConversion toDate(Date dateIfNull,
                                    String stringIfNull,
                                    String... dateFormats)
Returns a new instance of DateConversion

Parameters:
dateIfNull - default Date value to be returned when the input String is null. Used when ObjectConversion.execute(String) is invoked.
stringIfNull - default String value to be returned when a Date input is null. Used when DateConversion.revert(Date) is invoked.
dateFormats - 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).
Returns:
the new instance of DateConversion created with the given parameters.

toCalendar

public static CalendarConversion toCalendar(String... dateFormats)
Returns a new instance of CalendarConversion

Parameters:
dateFormats - 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).
Returns:
the new instance of CalendarConversion created with the given parameters.

toCalendar

public static CalendarConversion toCalendar(Calendar dateIfNull,
                                            String... dateFormats)
Returns a new instance of CalendarConversion

Parameters:
dateIfNull - default Calendar value to be returned when the input String is null. Used when ObjectConversion.execute(String) is invoked.
dateFormats - 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).
Returns:
the new instance of CalendarConversion created with the given parameters.

toCalendar

public static CalendarConversion toCalendar(Calendar dateIfNull,
                                            String stringIfNull,
                                            String... dateFormats)
Returns a new instance of CalendarConversion

Parameters:
dateIfNull - default Calendar value to be returned when the input String is null. Used when ObjectConversion.execute(String) is invoked.
stringIfNull - default String value to be returned when a Date input is null. Used when CalendarConversion.revert(Calendar) is invoked.
dateFormats - 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).
Returns:
the new instance of CalendarConversion created with the given parameters.

toByte

public static ByteConversion toByte()
Returns a new instance of ByteConversion

Returns:
a new instance of ByteConversion

toShort

public static ShortConversion toShort()
Returns a new instance of ShortConversion

Returns:
a new instance of ShortConversion

toInteger

public static IntegerConversion toInteger()
Returns a new instance of IntegerConversion

Returns:
a new instance of IntegerConversion

toLong

public static LongConversion toLong()
Returns a new instance of LongConversion

Returns:
a new instance of LongConversion

toBigInteger

public static BigIntegerConversion toBigInteger()
Returns a new instance of BigIntegerConversion

Returns:
a new instance of BigIntegerConversion

toFloat

public static FloatConversion toFloat()
Returns a new instance of FloatConversion

Returns:
a new instance of FloatConversion

toDouble

public static DoubleConversion toDouble()
Returns a new instance of DoubleConversion

Returns:
a new instance of DoubleConversion

toBigDecimal

public static BigDecimalConversion toBigDecimal()
Returns a new instance of BigDecimalConversion

Returns:
a new instance of BigDecimalConversion

formatToNumber

public static NumericConversion<Number> formatToNumber(String... numberFormats)
Returns a new instance of NumericConversion

Parameters:
numberFormats - 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).
Returns:
a new instance of NumericConversion that supports the given number formats

formatToBigDecimal

public static FormattedBigDecimalConversion formatToBigDecimal(String... numberFormats)
Returns a new instance of FormattedBigDecimalConversion

Parameters:
numberFormats - 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).
Returns:
a new instance of FormattedBigDecimalConversion that supports the given number formats

formatToBigDecimal

public static FormattedBigDecimalConversion formatToBigDecimal(BigDecimal defaultValueForNullString,
                                                               String... numberFormats)
Returns a new instance of FormattedBigDecimalConversion

Parameters:
defaultValueForNullString - default BigDecimal to be returned when the input String is null. Used when ObjectConversion.execute(String) is invoked.
numberFormats - 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).
Returns:
a new instance of FormattedBigDecimalConversion that supports the given number formats

formatToBigDecimal

public static FormattedBigDecimalConversion formatToBigDecimal(BigDecimal defaultValueForNullString,
                                                               String stringIfNull,
                                                               String... numberFormats)
Returns a new instance of FormattedBigDecimalConversion

Parameters:
defaultValueForNullString - default BigDecimal to be returned when the input String is null. Used when ObjectConversion.execute(String) is invoked.
stringIfNull - default String value to be returned when a BigDecimal input is null. Used when FormattedBigDecimalConversion#revert(BigDecimal) is invoked.
numberFormats - 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).
Returns:
a new instance of FormattedBigDecimalConversion that supports the given number formats

toBoolean

public static BooleanConversion toBoolean(Boolean defaultValueForNullString,
                                          String defaultValueForNullBoolean,
                                          String[] valuesForTrue,
                                          String[] valuesForFalse)
Returns a new instance of BooleanConversion

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

toBoolean

public static BooleanConversion toBoolean(String[] valuesForTrue,
                                          String[] valuesForFalse)
Returns a new instance of BooleanConversion

Parameters:
valuesForTrue - Strings that identify the boolean value true. The first element will be returned when executing BooleanConversion.revert(true)
valuesForFalse - Strings that identify the boolean value false. The first element will be returned when executing BooleanConversion.revert(false)
Returns:
a new instance of BooleanConversion with support for multiple representations of true and false

toBoolean

public static BooleanConversion toBoolean()
Returns a new instance of BooleanConversion that converts the string "true" to true, and the String "false" to false.

Returns:
a new instance of BooleanConversion with support for multiple representations of true and false

toBoolean

public static BooleanConversion toBoolean(String valueForTrue,
                                          String valueForFalse)
Returns a new instance of BooleanConversion

Parameters:
valueForTrue - String that identifies the boolean value true.
valueForFalse - String that identifies the boolean value false.
Returns:
a new instance of BooleanConversion with support for multiple representations of true and false

toChar

public static CharacterConversion toChar()
Returns a new instance of CharacterConversion

Returns:
a new instance of CharacterConversion

toChar

public static CharacterConversion toChar(Character defaultValueForNullString,
                                         String defaultValueForNullChar)
Returns a new instance of CharacterConversion

Parameters:
defaultValueForNullString - default Character value to be returned when the input String is null. Used when ObjectConversion.execute(String) is invoked.
defaultValueForNullChar - default String value to be returned when a Character input is null. Used when CharacterConversion#revert(Character) is invoked.
Returns:
a new instance of CharacterConversion

toChar

public static CharacterConversion toChar(Character defaultValueForNullString)
Returns a new instance of CharacterConversion

Parameters:
defaultValueForNullString - default Character value to be returned when the input String is null. Used when ObjectConversion.execute(String) is invoked.
Returns:
a new instance of CharacterConversion


Copyright © 2014 uniVocity Software Pty Ltd. All rights reserved.