Interface FieldSet
- All Known Implementing Classes:
DefaultFieldSet
public interface FieldSet
Interface used by flat file input sources to encapsulate concerns of converting an
array of Strings to Java native types. A bit like the role played by
ResultSet
in JDBC, clients will know the name or position of strongly typed fields that they want
to extract.- Author:
- Dave Syer
-
Method Summary
Modifier and TypeMethodDescriptionintReturn 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[]booleanhasNames()Check if there are names defined for the fields.readBigDecimal(int index) Read theBigDecimalvalue at index 'index'.readBigDecimal(int index, BigDecimal defaultValue) Read theBigDecimalvalue at index 'index', returning the supplieddefaultValueif the trimmed string value at index 'index' is blank.readBigDecimal(String name) Read theBigDecimalvalue from column with given 'name.readBigDecimal(String name, 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, String trueValue) Read the 'boolean' value at index 'index'.booleanreadBoolean(String name) Read the 'boolean' value from column with given 'name'.booleanreadBoolean(String name, String trueValue) Read the 'boolean' value from column with given 'name'.bytereadByte(int index) Read the 'byte' value at index 'index'.byteRead the 'byte' value from column with given 'name'.charreadChar(int index) Read the 'char' value at index 'index'.charRead the 'char' value from column with given 'name'.readDate(int index) Read thejava.util.Datevalue in default format at designated columnindex.Read thejava.util.Datevalue in default format at designated columnindex.Read thejava.util.Datevalue in default format at designated columnindex.Read thejava.util.Datevalue in default format at designated columnindex.Read thejava.sql.Datevalue in given format from column with givenname.Read thejava.sql.Datevalue in given format from column with givenname.Read thejava.sql.Datevalue in given format from column with givenname.Read thejava.sql.Datevalue in given format from column with givenname.doublereadDouble(int index) Read the 'double' value at index 'index'.doublereadDouble(String name) Read the 'double' value from column with given 'name.floatreadFloat(int index) Read the 'float' value at index 'index'.floatRead 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.intRead the 'int' value from column with given 'name'.intRead 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.longRead the 'long' value from column with given 'name'.longRead the 'long' value from column with given 'name', using the supplieddefaultValueif the field value is blank.readRawString(int index) Read theStringvalue at index 'index' including trailing whitespace (don't trim).readRawString(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'.shortRead the 'short' value from column with given 'name'.readString(int index) Read theStringvalue at index 'index'.readString(String name) Read theStringvalue from column with given 'name'.
-
Method Details
-
getNames
String[] getNames()Accessor for the names of the fields.- Returns:
- the names
- Throws:
IllegalStateException- if the names are not defined
-
hasNames
boolean hasNames()Check if there are names defined for the fields.- Returns:
- true if there are names for the fields
-
getValues
String[] getValues()- Returns:
- fields wrapped by this '
FieldSet' instance as String values.
-
readString
Read theStringvalue at index 'index'.- Parameters:
index- the field index.- Returns:
Stringcontaining the value at the index.- Throws:
IndexOutOfBoundsException- if theindexis out of bounds.
-
readString
Read theStringvalue from column with given 'name'.- Parameters:
name- the fieldname.- Returns:
Stringcontaining the value from the specifiedname.
-
readRawString
Read theStringvalue at index 'index' including trailing whitespace (don't trim).- Parameters:
index- the field index.- Returns:
Stringcontaining the value from the specifiedindex.- Throws:
IndexOutOfBoundsException- if theindexis out of bounds.
-
readRawString
Read theStringvalue from column with given 'name' including trailing whitespace (don't trim).- Parameters:
name- the fieldname.- Returns:
Stringcontaining the value from the specifiedname.
-
readBoolean
boolean readBoolean(int index) Read the 'boolean' value at index 'index'.- Parameters:
index- the field index.- Returns:
- boolean containing the value from the specified
index. - Throws:
IndexOutOfBoundsException- if theindexis out of bounds.
-
readBoolean
Read the 'boolean' value from column with given 'name'.- Parameters:
name- the fieldname.- Returns:
- boolean containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readBoolean
Read the 'boolean' value at index 'index'.- Parameters:
index- the field index.trueValue- the value that signifiestrue; case-sensitive.- Returns:
- boolean containing the value from the specified
index. - Throws:
IndexOutOfBoundsException- if the index is out of bounds, or if the suppliedtrueValueisnull.
-
readBoolean
Read the 'boolean' value from column with given 'name'.- Parameters:
name- the fieldname.trueValue- the value that signifiestrue; case-sensitive.- Returns:
- boolean containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined, or if the suppliedtrueValueisnull.
-
readChar
char readChar(int index) Read the 'char' value at index 'index'.- Parameters:
index- the field index.- Returns:
- char containing the value from the specified
index. - Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readChar
Read the 'char' value from column with given 'name'.- Parameters:
name- the fieldname.- Returns:
- char containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readByte
byte readByte(int index) Read the 'byte' value at index 'index'.- Parameters:
index- the field index.- Returns:
- byte containing the value from the specified
index. - Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readByte
Read the 'byte' value from column with given 'name'.- Parameters:
name- the fieldname.- Returns:
- byte containing the value from the specified
name.
-
readShort
short readShort(int index) Read the 'short' value at index 'index'.- Parameters:
index- the fieldindex.- Returns:
- short containing the value from the specified index.
- Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readShort
Read the 'short' value from column with given 'name'.- Parameters:
name- the fieldname.- Returns:
- short containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readInt
int readInt(int index) Read the 'int' value at index 'index'.- Parameters:
index- the field index.- Returns:
- int containing the value from the specified index.
- Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readInt
Read the 'int' value from column with given 'name'.- Parameters:
name- the fieldname.- Returns:
- int containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readInt
int readInt(int index, int defaultValue) Read the 'int' value at index 'index', using the supplieddefaultValueif the field value is blank.- 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.
- Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readInt
Read the 'int' value from column with given 'name', using the supplieddefaultValueif the field value is blank.- Parameters:
name- the fieldname.defaultValue- the value to use if the field value is blank.- Returns:
- int containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readLong
long readLong(int index) Read the 'long' value at index 'index'.- Parameters:
index- the field index.- Returns:
- long containing the value from the specified index.
- Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readLong
Read the 'long' value from column with given 'name'.- Parameters:
name- the fieldname.- Returns:
- long containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readLong
long readLong(int index, long defaultValue) Read the 'long' value at index 'index', using the supplieddefaultValueif the field value is blank.- 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.
- Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readLong
Read the 'long' value from column with given 'name', using the supplieddefaultValueif the field value is blank.- Parameters:
name- the fieldname.defaultValue- the value to use if the field value is blank.- Returns:
- long containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readFloat
float readFloat(int index) Read the 'float' value at index 'index'.- Parameters:
index- the field index.- Returns:
- float containing the value from the specified index.
- Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readFloat
Read the 'float' value from column with given 'name.- Parameters:
name- the fieldname.- Returns:
- float containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readDouble
double readDouble(int index) Read the 'double' value at index 'index'.- Parameters:
index- the field index.- Returns:
- double containing the value from the specified index.
- Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readDouble
Read the 'double' value from column with given 'name.- Parameters:
name- the fieldname.- Returns:
- double containing the value from the specified
name. - Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readBigDecimal
Read theBigDecimalvalue at index 'index'.- Parameters:
index- the field index.- Returns:
BigDecimalcontaining the value from the specified index.- Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readBigDecimal
Read theBigDecimalvalue from column with given 'name.- Parameters:
name- the fieldname.- Returns:
BigDecimalcontaining the value from the specifiedname.- Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readBigDecimal
Read theBigDecimalvalue at index 'index', returning the supplieddefaultValueif the trimmed string value at index 'index' is blank.- Parameters:
index- the field index.defaultValue- the value to use if the field value is blank.- Returns:
BigDecimalcontaining the value from the specified index.- Throws:
IndexOutOfBoundsException- if the index is out of bounds.
-
readBigDecimal
Read theBigDecimalvalue from column with given 'name, returning the supplieddefaultValueif the trimmed string value at index 'index' is blank.- Parameters:
name- the fieldname.defaultValue- the default value to use if the field is blank- Returns:
BigDecimalcontaining the value from the specifiedname.- Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readDate
Read thejava.util.Datevalue in default format at designated columnindex.- Parameters:
index- the field index.- Returns:
Datecontaining the value from the specified index.- Throws:
IndexOutOfBoundsException- if the index is out of bounds.IllegalArgumentException- if the value is not parseableNullPointerException- if the value is empty
-
readDate
Read thejava.sql.Datevalue in given format from column with givenname.- Parameters:
name- the fieldname.- Returns:
Datecontaining the value from the specifiedname.- Throws:
IllegalArgumentException- if a column with givennameis not defined or if the value is not parseableNullPointerException- if the value is empty
-
readDate
Read thejava.util.Datevalue in default format at designated columnindex.- Parameters:
index- the field index.defaultValue- the default value to use if the field is blank- Returns:
Datecontaining the value from the specified index.- Throws:
IndexOutOfBoundsException- if the index is out of bounds.IllegalArgumentException- if the value is not parseableNullPointerException- if the value is empty
-
readDate
Read thejava.sql.Datevalue in given format from column with givenname.- Parameters:
name- the fieldname.defaultValue- the default value to use if the field is blank- Returns:
Datecontaining the value from the specifiedname.- Throws:
IllegalArgumentException- if a column with givennameis not defined.
-
readDate
Read thejava.util.Datevalue in default format at designated columnindex.- Parameters:
index- the field index.pattern- the pattern describing the date and time format- Returns:
Datecontaining the value from the specified index.- Throws:
IndexOutOfBoundsException- if the index is out of bounds.IllegalArgumentException- if the date cannot be parsed.
-
readDate
Read thejava.sql.Datevalue in given format from column with givenname.- Parameters:
name- the fieldname.pattern- the pattern describing the date and time format- Returns:
Datecontaining the value from the specifiedname.- Throws:
IllegalArgumentException- if a column with givennameis not defined or if the specified field cannot be parsed
-
readDate
Read thejava.util.Datevalue in default format at designated columnindex.- Parameters:
index- the field index.pattern- the pattern describing the date and time formatdefaultValue- the default value to use if the field is blank- Returns:
Datecontaining the value from the specified index.- Throws:
IndexOutOfBoundsException- if the index is out of bounds.IllegalArgumentException- if the date cannot be parsed.
-
readDate
Read thejava.sql.Datevalue in given format from column with givenname.- Parameters:
name- the fieldname.pattern- the pattern describing the date and time formatdefaultValue- the default value to use if the field is blank- Returns:
Datecontaining the value from the specifiedname.- Throws:
IllegalArgumentException- if a column with givennameis not defined or if the specified field cannot be parsed
-
getFieldCount
int getFieldCount()Return the number of fields in this 'FieldSet'.- Returns:
- int containing the number of fields in this field set.
-
getProperties
Properties getProperties()Construct name-value pairs from the field names and string values. Null values are omitted.- Returns:
- some properties representing the field set.
- Throws:
IllegalStateException- if the field name meta data is not available.
-