Package csv.util
Class ObjectReader<T>
java.lang.Object
csv.util.ObjectReader<T>
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Iterator<T>
public class ObjectReader<T>
extends java.lang.Object
implements java.util.Iterator<T>, java.lang.Iterable<T>
Reads objects from a table.
This class is different to BeanReader
as it asks a converter to convert the row.
// Create an instance of your table reader TableReader tableReader = ...; // Get an instance of your row converter RowConverter<MyClass> converter = new MyClassConverter(); // Now read from the table stream ObjectReader<MyClass> reader = new ObjectReader(tableReader, converter, true); Object tableHeader[] = reader.getTableHeader(); while (reader.hasNext()) { MyClass myObject = reader.next(); // do something... } // Close the reader reader.close();
- Author:
- ralph
-
Field Summary
Fields Modifier and Type Field Description protected RowConverter<T>
converter
protected java.util.Iterator<java.lang.Object[]>
iterator
protected TableReader
reader
protected java.lang.Object[]
tableHeader
-
Constructor Summary
Constructors Constructor Description ObjectReader(TableReader reader, RowConverter<T> converter, boolean hasHeaderRow)
Constructor. -
Method Summary
Modifier and Type Method Description void
close()
Closes the stream.RowConverter<T>
getConverter()
Returns the row converter.java.lang.Object[]
getTableHeader()
Returns the header row that was read.boolean
hasNext()
java.util.Iterator<T>
iterator()
T
next()
void
setConverter(RowConverter<T> converter)
Sets the row converter.
-
Field Details
-
reader
-
iterator
protected java.util.Iterator<java.lang.Object[]> iterator -
converter
-
tableHeader
protected java.lang.Object[] tableHeader
-
-
Constructor Details
-
ObjectReader
Constructor.- Parameters:
reader
- the underlying table readerconverter
- the converter to be usedhasHeaderRow
- whether the table has a table header to read
-
-
Method Details
-
getTableHeader
public java.lang.Object[] getTableHeader()Returns the header row that was read.- Returns:
- the header row or null if no such row was read.
-
getConverter
Returns the row converter.- Returns:
- the row converter
-
setConverter
Sets the row converter.- Parameters:
converter
- the row converter to be used
-
iterator
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
hasNext
public boolean hasNext()- Specified by:
hasNext
in interfacejava.util.Iterator<T>
-
next
- Specified by:
next
in interfacejava.util.Iterator<T>
-
close
public void close()Closes the stream.
-