Class DefaultFieldSet
java.lang.Object
org.springframework.batch.item.file.transform.DefaultFieldSet
- All Implemented Interfaces:
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
ConstructorDescriptionDefaultFieldSet
(String[] tokens) Create a FieldSet with anonymous tokens.DefaultFieldSet
(String[] tokens, String[] names) Create a FieldSet with named tokens. -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
Return the number of fields in this 'FieldSet
'.String[]
getNames()
Accessor for the names of the fields.Construct name-value pairs from the field names and string values.String[]
int
hashCode()
boolean
hasNames()
Check if there are names defined for the fields.protected int
Retrieve the index of where a specified column is located based on thename
parameter.protected String
readAndTrim
(int index) Read and trim theString
value at 'index
'.readBigDecimal
(int index) Read theBigDecimal
value at index 'index
'.readBigDecimal
(int index, BigDecimal defaultValue) Read theBigDecimal
value at index 'index
', returning the supplieddefaultValue
if the trimmed string value at index 'index
' is blank.readBigDecimal
(String name) Read theBigDecimal
value from column with given 'name
.readBigDecimal
(String name, BigDecimal defaultValue) Read theBigDecimal
value from column with given 'name
, returning the supplieddefaultValue
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
Read the 'byte
' value from column with given 'name
'.char
readChar
(int index) Read the 'char
' value at index 'index
'.char
Read the 'char
' value from column with given 'name
'.readDate
(int index) Read thejava.util.Date
value in default format at designated columnindex
.Read thejava.util.Date
value in default format at designated columnindex
.Read thejava.util.Date
value in default format at designated columnindex
.Read thejava.util.Date
value in default format at designated columnindex
.Read thejava.sql.Date
value in given format from column with givenname
.Read thejava.sql.Date
value in given format from column with givenname
.Read thejava.sql.Date
value in given format from column with givenname
.Read thejava.sql.Date
value in given format from column with givenname
.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
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 supplieddefaultValue
if the field value is blank.int
Read the 'int
' value from column with given 'name
'.int
Read the 'int
' value from column with given 'name
', using the supplieddefaultValue
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 supplieddefaultValue
if the field value is blank.long
Read the 'long
' value from column with given 'name
'.long
Read the 'long
' value from column with given 'name
', using the supplieddefaultValue
if the field value is blank.readRawString
(int index) Read theString
value at index 'index
' including trailing whitespace (don't trim).readRawString
(String name) Read theString
value from column with given 'name
' including trailing whitespace (don't trim).short
readShort
(int index) Read the 'short
' value at index 'index
'.short
Read the 'short
' value from column with given 'name
'.readString
(int index) Read theString
value at index 'index
'.readString
(String name) Read theString
value from column with given 'name
'.void
setDateFormat
(DateFormat dateFormat) TheDateFormat
to use for parsing numbers.final void
setNumberFormat
(NumberFormat numberFormat) TheNumberFormat
to use for parsing numbers.toString()
-
Constructor Details
-
DefaultFieldSet
Create a FieldSet with anonymous tokens. They can only be retrieved by column number.- Parameters:
tokens
- the token values- See Also:
-
DefaultFieldSet
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:
-
-
Method Details
-
setNumberFormat
TheNumberFormat
to use for parsing numbers. If unset the US locale will be used ('.' as decimal place).- Parameters:
numberFormat
- theNumberFormat
to use for number parsing
-
setDateFormat
TheDateFormat
to use for parsing numbers. If unset the default pattern is ISO standardyyyy/MM/dd
.- Parameters:
dateFormat
- theDateFormat
to use for date parsing
-
getNames
Description copied from interface:FieldSet
Accessor for the names of the fields. -
hasNames
public boolean hasNames()Description copied from interface:FieldSet
Check if there are names defined for the fields. -
getValues
-
readString
Description copied from interface:FieldSet
Read theString
value at index 'index
'.- Specified by:
readString
in interfaceFieldSet
- Parameters:
index
- the field index.- Returns:
String
containing the value at the index.
-
readString
Description copied from interface:FieldSet
Read theString
value from column with given 'name
'.- Specified by:
readString
in interfaceFieldSet
- Parameters:
name
- the fieldname
.- Returns:
String
containing the value from the specifiedname
.
-
readRawString
Description copied from interface:FieldSet
Read theString
value at index 'index
' including trailing whitespace (don't trim).- Specified by:
readRawString
in interfaceFieldSet
- Parameters:
index
- the field index.- Returns:
String
containing the value from the specifiedindex
.
-
readRawString
Description copied from interface:FieldSet
Read theString
value from column with given 'name
' including trailing whitespace (don't trim).- Specified by:
readRawString
in interfaceFieldSet
- Parameters:
name
- the fieldname
.- Returns:
String
containing the value from the specifiedname
.
-
readBoolean
public boolean readBoolean(int index) Description copied from interface:FieldSet
Read the 'boolean
' value at index 'index
'.- Specified by:
readBoolean
in interfaceFieldSet
- Parameters:
index
- the field index.- Returns:
- boolean containing the value from the specified
index
.
-
readBoolean
Description copied from interface:FieldSet
Read the 'boolean
' value from column with given 'name
'.- Specified by:
readBoolean
in interfaceFieldSet
- Parameters:
name
- the fieldname
.- Returns:
- boolean containing the value from the specified
name
.
-
readBoolean
Description copied from interface:FieldSet
Read the 'boolean
' value at index 'index
'.- Specified by:
readBoolean
in interfaceFieldSet
- Parameters:
index
- the field index.trueValue
- the value that signifiestrue
; case-sensitive.- Returns:
- boolean containing the value from the specified
index
.
-
readBoolean
Description copied from interface:FieldSet
Read the 'boolean
' value from column with given 'name
'.- Specified by:
readBoolean
in 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:FieldSet
Read the 'char
' value at index 'index
'. -
readChar
Description copied from interface:FieldSet
Read the 'char
' value from column with given 'name
'. -
readByte
public byte readByte(int index) Description copied from interface:FieldSet
Read the 'byte
' value at index 'index
'. -
readByte
Description copied from interface:FieldSet
Read the 'byte
' value from column with given 'name
'. -
readShort
public short readShort(int index) Description copied from interface:FieldSet
Read the 'short
' value at index 'index
'. -
readShort
Description copied from interface:FieldSet
Read the 'short
' value from column with given 'name
'. -
readInt
public int readInt(int index) Description copied from interface:FieldSet
Read the 'int
' value at index 'index
'. -
readInt
Description copied from interface:FieldSet
Read the 'int
' value from column with given 'name
'. -
readInt
public int readInt(int index, int defaultValue) Description copied from interface:FieldSet
Read the 'int
' value at index 'index
', using the supplieddefaultValue
if the field value is blank. -
readInt
Description copied from interface:FieldSet
Read the 'int
' value from column with given 'name
', using the supplieddefaultValue
if the field value is blank. -
readLong
public long readLong(int index) Description copied from interface:FieldSet
Read the 'long
' value at index 'index
'. -
readLong
Description copied from interface:FieldSet
Read the 'long
' value from column with given 'name
'. -
readLong
public long readLong(int index, long defaultValue) Description copied from interface:FieldSet
Read the 'long
' value at index 'index
', using the supplieddefaultValue
if the field value is blank. -
readLong
Description copied from interface:FieldSet
Read the 'long
' value from column with given 'name
', using the supplieddefaultValue
if the field value is blank. -
readFloat
public float readFloat(int index) Description copied from interface:FieldSet
Read the 'float
' value at index 'index
'. -
readFloat
Description copied from interface:FieldSet
Read the 'float
' value from column with given 'name
. -
readDouble
public double readDouble(int index) Description copied from interface:FieldSet
Read the 'double
' value at index 'index
'.- Specified by:
readDouble
in interfaceFieldSet
- Parameters:
index
- the field index.- Returns:
- double containing the value from the specified index.
-
readDouble
Description copied from interface:FieldSet
Read the 'double
' value from column with given 'name
.- Specified by:
readDouble
in interfaceFieldSet
- Parameters:
name
- the fieldname
.- Returns:
- double containing the value from the specified
name
.
-
readBigDecimal
Description copied from interface:FieldSet
Read theBigDecimal
value at index 'index
'.- Specified by:
readBigDecimal
in interfaceFieldSet
- Parameters:
index
- the field index.- Returns:
BigDecimal
containing the value from the specified index.
-
readBigDecimal
Description copied from interface:FieldSet
Read theBigDecimal
value from column with given 'name
.- Specified by:
readBigDecimal
in interfaceFieldSet
- Parameters:
name
- the fieldname
.- Returns:
BigDecimal
containing the value from the specifiedname
.
-
readBigDecimal
Description copied from interface:FieldSet
Read theBigDecimal
value at index 'index
', returning the supplieddefaultValue
if the trimmed string value at index 'index
' is blank.- Specified by:
readBigDecimal
in interfaceFieldSet
- 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
Description copied from interface:FieldSet
Read theBigDecimal
value from column with given 'name
, returning the supplieddefaultValue
if the trimmed string value at index 'index
' is blank.- Specified by:
readBigDecimal
in interfaceFieldSet
- Parameters:
name
- the fieldname
.defaultValue
- the default value to use if the field is blank- Returns:
BigDecimal
containing the value from the specifiedname
.
-
readDate
Description copied from interface:FieldSet
Read thejava.util.Date
value in default format at designated columnindex
. -
readDate
Description copied from interface:FieldSet
Read thejava.util.Date
value in default format at designated columnindex
. -
readDate
Description copied from interface:FieldSet
Read thejava.sql.Date
value in given format from column with givenname
. -
readDate
Description copied from interface:FieldSet
Read thejava.sql.Date
value in given format from column with givenname
. -
readDate
Description copied from interface:FieldSet
Read thejava.util.Date
value in default format at designated columnindex
. -
readDate
Description copied from interface:FieldSet
Read thejava.util.Date
value in default format at designated columnindex
. -
readDate
Description copied from interface:FieldSet
Read thejava.sql.Date
value in given format from column with givenname
. -
readDate
Description copied from interface:FieldSet
Read thejava.sql.Date
value in given format from column with givenname
. -
getFieldCount
public int getFieldCount()Description copied from interface:FieldSet
Return the number of fields in this 'FieldSet
'.- Specified by:
getFieldCount
in interfaceFieldSet
- Returns:
- int containing the number of fields in this field set.
-
readAndTrim
Read and trim theString
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
Retrieve the index of where a specified column is located based on thename
parameter.- Parameters:
name
- the value to search in theList
of names.- Returns:
- the index in the
List
of names where the name was found. - Throws:
IllegalArgumentException
- if a column with given name is not defined.
-
toString
-
equals
-
hashCode
public int hashCode() -
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 interfaceFieldSet
- Returns:
- some properties representing the field set.
-