Package csv.impl

Class AbstractTableReader

java.lang.Object
csv.impl.AbstractTableReader
All Implemented Interfaces:
TableReader, Iterable<Object[]>, Iterator<Object[]>
Direct Known Subclasses:
AbstractStreamTableReader, JdbcReader, JTableReader

public abstract class AbstractTableReader extends Object implements TableReader
Abstract implementation that shall be suitable for most implementations.
Author:
ralph
  • Constructor Details

    • AbstractTableReader

      public AbstractTableReader()
      Default Constructor.
  • Method Details

    • getMapper

      public StreamMapper getMapper()
      Returns the mapper.
      Returns:
      the mapper
    • setMapper

      public void setMapper(StreamMapper mapper)
      Sets the mapper.
      Parameters:
      mapper - the mapper to set
    • open

      public void open()
      Opens the CSV reader.
      Specified by:
      open in interface TableReader
    • reset

      public void reset()
      Resets the CSV reader and its underlying stream.
      Specified by:
      reset in interface TableReader
    • getHeaderRow

      public Object[] getHeaderRow()
      Returns the header row.
      Specified by:
      getHeaderRow in interface TableReader
      Returns:
      header row if such was defined.
    • readHeaderRow

      protected void readHeaderRow()
      Reads the header row if required. This is an empty method. Subclasses must override to correctly read the header row.
    • setHeaderRow

      protected void setHeaderRow(String[] names)
      Sets the header rows.
      Parameters:
      names - names to be set
    • setHeaderRowRead

      protected void setHeaderRowRead(boolean headerRowRead)
      Parameters:
      headerRowRead - the headerRowRead to set
    • get

      public Object get(String name, Object[] row)
      Returns the value in column with specified name. Returns null if row has no such column.
      Parameters:
      name - name of column (from header row)
      row - row of values
      Returns:
      value in row for specified column.
    • getColumnIndex

      public int getColumnIndex(String name)
      Returns the column index of given column name. The first column with given name will be returned.
      Specified by:
      getColumnIndex in interface TableReader
      Parameters:
      name - name of column
      Returns:
      index of column or -1 if it does not exist.
    • setColumnType

      public void setColumnType(int columnIndex, Class<?> type)
      Explicitely set the type of a column. This information will be used to convert the value of this column.
      Parameters:
      columnIndex - index of column
      type - type of column
      See Also:
    • getColumnType

      public Class<?> getColumnType(int columnIndex)
      Returns the type of a column. This information will be used to convert the value of this column.
      Parameters:
      columnIndex - index of column.
      Returns:
      type of values in column
      See Also:
    • hasHeaderRow

      public boolean hasHeaderRow()
      Tells whether the underlying stream has a header row or not
      Specified by:
      hasHeaderRow in interface TableReader
      Returns:
      true if there is a header row.
    • setHasHeaderRow

      public void setHasHeaderRow(boolean hasHeaderRow)
      Tells the reader whether the underlying stream will treat first row as header row.
      Specified by:
      setHasHeaderRow in interface TableReader
      Parameters:
      hasHeaderRow - true if there is a header row.
    • registerCommentCallBack

      public void registerCommentCallBack(CommentCallback callback)
      Adds a comment callback.
      Specified by:
      registerCommentCallBack in interface TableReader
      Parameters:
      callback - the callback
    • unregisterCommentCallBack

      public void unregisterCommentCallBack(CommentCallback callback)
      Removes a comment callback.
      Specified by:
      unregisterCommentCallBack in interface TableReader
      Parameters:
      callback - the callback
    • iterator

      public Iterator<Object[]> iterator()
      Specified by:
      iterator in interface Iterable<Object[]>
    • notifyComment

      protected void notifyComment(String s, int row, int cell)
      Notifies all comment callbacks about a comment.
      Parameters:
      s - the comment to notify about
      row - row number
      cell - cell number in row
    • convert

      protected Object convert(int columnIndex, Object value)
      Converts the string back to correct object. This method will retrieve the column type from getColumnType(int) and then then forward the transformation to mapper object.
      Parameters:
      columnIndex - index of column of this value
      value - string representation of object
      Returns:
      object the converted object
      See Also:
    • convert

      protected Object convert(Class<?> type, Object value)
      Converts the string back to correct object. This method will forward the transformation to mapper object.
      Parameters:
      type - the target type of the return value
      value - stream representation of object
      Returns:
      object the converted object
    • incrementLineCount

      protected int incrementLineCount()
      Increases the line count. Line count reflects the lines in an input file.
      Returns:
      lines read so far
    • getLineCount

      public int getLineCount()
      Line count reflects the lines in an input file.
      Returns:
      lines read so far
    • incrementRowCount

      protected int incrementRowCount()
      Increments the row Count. Row count is the number of netto rows (<= line count) meaning rows delivered by Iterator.next().
      Returns:
      rows delivered so far
    • getRowCount

      public int getRowCount()
      Returns the row count. Row count is the number of netto rows (<= line count) meaning rows delivered by Iterator.next().
      Returns:
      rows delivered so far
    • close

      public void close()
      Does nothing
      Specified by:
      close in interface TableReader
      See Also:
    • setMinimumColumnCount

      public void setMinimumColumnCount(int length)
      Description copied from interface: TableReader
      Sets the minimum number of columns to be returned by Iterator.next().
      Specified by:
      setMinimumColumnCount in interface TableReader
      Parameters:
      length - number of columns
      See Also:
    • getMinimumColumnCount

      public int getMinimumColumnCount()
      Description copied from interface: TableReader
      Returns the minimum number of columns to be returned by Iterator.next().
      Specified by:
      getMinimumColumnCount in interface TableReader
      Returns:
      the minimumLineCount
    • convertArray

      protected Object[] convertArray(List<String> columns)
      Returns an array from the columns. This function exists for convinience to take care of minimum column count.
      Parameters:
      columns - columns to return
      Returns:
      arrray with column values
    • convertArray

      protected Object[] convertArray(String[] columns)
      Returns an array from the columns. This function exists for convinience to take care of minimum column count.
      Parameters:
      columns - columns to return
      Returns:
      arrray with column values
    • isHeaderRowRead

      public boolean isHeaderRowRead()
      Returns:
      the headerRowRead