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
Abstract implementation that shall be suitable for most implementations.
- Author:
- ralph
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Does nothingprotected ObjectConverts the string back to correct object.protected ObjectConverts the string back to correct object.protected Object[]convertArray(String[] columns) Returns an array from the columns.protected Object[]convertArray(List<String> columns) Returns an array from the columns.Returns the value in column with specified name.intgetColumnIndex(String name) Returns the column index of given column name.Class<?> getColumnType(int columnIndex) Returns the type of a column.Object[]Returns the header row.intLine count reflects the lines in an input file.Returns the mapper.intReturns the minimum number of columns to be returned byIterator.next().intReturns the row count.booleanTells whether the underlying stream has a header row or notprotected intIncreases the line count.protected intIncrements the row Count.booleaniterator()protected voidnotifyComment(String s, int row, int cell) Notifies all comment callbacks about a comment.voidopen()Opens the CSV reader.protected voidReads the header row if required.voidregisterCommentCallBack(CommentCallback callback) Adds a comment callback.voidreset()Resets the CSV reader and its underlying stream.voidsetColumnType(int columnIndex, Class<?> type) Explicitely set the type of a column.voidsetHasHeaderRow(boolean hasHeaderRow) Tells the reader whether the underlying stream will treat first row as header row.protected voidsetHeaderRow(String[] names) Sets the header rows.protected voidsetHeaderRowRead(boolean headerRowRead) voidsetMapper(StreamMapper mapper) Sets the mapper.voidsetMinimumColumnCount(int length) Sets the minimum number of columns to be returned byIterator.next().voidunregisterCommentCallBack(CommentCallback callback) Removes 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, hasNext, next, remove
-
Constructor Details
-
AbstractTableReader
public AbstractTableReader()Default Constructor.
-
-
Method Details
-
getMapper
Returns the mapper.- Returns:
- the mapper
-
setMapper
Sets the mapper.- Parameters:
mapper- the mapper to set
-
open
public void open()Opens the CSV reader.- Specified by:
openin interfaceTableReader
-
reset
public void reset()Resets the CSV reader and its underlying stream.- Specified by:
resetin interfaceTableReader
-
getHeaderRow
Returns the header row.- Specified by:
getHeaderRowin interfaceTableReader- 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
Sets the header rows.- Parameters:
names- names to be set
-
setHeaderRowRead
protected void setHeaderRowRead(boolean headerRowRead) - Parameters:
headerRowRead- the headerRowRead to set
-
get
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
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.
-
setColumnType
Explicitely set the type of a column. This information will be used to convert the value of this column.- Parameters:
columnIndex- index of columntype- type of column- See Also:
-
getColumnType
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:
hasHeaderRowin interfaceTableReader- 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:
setHasHeaderRowin interfaceTableReader- Parameters:
hasHeaderRow- true if there is a header row.
-
registerCommentCallBack
Adds a comment callback.- Specified by:
registerCommentCallBackin interfaceTableReader- Parameters:
callback- the callback
-
unregisterCommentCallBack
Removes a comment callback.- Specified by:
unregisterCommentCallBackin interfaceTableReader- Parameters:
callback- the callback
-
iterator
-
notifyComment
Notifies all comment callbacks about a comment.- Parameters:
s- the comment to notify aboutrow- row numbercell- cell number in row
-
convert
Converts the string back to correct object. This method will retrieve the column type fromgetColumnType(int)and then then forward the transformation tomapperobject.- Parameters:
columnIndex- index of column of this valuevalue- string representation of object- Returns:
- object the converted object
- See Also:
-
convert
Converts the string back to correct object. This method will forward the transformation tomapperobject.- Parameters:
type- the target type of the return valuevalue- 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 byIterator.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 byIterator.next().- Returns:
- rows delivered so far
-
close
public void close()Does nothing- Specified by:
closein interfaceTableReader- See Also:
-
setMinimumColumnCount
public void setMinimumColumnCount(int length) Description copied from interface:TableReaderSets the minimum number of columns to be returned byIterator.next().- Specified by:
setMinimumColumnCountin interfaceTableReader- Parameters:
length- number of columns- See Also:
-
getMinimumColumnCount
public int getMinimumColumnCount()Description copied from interface:TableReaderReturns the minimum number of columns to be returned byIterator.next().- Specified by:
getMinimumColumnCountin interfaceTableReader- Returns:
- the minimumLineCount
-
convertArray
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
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
-