org.springframework.batch.item.file.transform

## Class DefaultFieldSet

- java.lang.Object
- - org.springframework.batch.item.file.transform.DefaultFieldSet

- All Implemented Interfaces:
    FieldSet

      public class DefaultFieldSet
      extends java.lang.Object
      implements FieldSet

  Default implementation of `FieldSet` using Java using Java primitive and standard types and utilities. Strings are trimmed before parsing by default, and so are plain String values.
  Author:
    Rob Harrop, Dave Syer

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultFieldSet(java.lang.String[] tokens)` Create a FieldSet with anonymous tokens.
    `DefaultFieldSet(java.lang.String[] tokens, java.lang.String[] names)` Create a FieldSet with named tokens.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(java.lang.Object object)`
    `int` | `getFieldCount()` Return the number of fields in this '`FieldSet`'.
    `java.lang.String[]` | `getNames()` Accessor for the names of the fields.
    `java.util.Properties` | `getProperties()` Construct name-value pairs from the field names and string values.
    `java.lang.String[]` | `getValues()`
    `int` | `hashCode()`
    `boolean` | `hasNames()` Check if there are names defined for the fields.
    `protected int` | `indexOf(java.lang.String name)` Retrieve the index of where a specified column is located based on the `name` parameter.
    `protected java.lang.String` | `readAndTrim(int index)` Read and trim the `String` value at '`index`'.
    `java.math.BigDecimal` | `readBigDecimal(int index)` Read the `BigDecimal` value at index '`index`'.
    `java.math.BigDecimal` | `readBigDecimal(int index, java.math.BigDecimal defaultValue)` Read the `BigDecimal` value at index '`index`', returning the supplied `defaultValue` if the trimmed string value at index '`index`' is blank.
    `java.math.BigDecimal` | `readBigDecimal(java.lang.String name)` Read the `BigDecimal` value from column with given '`name`.
    `java.math.BigDecimal` | `readBigDecimal(java.lang.String name, java.math.BigDecimal defaultValue)` Read the `BigDecimal` value from column with given '`name`, returning the supplied `defaultValue` if the trimmed string value at index '`index`' is blank.
    `boolean` | `readBoolean(int index)` Read the '`boolean`' value at index '`index`'.
    `boolean` | `readBoolean(int index, java.lang.String trueValue)` Read the '`boolean`' value at index '`index`'.
    `boolean` | `readBoolean(java.lang.String name)` Read the '`boolean`' value from column with given '`name`'.
    `boolean` | `readBoolean(java.lang.String name, java.lang.String trueValue)` Read the '`boolean`' value from column with given '`name`'.
    `byte` | `readByte(int index)` Read the '`byte`' value at index '`index`'.
    `byte` | `readByte(java.lang.String name)` Read the '`byte`' value from column with given '`name`'.
    `char` | `readChar(int index)` Read the '`char`' value at index '`index`'.
    `char` | `readChar(java.lang.String name)` Read the '`char`' value from column with given '`name`'.
    `java.util.Date` | `readDate(int index)` Read the `java.util.Date` value in default format at designated column `index`.
    `java.util.Date` | `readDate(int index, java.util.Date defaultValue)` Read the `java.util.Date` value in default format at designated column `index`.
    `java.util.Date` | `readDate(int index, java.lang.String pattern)` Read the `java.util.Date` value in default format at designated column `index`.
    `java.util.Date` | `readDate(int index, java.lang.String pattern, java.util.Date defaultValue)` Read the `java.util.Date` value in default format at designated column `index`.
    `java.util.Date` | `readDate(java.lang.String name)` Read the `java.sql.Date` value in given format from column with given `name`.
    `java.util.Date` | `readDate(java.lang.String name, java.util.Date defaultValue)` Read the `java.sql.Date` value in given format from column with given `name`.
    `java.util.Date` | `readDate(java.lang.String name, java.lang.String pattern)` Read the `java.sql.Date` value in given format from column with given `name`.
    `java.util.Date` | `readDate(java.lang.String name, java.lang.String pattern, java.util.Date defaultValue)` Read the `java.sql.Date` value in given format from column with given `name`.
    `double` | `readDouble(int index)` Read the '`double`' value at index '`index`'.
    `double` | `readDouble(java.lang.String name)` Read the '`double`' value from column with given '`name`.
    `float` | `readFloat(int index)` Read the '`float`' value at index '`index`'.
    `float` | `readFloat(java.lang.String name)` Read the '`float`' value from column with given '`name`.
    `int` | `readInt(int index)` Read the '`int`' value at index '`index`'.
    `int` | `readInt(int index, int defaultValue)` Read the '`int`' value at index '`index`', using the supplied `defaultValue` if the field value is blank.
    `int` | `readInt(java.lang.String name)` Read the '`int`' value from column with given '`name`'.
    `int` | `readInt(java.lang.String name, int defaultValue)` Read the '`int`' value from column with given '`name`', using the supplied `defaultValue` if the field value is blank.
    `long` | `readLong(int index)` Read the '`long`' value at index '`index`'.
    `long` | `readLong(int index, long defaultValue)` Read the '`long`' value at index '`index`', using the supplied `defaultValue` if the field value is blank.
    `long` | `readLong(java.lang.String name)` Read the '`long`' value from column with given '`name`'.
    `long` | `readLong(java.lang.String name, long defaultValue)` Read the '`long`' value from column with given '`name`', using the supplied `defaultValue` if the field value is blank.
    `java.lang.String` | `readRawString(int index)` Read the `String` value at index '`index`' including trailing whitespace (don't trim).
    `java.lang.String` | `readRawString(java.lang.String name)` Read the `String` value from column with given '`name`' including trailing whitespace (don't trim).
    `short` | `readShort(int index)` Read the '`short`' value at index '`index`'.
    `short` | `readShort(java.lang.String name)` Read the '`short`' value from column with given '`name`'.
    `java.lang.String` | `readString(int index)` Read the `String` value at index '`index`'.
    `java.lang.String` | `readString(java.lang.String name)` Read the `String` value from column with given '`name`'.
    `void` | `setDateFormat(java.text.DateFormat dateFormat)` The `DateFormat` to use for parsing numbers.
    `void` | `setNumberFormat(java.text.NumberFormat numberFormat)` The `NumberFormat` to use for parsing numbers.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultFieldSet

          public DefaultFieldSet(java.lang.String[] tokens)

      Create a FieldSet with anonymous tokens. They can only be retrieved by column number.
      Parameters:
        `tokens` - the token values
      See Also:
        `FieldSet.readString(int)`

    - #### DefaultFieldSet

          public DefaultFieldSet(java.lang.String[] tokens,
                                 java.lang.String[] names)

      Create a FieldSet with named tokens. The token values can then be retrieved either by name or by column number.
      Parameters:
        `tokens` - the token values
        `names` - the names of the tokens
      See Also:
        `FieldSet.readString(String)`

  - ### Method Detail

    - #### setNumberFormat

          public final void setNumberFormat(java.text.NumberFormat numberFormat)

      The `NumberFormat` to use for parsing numbers. If unset the US locale will be used ('.' as decimal place).
      Parameters:
        `numberFormat` - the `NumberFormat` to use for number parsing

    - #### setDateFormat

          public void setDateFormat(java.text.DateFormat dateFormat)

      The `DateFormat` to use for parsing numbers. If unset the default pattern is ISO standard `yyyy/MM/dd`.
      Parameters:
        `dateFormat` - the `DateFormat` to use for date parsing

    - #### getNames

          public java.lang.String[] getNames()

      Description copied from interface: `FieldSet`
      Accessor for the names of the fields.
      Specified by:
        `getNames` in interface `FieldSet`
      Returns:
        the names

    - #### hasNames

          public boolean hasNames()

      Description copied from interface: `FieldSet`
      Check if there are names defined for the fields.
      Specified by:
        `hasNames` in interface `FieldSet`
      Returns:
        true if there are names for the fields

    - #### getValues

          public java.lang.String[] getValues()

      Specified by:
        `getValues` in interface `FieldSet`
      Returns:
        fields wrapped by this '`FieldSet`' instance as String values.

    - #### readString

          public java.lang.String readString(int index)

      Description copied from interface: `FieldSet`
      Read the `String` value at index '`index`'.
      Specified by:
        `readString` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        `String` containing the value at the index.

    - #### readString

          public java.lang.String readString(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the `String` value from column with given '`name`'.
      Specified by:
        `readString` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        `String` containing the value from the specified `name`.

    - #### readRawString

          public java.lang.String readRawString(int index)

      Description copied from interface: `FieldSet`
      Read the `String` value at index '`index`' including trailing whitespace (don't trim).
      Specified by:
        `readRawString` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        `String` containing the value from the specified `index`.

    - #### readRawString

          public java.lang.String readRawString(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the `String` value from column with given '`name`' including trailing whitespace (don't trim).
      Specified by:
        `readRawString` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        `String` containing the value from the specified `name`.

    - #### readBoolean

          public boolean readBoolean(int index)

      Description copied from interface: `FieldSet`
      Read the '`boolean`' value at index '`index`'.
      Specified by:
        `readBoolean` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        boolean containing the value from the specified `index`.

    - #### readBoolean

          public boolean readBoolean(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the '`boolean`' value from column with given '`name`'.
      Specified by:
        `readBoolean` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        boolean containing the value from the specified `name`.

    - #### readBoolean

          public boolean readBoolean(int index,
                                     java.lang.String trueValue)

      Description copied from interface: `FieldSet`
      Read the '`boolean`' value at index '`index`'.
      Specified by:
        `readBoolean` in interface `FieldSet`
      Parameters:
        `index` - the field index.
        `trueValue` - the value that signifies `true`; case-sensitive.
      Returns:
        boolean containing the value from the specified `index`.

    - #### readBoolean

          public boolean readBoolean(java.lang.String name,
                                     java.lang.String trueValue)

      Description copied from interface: `FieldSet`
      Read the '`boolean`' value from column with given '`name`'.
      Specified by:
        `readBoolean` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
        `trueValue` - the value that signifies `true`; case-sensitive.
      Returns:
        boolean containing the value from the specified `name`.

    - #### readChar

          public char readChar(int index)

      Description copied from interface: `FieldSet`
      Read the '`char`' value at index '`index`'.
      Specified by:
        `readChar` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        char containing the value from the specified `index`.

    - #### readChar

          public char readChar(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the '`char`' value from column with given '`name`'.
      Specified by:
        `readChar` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        char containing the value from the specified `name`.

    - #### readByte

          public byte readByte(int index)

      Description copied from interface: `FieldSet`
      Read the '`byte`' value at index '`index`'.
      Specified by:
        `readByte` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        byte containing the value from the specified `index`.

    - #### readByte

          public byte readByte(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the '`byte`' value from column with given '`name`'.
      Specified by:
        `readByte` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        byte containing the value from the specified `name`.

    - #### readShort

          public short readShort(int index)

      Description copied from interface: `FieldSet`
      Read the '`short`' value at index '`index`'.
      Specified by:
        `readShort` in interface `FieldSet`
      Parameters:
        `index` - the field `index`.
      Returns:
        short containing the value from the specified index.

    - #### readShort

          public short readShort(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the '`short`' value from column with given '`name`'.
      Specified by:
        `readShort` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        short containing the value from the specified `name`.

    - #### readInt

          public int readInt(int index)

      Description copied from interface: `FieldSet`
      Read the '`int`' value at index '`index`'.
      Specified by:
        `readInt` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        int containing the value from the specified index.

    - #### readInt

          public int readInt(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the '`int`' value from column with given '`name`'.
      Specified by:
        `readInt` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        int containing the value from the specified `name`.

    - #### readInt

          public int readInt(int index,
                             int defaultValue)

      Description copied from interface: `FieldSet`
      Read the '`int`' value at index '`index`', using the supplied `defaultValue` if the field value is blank.
      Specified by:
        `readInt` in interface `FieldSet`
      Parameters:
        `index` - the field index.
        `defaultValue` - the value to use if the field value is blank.
      Returns:
        int containing the value from the specified index.

    - #### readInt

          public int readInt(java.lang.String name,
                             int defaultValue)

      Description copied from interface: `FieldSet`
      Read the '`int`' value from column with given '`name`', using the supplied `defaultValue` if the field value is blank.
      Specified by:
        `readInt` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
        `defaultValue` - the value to use if the field value is blank.
      Returns:
        int containing the value from the specified `name`.

    - #### readLong

          public long readLong(int index)

      Description copied from interface: `FieldSet`
      Read the '`long`' value at index '`index`'.
      Specified by:
        `readLong` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        long containing the value from the specified index.

    - #### readLong

          public long readLong(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the '`long`' value from column with given '`name`'.
      Specified by:
        `readLong` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        long containing the value from the specified `name`.

    - #### readLong

          public long readLong(int index,
                               long defaultValue)

      Description copied from interface: `FieldSet`
      Read the '`long`' value at index '`index`', using the supplied `defaultValue` if the field value is blank.
      Specified by:
        `readLong` in interface `FieldSet`
      Parameters:
        `index` - the field index.
        `defaultValue` - the value to use if the field value is blank.
      Returns:
        long containing the value from the specified index.

    - #### readLong

          public long readLong(java.lang.String name,
                               long defaultValue)

      Description copied from interface: `FieldSet`
      Read the '`long`' value from column with given '`name`', using the supplied `defaultValue` if the field value is blank.
      Specified by:
        `readLong` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
        `defaultValue` - the value to use if the field value is blank.
      Returns:
        long containing the value from the specified `name`.

    - #### readFloat

          public float readFloat(int index)

      Description copied from interface: `FieldSet`
      Read the '`float`' value at index '`index`'.
      Specified by:
        `readFloat` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        float containing the value from the specified index.

    - #### readFloat

          public float readFloat(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the '`float`' value from column with given '`name`.
      Specified by:
        `readFloat` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        float containing the value from the specified `name`.

    - #### readDouble

          public double readDouble(int index)

      Description copied from interface: `FieldSet`
      Read the '`double`' value at index '`index`'.
      Specified by:
        `readDouble` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        double containing the value from the specified index.

    - #### readDouble

          public double readDouble(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the '`double`' value from column with given '`name`.
      Specified by:
        `readDouble` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        double containing the value from the specified `name`.

    - #### readBigDecimal

          public java.math.BigDecimal readBigDecimal(int index)

      Description copied from interface: `FieldSet`
      Read the `BigDecimal` value at index '`index`'.
      Specified by:
        `readBigDecimal` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        `BigDecimal` containing the value from the specified index.

    - #### readBigDecimal

          public java.math.BigDecimal readBigDecimal(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the `BigDecimal` value from column with given '`name`.
      Specified by:
        `readBigDecimal` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        `BigDecimal` containing the value from the specified `name`.

    - #### readBigDecimal

          public java.math.BigDecimal readBigDecimal(int index,
                                                     java.math.BigDecimal defaultValue)

      Description copied from interface: `FieldSet`
      Read the `BigDecimal` value at index '`index`', returning the supplied `defaultValue` if the trimmed string value at index '`index`' is blank.
      Specified by:
        `readBigDecimal` in interface `FieldSet`
      Parameters:
        `index` - the field index.
        `defaultValue` - the value to use if the field value is blank.
      Returns:
        `BigDecimal` containing the value from the specified index.

    - #### readBigDecimal

          public java.math.BigDecimal readBigDecimal(java.lang.String name,
                                                     java.math.BigDecimal defaultValue)

      Description copied from interface: `FieldSet`
      Read the `BigDecimal` value from column with given '`name`, returning the supplied `defaultValue` if the trimmed string value at index '`index`' is blank.
      Specified by:
        `readBigDecimal` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
        `defaultValue` - the default value to use if the field is blank
      Returns:
        `BigDecimal` containing the value from the specified `name`.

    - #### readDate

          public java.util.Date readDate(int index)

      Description copied from interface: `FieldSet`
      Read the `java.util.Date` value in default format at designated column `index`.
      Specified by:
        `readDate` in interface `FieldSet`
      Parameters:
        `index` - the field index.
      Returns:
        `Date` containing the value from the specified index.

    - #### readDate

          public java.util.Date readDate(int index,
                                         java.util.Date defaultValue)

      Description copied from interface: `FieldSet`
      Read the `java.util.Date` value in default format at designated column `index`.
      Specified by:
        `readDate` in interface `FieldSet`
      Parameters:
        `index` - the field index.
        `defaultValue` - the default value to use if the field is blank
      Returns:
        `Date` containing the value from the specified index.

    - #### readDate

          public java.util.Date readDate(java.lang.String name)

      Description copied from interface: `FieldSet`
      Read the `java.sql.Date` value in given format from column with given `name`.
      Specified by:
        `readDate` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
      Returns:
        `Date` containing the value from the specified `name`.

    - #### readDate

          public java.util.Date readDate(java.lang.String name,
                                         java.util.Date defaultValue)

      Description copied from interface: `FieldSet`
      Read the `java.sql.Date` value in given format from column with given `name`.
      Specified by:
        `readDate` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
        `defaultValue` - the default value to use if the field is blank
      Returns:
        `Date` containing the value from the specified `name`.

    - #### readDate

          public java.util.Date readDate(int index,
                                         java.lang.String pattern)

      Description copied from interface: `FieldSet`
      Read the `java.util.Date` value in default format at designated column `index`.
      Specified by:
        `readDate` in interface `FieldSet`
      Parameters:
        `index` - the field index.
        `pattern` - the pattern describing the date and time format
      Returns:
        `Date` containing the value from the specified index.

    - #### readDate

          public java.util.Date readDate(int index,
                                         java.lang.String pattern,
                                         java.util.Date defaultValue)

      Description copied from interface: `FieldSet`
      Read the `java.util.Date` value in default format at designated column `index`.
      Specified by:
        `readDate` in interface `FieldSet`
      Parameters:
        `index` - the field index.
        `pattern` - the pattern describing the date and time format
        `defaultValue` - the default value to use if the field is blank
      Returns:
        `Date` containing the value from the specified index.

    - #### readDate

          public java.util.Date readDate(java.lang.String name,
                                         java.lang.String pattern)

      Description copied from interface: `FieldSet`
      Read the `java.sql.Date` value in given format from column with given `name`.
      Specified by:
        `readDate` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
        `pattern` - the pattern describing the date and time format
      Returns:
        `Date` containing the value from the specified `name`.

    - #### readDate

          public java.util.Date readDate(java.lang.String name,
                                         java.lang.String pattern,
                                         java.util.Date defaultValue)

      Description copied from interface: `FieldSet`
      Read the `java.sql.Date` value in given format from column with given `name`.
      Specified by:
        `readDate` in interface `FieldSet`
      Parameters:
        `name` - the field `name`.
        `pattern` - the pattern describing the date and time format
        `defaultValue` - the default value to use if the field is blank
      Returns:
        `Date` containing the value from the specified `name`.

    - #### getFieldCount

          public int getFieldCount()

      Description copied from interface: `FieldSet`
      Return the number of fields in this '`FieldSet`'.
      Specified by:
        `getFieldCount` in interface `FieldSet`
      Returns:
        int containing the number of fields in this field set.

    - #### readAndTrim

          protected java.lang.String readAndTrim(int index)

      Read and trim the `String` value at '`index`'.
      Parameters:
        `index` - the offset in the token array to obtain the value to be trimmed.
      Returns:
        null if the field value is `null`.

    - #### indexOf

          protected int indexOf(java.lang.String name)

      Retrieve the index of where a specified column is located based on the `name` parameter.
      Parameters:
        `name` - the value to search in the `List` of names.
      Returns:
        the index in the `List` of names where the name was found.
      Throws:
        `java.lang.IllegalArgumentException` - if a column with given name is not defined.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### equals

          public boolean equals(java.lang.Object object)

      Overrides:
        `equals` in class `java.lang.Object`
      See Also:
        `Object.equals(java.lang.Object)`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### getProperties

          public java.util.Properties getProperties()

      Description copied from interface: `FieldSet`
      Construct name-value pairs from the field names and string values. Null values are omitted.
      Specified by:
        `getProperties` in interface `FieldSet`
      Returns:
        some properties representing the field set.