Package csv.impl

Class AbstractRowFilter

java.lang.Object
csv.impl.AbstractRowFilter
All Implemented Interfaces:
TableReader, java.lang.Iterable<java.lang.Object[]>, java.util.Iterator<java.lang.Object[]>
Direct Known Subclasses:
IndexRowFilter

public abstract class AbstractRowFilter
extends java.lang.Object
implements TableReader
Filters rows from underlying table reader. This is an abstract implementation only that eases filtering.
Author:
ralph
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractRowFilter​(TableReader reader)
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    void close()
    Closes the reader.
    protected void findNextRow()
    Read from underlying reader until there is a row not filtered away.
    java.lang.Object get​(java.lang.String name, java.lang.Object[] row)
    Forwarded to underlying reader.
    int getColumnIndex​(java.lang.String name)
    Returns the column index of given column name.
    java.lang.Object[] getHeaderRow()
    Returns the header row.
    int getMinimumColumnCount()
    Returns the minimum number of columns to be returned by Iterator.next().
    protected int getRawRowIndex()
    Returns the row index from the underlying reader (raw row index)
    protected TableReader getReader()
    Returns the underlying reader.
    protected int getRowIndex()
    Returns the index of current row (delivered rows only)
    boolean hasHeaderRow()
    Tells whether the underlying stream has a header row or not
    boolean hasNext()
    protected boolean isMoreRowsExpected()
    Tells whether more rows will be expected after current row.
    protected abstract boolean isValidRow​(java.lang.Object[] row)
    Tells whether the row can be delivered or will be filtered away.
    java.util.Iterator<java.lang.Object[]> iterator()
    java.lang.Object[] next()
    void open()
    Opens the reader or resets it.
    void registerCommentCallBack​(CommentCallback callback)
    Registers a comment callback.
    void remove()
    void reset()
    Resets the reader.
    void setHasHeaderRow​(boolean hasHeaderRow)
    Tells the reader whether the underlying stream will treat first row as header row.
    void setMinimumColumnCount​(int length)
    Sets the minimum number of columns to be returned by Iterator.next().
    void unregisterCommentCallBack​(CommentCallback callback)
    Unregisters a comment callback.

    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
  • Constructor Details

    • AbstractRowFilter

      public AbstractRowFilter​(TableReader reader)
      Constructor.
      Parameters:
      reader - the reader this filter shall process
  • Method Details

    • getReader

      protected TableReader getReader()
      Returns the underlying reader.
      Returns:
      the reader
    • close

      public void close()
      Closes the reader.
      Specified by:
      close in interface TableReader
    • get

      public java.lang.Object get​(java.lang.String name, java.lang.Object[] row)
      Forwarded to underlying reader.
      Parameters:
      name - name of column (from header row)
      row - row of values
      Returns:
      the value in the respective column
      See Also:
      AbstractTableReader.get(String, Object[])
    • getColumnIndex

      public int getColumnIndex​(java.lang.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.
    • getHeaderRow

      public java.lang.Object[] getHeaderRow()
      Returns the header row. Please note that header rows are never delivered through Iterator.next().
      Specified by:
      getHeaderRow in interface TableReader
      Returns:
      header row if such was defined.
    • getMinimumColumnCount

      public int getMinimumColumnCount()
      Returns the minimum number of columns to be returned by Iterator.next().
      Specified by:
      getMinimumColumnCount in interface TableReader
      Returns:
      length number of columns
    • 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.
    • open

      public void open()
      Opens the reader or resets it.
      Specified by:
      open in interface TableReader
    • iterator

      public java.util.Iterator<java.lang.Object[]> iterator()
      Specified by:
      iterator in interface java.lang.Iterable<java.lang.Object[]>
    • registerCommentCallBack

      public void registerCommentCallBack​(CommentCallback callback)
      Registers a comment callback. The callback will be executed when a comment is detected in input. Note that not all implementations actually support comments.
      Specified by:
      registerCommentCallBack in interface TableReader
      Parameters:
      callback - callback to be registered
    • reset

      public void reset()
      Resets the reader.
      Specified by:
      reset in interface TableReader
    • 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.
    • setMinimumColumnCount

      public void setMinimumColumnCount​(int length)
      Sets the minimum number of columns to be returned by Iterator.next().
      Specified by:
      setMinimumColumnCount in interface TableReader
      Parameters:
      length - number of columns
    • unregisterCommentCallBack

      public void unregisterCommentCallBack​(CommentCallback callback)
      Unregisters a comment callback. Note that not all implementations actually support comments.
      Specified by:
      unregisterCommentCallBack in interface TableReader
      Parameters:
      callback - callback to be unregistered
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface java.util.Iterator<java.lang.Object[]>
    • findNextRow

      protected void findNextRow()
      Read from underlying reader until there is a row not filtered away.
    • isValidRow

      protected abstract boolean isValidRow​(java.lang.Object[] row)
      Tells whether the row can be delivered or will be filtered away.
      Parameters:
      row - row to be checked
      Returns:
      whether row is a valid row
      See Also:
      getRawRowIndex(), getRowIndex()
    • isMoreRowsExpected

      protected boolean isMoreRowsExpected()
      Tells whether more rows will be expected after current row. This method always returns true so all rows from underlying reader will be checked. However, you should override this method if you want to avoid checking more rows because you already know that no row will match your criteria anymore.
      Returns:
      true if another valid row can be expected
    • getRawRowIndex

      protected int getRawRowIndex()
      Returns the row index from the underlying reader (raw row index)
      Returns:
      the rawRowIndex
    • getRowIndex

      protected int getRowIndex()
      Returns the index of current row (delivered rows only)
      Returns:
      the rowIndex
    • next

      public java.lang.Object[] next()
      Specified by:
      next in interface java.util.Iterator<java.lang.Object[]>
    • remove

      public void remove()
      Specified by:
      remove in interface java.util.Iterator<java.lang.Object[]>