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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface java.util.Iterator

    forEachRemaining, remove
  • Field Details

  • Constructor Details

    • ObjectReader

      public ObjectReader​(TableReader reader, RowConverter<T> converter, boolean hasHeaderRow)
      Constructor.
      Parameters:
      reader - the underlying table reader
      converter - the converter to be used
      hasHeaderRow - 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

      public RowConverter<T> getConverter()
      Returns the row converter.
      Returns:
      the row converter
    • setConverter

      public void setConverter​(RowConverter<T> converter)
      Sets the row converter.
      Parameters:
      converter - the row converter to be used
    • iterator

      public java.util.Iterator<T> iterator()
      Specified by:
      iterator in interface java.lang.Iterable<T>
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface java.util.Iterator<T>
    • next

      public T next()
      Specified by:
      next in interface java.util.Iterator<T>
    • close

      public void close()
      Closes the stream.