|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jmatchparser.util.csv.fieldreader.FieldReader<K,V>
K
- The type of the fieldsV
- The type of the parsed valuespublic class FieldReader<K,V>
A parser that can be used to parse different CSV files into the same set of
records. It is useful for building parsers that need a fixed range of
information, but the files that contain them can have a multitude of
different formats; often the parser that consumes the records of this field
reader (who supplies FieldDefinition
s) is in a different library or
component than the creator of this field reader (who supplies
FieldSource
s).
Each record is formatted by this field reader into a Map
that maps
fields (usually either String
s or an Enum
that implements
FieldEnum
, see EnumFieldReader
) to values (sometimes strings,
but often other objects as well).
By convention, keys that are mapped to null
are expected to be
cleared by the parser (when updating anything), and records that are not
present are expected not to be touched. Therefore, parsers that use this
reader should use the Map.containsKey(Object)
method to determine if
a key is present, instead of checking the value of Map.get(Object)
for null
. Alternatively, the setEmptyFieldValue(Object)
method can be used to set the "empty" (clear) value to something else.
Constructor Summary | |
---|---|
FieldReader(Map<K,FieldDefinition<? extends V>> fieldDefinitions,
AbstractCSVReader reader)
Create a new field reader. |
Method Summary | |
---|---|
void |
close()
Close this field reader. |
void |
computeFieldSourcesFromIndex(FieldSource.EmptyAction emptyAction,
K[] fields)
Compute the field sources automatically from the index of the key inside the given array. |
void |
computeFieldSourcesFromName(FieldSource.EmptyAction emptyAction)
Compute the field sources automatically from the names (see Object.toString() ) of all fields
To be used when header parsing is enabled. |
void |
computeFieldSourcesFromName(FieldSource.EmptyAction emptyAction,
Collection<K> fields)
Compute the field sources automatically from the names (see Object.toString() ) of the given fields
To be used when header parsing is enabled. |
Map<K,V> |
postprocessNewRecord(Map<K,V> record)
Verify and postprocess a new record (i. e. one that does not already exist in the underlying database and has to be created instead of updated. |
Map<K,V> |
read()
Read a record from this field reader. |
void |
readHeader(boolean ignore)
Read a header line from the CSV reader, and optionally use it for column assignment. |
void |
setEmptyFieldValue(V emptyFieldValue)
Set the value that should be used for records that should be updated, but to an empty value (by default null ). |
void |
setFieldSources(Map<K,FieldSource> fieldSources)
Set the FieldSource s to be used for this field reader. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FieldReader(Map<K,FieldDefinition<? extends V>> fieldDefinitions, AbstractCSVReader reader)
fieldDefinitions
- Field definitions to usereader
- Reader to read the records fromMethod Detail |
---|
public void setFieldSources(Map<K,FieldSource> fieldSources)
FieldSource
s to be used for this field reader.
public void computeFieldSourcesFromIndex(FieldSource.EmptyAction emptyAction, K[] fields)
emptyAction
- FieldSource.EmptyAction
to usefields
- Fields in the desired orderpublic void computeFieldSourcesFromName(FieldSource.EmptyAction emptyAction)
Object.toString()
) of all fields
To be used when header parsing is enabled.
emptyAction
- FieldSource.EmptyAction
to usepublic void computeFieldSourcesFromName(FieldSource.EmptyAction emptyAction, Collection<K> fields)
Object.toString()
) of the given fields
To be used when header parsing is enabled.
emptyAction
- FieldSource.EmptyAction
to usefields
- Fields to usepublic void readHeader(boolean ignore) throws IOException
ignore
- Whether to ignore the read header (not use it for column
assignment)
IOException
public void setEmptyFieldValue(V emptyFieldValue)
null
).
emptyFieldValue
- new value for empty fieldspublic Map<K,V> read() throws IOException, FieldReaderException
IOException
FieldReaderException
public Map<K,V> postprocessNewRecord(Map<K,V> record) throws FieldReaderException
record
- Record that has been read by this field reader before
FieldReaderException
- if mandatory fields are missingpublic void close() throws IOException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |