Package csv.impl
Class AbstractRowFilter
java.lang.Object
csv.impl.AbstractRowFilter
- All Implemented Interfaces:
TableReader,Iterable<Object[]>,Iterator<Object[]>
- Direct Known Subclasses:
IndexRowFilter
Filters rows from underlying table reader.
This is an abstract implementation only that eases filtering.
- Author:
- ralph
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the reader.protected voidRead from underlying reader until there is a row not filtered away.Forwarded to underlying reader.intgetColumnIndex(String name) Returns the column index of given column name.Object[]Returns the header row.intReturns the minimum number of columns to be returned byIterator.next().protected intReturns the row index from the underlying reader (raw row index)protected TableReaderReturns the underlying reader.protected intReturns the index of current row (delivered rows only)booleanTells whether the underlying stream has a header row or notbooleanhasNext()protected booleanTells whether more rows will be expected after current row.protected abstract booleanisValidRow(Object[] row) Tells whether the row can be delivered or will be filtered away.iterator()Object[]next()voidopen()Opens the reader or resets it.voidregisterCommentCallBack(CommentCallback callback) Registers a comment callback.voidremove()voidreset()Resets the reader.voidsetHasHeaderRow(boolean hasHeaderRow) Tells the reader whether the underlying stream will treat first row as header row.voidsetMinimumColumnCount(int length) Sets the minimum number of columns to be returned byIterator.next().voidunregisterCommentCallBack(CommentCallback callback) Unregisters a comment callback.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
AbstractRowFilter
Constructor.- Parameters:
reader- the reader this filter shall process
-
-
Method Details
-
getReader
Returns the underlying reader.- Returns:
- the reader
-
close
public void close()Closes the reader.- Specified by:
closein interfaceTableReader
-
get
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:
-
getColumnIndex
Returns the column index of given column name. The first column with given name will be returned.- Specified by:
getColumnIndexin interfaceTableReader- Parameters:
name- name of column- Returns:
- index of column or -1 if it does not exist.
-
getHeaderRow
Returns the header row. Please note that header rows are never delivered throughIterator.next().- Specified by:
getHeaderRowin interfaceTableReader- Returns:
- header row if such was defined.
-
getMinimumColumnCount
public int getMinimumColumnCount()Returns the minimum number of columns to be returned byIterator.next().- Specified by:
getMinimumColumnCountin interfaceTableReader- Returns:
- length number of columns
-
hasHeaderRow
public boolean hasHeaderRow()Tells whether the underlying stream has a header row or not- Specified by:
hasHeaderRowin interfaceTableReader- Returns:
- true if there is a header row.
-
open
public void open()Opens the reader or resets it.- Specified by:
openin interfaceTableReader
-
iterator
-
registerCommentCallBack
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:
registerCommentCallBackin interfaceTableReader- Parameters:
callback- callback to be registered
-
reset
public void reset()Resets the reader.- Specified by:
resetin interfaceTableReader
-
setHasHeaderRow
public void setHasHeaderRow(boolean hasHeaderRow) Tells the reader whether the underlying stream will treat first row as header row.- Specified by:
setHasHeaderRowin interfaceTableReader- Parameters:
hasHeaderRow- true if there is a header row.
-
setMinimumColumnCount
public void setMinimumColumnCount(int length) Sets the minimum number of columns to be returned byIterator.next().- Specified by:
setMinimumColumnCountin interfaceTableReader- Parameters:
length- number of columns
-
unregisterCommentCallBack
Unregisters a comment callback. Note that not all implementations actually support comments.- Specified by:
unregisterCommentCallBackin interfaceTableReader- Parameters:
callback- callback to be unregistered
-
hasNext
public boolean hasNext() -
findNextRow
protected void findNextRow()Read from underlying reader until there is a row not filtered away. -
isValidRow
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:
-
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
-
remove
public void remove()
-