Package csv.impl

Class AbstractColumnFilter

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

public abstract class AbstractColumnFilter
extends java.lang.Object
implements TableReader
Filters columns from underlying table reader. This is an abstract implementation only that eases filtering. Most of the methods are forwared to underlying reader.
Author:
ralph
  • Constructor Summary

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

    Modifier and Type Method Description
    void close()
    Closes the underlying reader.
    protected java.lang.Object[] filter​(java.lang.Object[] row)
    Filters columns within a row.
    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.
    protected abstract int getFilteredIndex​(int originalIndex)
    Returns the index in filtered row of the specified original column index.
    java.lang.Object[] getHeaderRow()
    Returns the header row.
    int getMinimumColumnCount()
    Returns the minimum number of columns to be returned by Iterator.next().
    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()
    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

  • Method Details

    • getReader

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

      public void close()
      Closes the underlying reader.
      Specified by:
      close in interface TableReader
      See Also:
      TableReader.close()
    • 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[]>
    • 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[]>
    • filter

      protected java.lang.Object[] filter​(java.lang.Object[] row)
      Filters columns within a row. Do not override here but override getFilteredIndex(int) instead.
      Parameters:
      row - row to be filtered
      Returns:
      row with filtered column sonly
      See Also:
      getFilteredIndex(int)
    • getFilteredIndex

      protected abstract int getFilteredIndex​(int originalIndex)
      Returns the index in filtered row of the specified original column index.
      Parameters:
      originalIndex - index of value in row from underlying reader
      Returns:
      index of value in filtered row or -1 if column will not be visible.
    • remove

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