org.springframework.batch.item.file.mapping
Class DefaultFieldSet

java.lang.Object
  extended by org.springframework.batch.item.file.mapping.DefaultFieldSet
All Implemented Interfaces:
FieldSet

public class DefaultFieldSet
extends 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
DefaultFieldSet(String[] tokens)
           
DefaultFieldSet(String[] tokens, String[] names)
           
 
Method Summary
 boolean equals(Object object)
           
 int getFieldCount()
          Return the number of fields in this 'FieldSet'.
 String[] getNames()
          Accessor for the names of the fields.
 Properties getProperties()
          Construct name-value pairs from the field names and string values.
 String[] getValues()
           
 int hashCode()
           
 boolean hasNames()
          Check if there are names defined for the fields.
protected  int indexOf(String name)
          Read and trim the String value from column with given 'name.
protected  String readAndTrim(int index)
          Read and trim the String value at 'index'.
 BigDecimal readBigDecimal(int index)
          Read the BigDecimal value at index 'index'.
 BigDecimal readBigDecimal(int index, BigDecimal defaultValue)
          Read the BigDecimal value at index 'index', returning the supplied defaultValue if the trimmed string value at index 'index' is blank.
 BigDecimal readBigDecimal(String name)
          Read the BigDecimal value from column with given 'name.
 BigDecimal readBigDecimal(String name, 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, String trueValue)
          Read the 'boolean' value at index 'index'.
 boolean readBoolean(String name)
          Read the 'boolean' value from column with given 'name'.
 boolean readBoolean(String name, String trueValue)
          Read the 'boolean' value from column with given 'name'.
 byte readByte(int index)
          Read the 'byte' value at index 'index'.
 byte readByte(String name)
          Read the 'byte' value from column with given 'name'.
 char readChar(int index)
          Read the 'char' value at index 'index'.
 char readChar(String name)
          Read the 'char' value from column with given 'name'.
 Date readDate(int index)
          Read the java.util.Date value in default format at designated column index.
 Date readDate(int index, String pattern)
          Read the java.util.Date value in default format at designated column index.
 Date readDate(String name)
          Read the java.sql.Date value in given format from column with given name.
 Date readDate(String name, String pattern)
          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(String name)
          Read the 'double' value from column with given 'name.
 float readFloat(int index)
          Read the 'float' value at index 'index'.
 float readFloat(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(String name)
          Read the 'int' value from column with given 'name'.
 int readInt(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(String name)
          Read the 'long' value from column with given 'name'.
 long readLong(String name, long defaultValue)
          Read the 'long' value from column with given 'name', using the supplied defaultValue if the field value is blank.
 String readRawString(int index)
          Read the String value at index 'index' including trailing whitespace (don't trim).
 String readRawString(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(String name)
          Read the 'short' value from column with given 'name'.
 String readString(int index)
          Read the String value at index 'index'.
 String readString(String name)
          Read the String value from column with given 'name'.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultFieldSet

public DefaultFieldSet(String[] tokens)

DefaultFieldSet

public DefaultFieldSet(String[] tokens,
                       String[] names)
Method Detail

getNames

public 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 String[] getValues()
Specified by:
getValues in interface FieldSet
Returns:
fields wrapped by this 'FieldSet' instance as String values.

readString

public 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.

readString

public String readString(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.

readRawString

public 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.

readRawString

public String readRawString(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.

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.

readBoolean

public boolean readBoolean(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.

readBoolean

public boolean readBoolean(int index,
                           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.

readBoolean

public boolean readBoolean(String name,
                           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.

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.

readChar

public char readChar(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.

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.

readByte

public byte readByte(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.

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.

readShort

public short readShort(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.

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.

readInt

public int readInt(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.

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..

readInt

public int readInt(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.

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.

readLong

public long readLong(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.

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..

readLong

public long readLong(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.

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.

readFloat

public float readFloat(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.

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.

readDouble

public double readDouble(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.

readBigDecimal

public 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.

readBigDecimal

public BigDecimal readBigDecimal(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.

readBigDecimal

public BigDecimal readBigDecimal(int index,
                                 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.

readBigDecimal

public BigDecimal readBigDecimal(String name,
                                 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.

readDate

public 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.

readDate

public Date readDate(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.

readDate

public Date readDate(int index,
                     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

readDate

public Date readDate(String name,
                     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

getFieldCount

public int getFieldCount()
Description copied from interface: FieldSet
Return the number of fields in this 'FieldSet'.

Specified by:
getFieldCount in interface FieldSet

readAndTrim

protected String readAndTrim(int index)
Read and trim the String value at 'index'.

Throws:
NullPointerException - if the field value is null.

indexOf

protected int indexOf(String name)
Read and trim the String value from column with given 'name.

Throws:
IllegalArgumentException - if a column with given name is not defined.

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object object)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getProperties

public 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.


Copyright © 2009 SpringSource. All Rights Reserved.