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 ofFieldSetusing 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 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 Description booleanequals(java.lang.Object object)intgetFieldCount()Return the number of fields in this 'FieldSet'.java.lang.String[]getNames()Accessor for the names of the fields.java.util.PropertiesgetProperties()Construct name-value pairs from the field names and string values.java.lang.String[]getValues()inthashCode()booleanhasNames()Check if there are names defined for the fields.protected intindexOf(java.lang.String name)Retrieve the index of where a specified column is located based on thenameparameter.protected java.lang.StringreadAndTrim(int index)Read and trim theStringvalue at 'index'.java.math.BigDecimalreadBigDecimal(int index)Read theBigDecimalvalue at index 'index'.java.math.BigDecimalreadBigDecimal(int index, java.math.BigDecimal defaultValue)Read theBigDecimalvalue at index 'index', returning the supplieddefaultValueif the trimmed string value at index 'index' is blank.java.math.BigDecimalreadBigDecimal(java.lang.String name)Read theBigDecimalvalue from column with given 'name.java.math.BigDecimalreadBigDecimal(java.lang.String name, java.math.BigDecimal defaultValue)Read theBigDecimalvalue from column with given 'name, returning the supplieddefaultValueif the trimmed string value at index 'index' is blank.booleanreadBoolean(int index)Read the 'boolean' value at index 'index'.booleanreadBoolean(int index, java.lang.String trueValue)Read the 'boolean' value at index 'index'.booleanreadBoolean(java.lang.String name)Read the 'boolean' value from column with given 'name'.booleanreadBoolean(java.lang.String name, java.lang.String trueValue)Read the 'boolean' value from column with given 'name'.bytereadByte(int index)Read the 'byte' value at index 'index'.bytereadByte(java.lang.String name)Read the 'byte' value from column with given 'name'.charreadChar(int index)Read the 'char' value at index 'index'.charreadChar(java.lang.String name)Read the 'char' value from column with given 'name'.java.util.DatereadDate(int index)Read thejava.util.Datevalue in default format at designated columnindex.java.util.DatereadDate(int index, java.lang.String pattern)Read thejava.util.Datevalue in default format at designated columnindex.java.util.DatereadDate(int index, java.lang.String pattern, java.util.Date defaultValue)Read thejava.util.Datevalue in default format at designated columnindex.java.util.DatereadDate(int index, java.util.Date defaultValue)Read thejava.util.Datevalue in default format at designated columnindex.java.util.DatereadDate(java.lang.String name)Read thejava.sql.Datevalue in given format from column with givenname.java.util.DatereadDate(java.lang.String name, java.lang.String pattern)Read thejava.sql.Datevalue in given format from column with givenname.java.util.DatereadDate(java.lang.String name, java.lang.String pattern, java.util.Date defaultValue)Read thejava.sql.Datevalue in given format from column with givenname.java.util.DatereadDate(java.lang.String name, java.util.Date defaultValue)Read thejava.sql.Datevalue in given format from column with givenname.doublereadDouble(int index)Read the 'double' value at index 'index'.doublereadDouble(java.lang.String name)Read the 'double' value from column with given 'name.floatreadFloat(int index)Read the 'float' value at index 'index'.floatreadFloat(java.lang.String name)Read the 'float' value from column with given 'name.intreadInt(int index)Read the 'int' value at index 'index'.intreadInt(int index, int defaultValue)Read the 'int' value at index 'index', using the supplieddefaultValueif the field value is blank.intreadInt(java.lang.String name)Read the 'int' value from column with given 'name'.intreadInt(java.lang.String name, int defaultValue)Read the 'int' value from column with given 'name', using the supplieddefaultValueif the field value is blank.longreadLong(int index)Read the 'long' value at index 'index'.longreadLong(int index, long defaultValue)Read the 'long' value at index 'index', using the supplieddefaultValueif the field value is blank.longreadLong(java.lang.String name)Read the 'long' value from column with given 'name'.longreadLong(java.lang.String name, long defaultValue)Read the 'long' value from column with given 'name', using the supplieddefaultValueif the field value is blank.java.lang.StringreadRawString(int index)Read theStringvalue at index 'index' including trailing whitespace (don't trim).java.lang.StringreadRawString(java.lang.String name)Read theStringvalue from column with given 'name' including trailing whitespace (don't trim).shortreadShort(int index)Read the 'short' value at index 'index'.shortreadShort(java.lang.String name)Read the 'short' value from column with given 'name'.java.lang.StringreadString(int index)Read theStringvalue at index 'index'.java.lang.StringreadString(java.lang.String name)Read theStringvalue from column with given 'name'.voidsetDateFormat(java.text.DateFormat dateFormat)TheDateFormatto use for parsing numbers.voidsetNumberFormat(java.text.NumberFormat numberFormat)TheNumberFormatto use for parsing numbers.java.lang.StringtoString()
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 valuesnames- the names of the tokens- See Also:
FieldSet.readString(String)
Method Detail
setNumberFormat
public final void setNumberFormat(java.text.NumberFormat numberFormat)
TheNumberFormatto use for parsing numbers. If unset the US locale will be used ('.' as decimal place).- Parameters:
numberFormat- theNumberFormatto use for number parsing
setDateFormat
public void setDateFormat(java.text.DateFormat dateFormat)
TheDateFormatto use for parsing numbers. If unset the default pattern is ISO standardyyyy/MM/dd.- Parameters:
dateFormat- theDateFormatto use for date parsing
getNames
public java.lang.String[] getNames()
Description copied from interface:FieldSetAccessor for the names of the fields.
hasNames
public boolean hasNames()
Description copied from interface:FieldSetCheck if there are names defined for the fields.
getValues
public java.lang.String[] getValues()
readString
public java.lang.String readString(int index)
Description copied from interface:FieldSetRead theStringvalue at index 'index'.- Specified by:
readStringin interfaceFieldSet- Parameters:
index- the field index.- Returns:
Stringcontaining the value at the index.
readString
public java.lang.String readString(java.lang.String name)
Description copied from interface:FieldSetRead theStringvalue from column with given 'name'.- Specified by:
readStringin interfaceFieldSet- Parameters:
name- the fieldname.- Returns:
Stringcontaining the value from the specifiedname.
readRawString
public java.lang.String readRawString(int index)
Description copied from interface:FieldSetRead theStringvalue at index 'index' including trailing whitespace (don't trim).- Specified by:
readRawStringin interfaceFieldSet- Parameters:
index- the field index.- Returns:
Stringcontaining the value from the specifiedindex.
readRawString
public java.lang.String readRawString(java.lang.String name)
Description copied from interface:FieldSetRead theStringvalue from column with given 'name' including trailing whitespace (don't trim).- Specified by:
readRawStringin interfaceFieldSet- Parameters:
name- the fieldname.- Returns:
Stringcontaining the value from the specifiedname.
readBoolean
public boolean readBoolean(int index)
Description copied from interface:FieldSetRead the 'boolean' value at index 'index'.- Specified by:
readBooleanin interfaceFieldSet- 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:FieldSetRead the 'boolean' value from column with given 'name'.- Specified by:
readBooleanin interfaceFieldSet- Parameters:
name- the fieldname.- Returns:
- boolean containing the value from the specified
name.
readBoolean
public boolean readBoolean(int index, java.lang.String trueValue)Description copied from interface:FieldSetRead the 'boolean' value at index 'index'.- Specified by:
readBooleanin interfaceFieldSet- Parameters:
index- the field index.trueValue- the value that signifiestrue; 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:FieldSetRead the 'boolean' value from column with given 'name'.- Specified by:
readBooleanin interfaceFieldSet- Parameters:
name- the fieldname.trueValue- the value that signifiestrue; case-sensitive.- Returns:
- boolean containing the value from the specified
name.
readChar
public char readChar(int index)
Description copied from interface:FieldSetRead the 'char' value at index 'index'.
readChar
public char readChar(java.lang.String name)
Description copied from interface:FieldSetRead the 'char' value from column with given 'name'.
readByte
public byte readByte(int index)
Description copied from interface:FieldSetRead the 'byte' value at index 'index'.
readByte
public byte readByte(java.lang.String name)
Description copied from interface:FieldSetRead the 'byte' value from column with given 'name'.
readShort
public short readShort(int index)
Description copied from interface:FieldSetRead the 'short' value at index 'index'.
readShort
public short readShort(java.lang.String name)
Description copied from interface:FieldSetRead the 'short' value from column with given 'name'.
readInt
public int readInt(int index)
Description copied from interface:FieldSetRead the 'int' value at index 'index'.
readInt
public int readInt(java.lang.String name)
Description copied from interface:FieldSetRead the 'int' value from column with given 'name'.
readInt
public int readInt(int index, int defaultValue)Description copied from interface:FieldSetRead the 'int' value at index 'index', using the supplieddefaultValueif the field value is blank.
readInt
public int readInt(java.lang.String name, int defaultValue)Description copied from interface:FieldSetRead the 'int' value from column with given 'name', using the supplieddefaultValueif the field value is blank.
readLong
public long readLong(int index)
Description copied from interface:FieldSetRead the 'long' value at index 'index'.
readLong
public long readLong(java.lang.String name)
Description copied from interface:FieldSetRead the 'long' value from column with given 'name'.
readLong
public long readLong(int index, long defaultValue)Description copied from interface:FieldSetRead the 'long' value at index 'index', using the supplieddefaultValueif the field value is blank.
readLong
public long readLong(java.lang.String name, long defaultValue)Description copied from interface:FieldSetRead the 'long' value from column with given 'name', using the supplieddefaultValueif the field value is blank.
readFloat
public float readFloat(int index)
Description copied from interface:FieldSetRead the 'float' value at index 'index'.
readFloat
public float readFloat(java.lang.String name)
Description copied from interface:FieldSetRead the 'float' value from column with given 'name.
readDouble
public double readDouble(int index)
Description copied from interface:FieldSetRead the 'double' value at index 'index'.- Specified by:
readDoublein interfaceFieldSet- 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:FieldSetRead the 'double' value from column with given 'name.- Specified by:
readDoublein interfaceFieldSet- Parameters:
name- the fieldname.- Returns:
- double containing the value from the specified
name.
readBigDecimal
public java.math.BigDecimal readBigDecimal(int index)
Description copied from interface:FieldSetRead theBigDecimalvalue at index 'index'.- Specified by:
readBigDecimalin interfaceFieldSet- Parameters:
index- the field index.- Returns:
BigDecimalcontaining the value from the specified index.
readBigDecimal
public java.math.BigDecimal readBigDecimal(java.lang.String name)
Description copied from interface:FieldSetRead theBigDecimalvalue from column with given 'name.- Specified by:
readBigDecimalin interfaceFieldSet- Parameters:
name- the fieldname.- Returns:
BigDecimalcontaining the value from the specifiedname.
readBigDecimal
public java.math.BigDecimal readBigDecimal(int index, java.math.BigDecimal defaultValue)Description copied from interface:FieldSetRead theBigDecimalvalue at index 'index', returning the supplieddefaultValueif the trimmed string value at index 'index' is blank.- Specified by:
readBigDecimalin interfaceFieldSet- Parameters:
index- the field index.defaultValue- the value to use if the field value is blank.- Returns:
BigDecimalcontaining the value from the specified index.
readBigDecimal
public java.math.BigDecimal readBigDecimal(java.lang.String name, java.math.BigDecimal defaultValue)Description copied from interface:FieldSetRead theBigDecimalvalue from column with given 'name, returning the supplieddefaultValueif the trimmed string value at index 'index' is blank.- Specified by:
readBigDecimalin interfaceFieldSet- Parameters:
name- the fieldname.defaultValue- the default value to use if the field is blank- Returns:
BigDecimalcontaining the value from the specifiedname.
readDate
public java.util.Date readDate(int index)
Description copied from interface:FieldSetRead thejava.util.Datevalue in default format at designated columnindex.
readDate
public java.util.Date readDate(int index, java.util.Date defaultValue)Description copied from interface:FieldSetRead thejava.util.Datevalue in default format at designated columnindex.
readDate
public java.util.Date readDate(java.lang.String name)
Description copied from interface:FieldSetRead thejava.sql.Datevalue in given format from column with givenname.
readDate
public java.util.Date readDate(java.lang.String name, java.util.Date defaultValue)Description copied from interface:FieldSetRead thejava.sql.Datevalue in given format from column with givenname.
readDate
public java.util.Date readDate(int index, java.lang.String pattern)Description copied from interface:FieldSetRead thejava.util.Datevalue in default format at designated columnindex.
readDate
public java.util.Date readDate(int index, java.lang.String pattern, java.util.Date defaultValue)Description copied from interface:FieldSetRead thejava.util.Datevalue in default format at designated columnindex.
readDate
public java.util.Date readDate(java.lang.String name, java.lang.String pattern)Description copied from interface:FieldSetRead thejava.sql.Datevalue in given format from column with givenname.
readDate
public java.util.Date readDate(java.lang.String name, java.lang.String pattern, java.util.Date defaultValue)Description copied from interface:FieldSetRead thejava.sql.Datevalue in given format from column with givenname.
getFieldCount
public int getFieldCount()
Description copied from interface:FieldSetReturn the number of fields in this 'FieldSet'.- Specified by:
getFieldCountin interfaceFieldSet- Returns:
- int containing the number of fields in this field set.
readAndTrim
protected java.lang.String readAndTrim(int index)
Read and trim theStringvalue 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 thenameparameter.- Parameters:
name- the value to search in theListof names.- Returns:
- the index in the
Listof 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:
toStringin classjava.lang.Object
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(java.lang.Object)
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
getProperties
public java.util.Properties getProperties()
Description copied from interface:FieldSetConstruct name-value pairs from the field names and string values. Null values are omitted.- Specified by:
getPropertiesin interfaceFieldSet- Returns:
- some properties representing the field set.