Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.

csv.impl
Class AbstractTableReader

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

public abstract class AbstractTableReader
extends java.lang.Object
implements TableReader

Abstract implementation that shall be suitable for most implementations.

Author:
ralph

Constructor Summary
AbstractTableReader()
          Default Constructor.
 
Method Summary
 void addCommentCallBack(CommentCallback callback)
          Deprecated. Use TableReader.registerCommentCallBack(CommentCallback) instead.
 void close()
          Does nothing
protected  java.lang.Object convert(int columnIndex, java.lang.String value)
          Converts the string back to correct object.
protected  java.lang.Object convert(java.lang.String type, java.lang.String value)
          Converts the string back to correct object.
protected  java.lang.Object[] convertArray(java.util.List<java.lang.String> columns)
          Returns an array from the columns.
protected  java.lang.Object[] convertArray(java.lang.String[] columns)
          Returns an array from the columns.
 java.lang.Object get(java.lang.String name, java.lang.Object[] row)
          Returns the value in column with specified name.
 int getColumnIndex(java.lang.String name)
          Returns the column index of given column name.
 java.lang.String getColumnType(int columnIndex)
          Returns the type of a column.
 java.lang.Object[] getHeaderRow()
          Returns the header row.
 int getLineCount()
          Line count reflects the lines in an input file.
 int getMinimumColumnCount()
          Returns the minimum number of columns to be returned by Iterator.next().
 int getRowCount()
          Returns the row count.
protected  TypeConversionHandler getTypeConversionHandler(java.lang.String type)
          Returns a type conversion handler for the given type.
 boolean hasHeaderRow()
          Tells whether the underlying stream has a header row or not
protected  int incrementLineCount()
          Increases the line count.
protected  int incrementRowCount()
          Increments the row Count.
 boolean isHeaderRowRead()
           
protected  void notifyComment(java.lang.String s, int row, int cell)
          Notifies all comment callbacks about a comment.
 void open()
          Opens the CSV reader.
protected  void readHeaderRow()
          Reads the header row if required.
 void registerCommentCallBack(CommentCallback callback)
          Adds a comment callback.
 void registerTypeConversionHandler(TypeConversionHandler handler)
          Registers a type conversion handler.
 void removeCommentCallBack(CommentCallback callback)
          Deprecated. Use TableReader.unregisterCommentCallBack(CommentCallback) instead
 void reset()
          Resets the CSV reader and its underlying stream.
 void setColumnType(int columnIndex, java.lang.Class<?> type)
          Explicitely set the type of a column.
 void setHasHeaderRow(boolean hasHeaderRow)
          Tells the reader whether the underlying stream will treat first row as header row.
protected  void setHeaderRow(java.lang.String[] names)
          Sets the header rows.
protected  void setHeaderRowRead(boolean headerRowRead)
           
 void setMinimumColumnCount(int length)
          Sets the minimum number of columns to be returned by Iterator.next().
 void unregisterCommentCallBack(CommentCallback callback)
          Removes a comment callback.
 void unregisterTypeConversionHandler(TypeConversionHandler handler)
          Unregisters a type conversion handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Iterator
hasNext, next, remove
 

Constructor Detail

AbstractTableReader

public AbstractTableReader()
Default Constructor.

Method Detail

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 java.lang.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(java.lang.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 java.lang.Object get(java.lang.String name,
                            java.lang.Object[] row)
Returns the value in column with specified name. Returns null if row has no such column.

Specified by:
get in interface TableReader
Parameters:
name - name of column (from header row)
row - row of values
Returns:
value in row for specified column.

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.

setColumnType

public void setColumnType(int columnIndex,
                          java.lang.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:
getTypeConversionHandler(String), convert(int, String)

getColumnType

public java.lang.String 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:
getTypeConversionHandler(String), convert(int, String)

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.

addCommentCallBack

public void addCommentCallBack(CommentCallback callback)
Deprecated. Use TableReader.registerCommentCallBack(CommentCallback) instead.

Adds a comment callback.

Parameters:
callback - the callback

registerCommentCallBack

public void registerCommentCallBack(CommentCallback callback)
Adds a comment callback.

Specified by:
registerCommentCallBack in interface TableReader
Parameters:
callback - the callback

removeCommentCallBack

public void removeCommentCallBack(CommentCallback callback)
Deprecated. Use TableReader.unregisterCommentCallBack(CommentCallback) instead

Removes a comment callback.

Parameters:
callback - the callback

unregisterCommentCallBack

public void unregisterCommentCallBack(CommentCallback callback)
Removes a comment callback.

Specified by:
unregisterCommentCallBack in interface TableReader
Parameters:
callback - the callback

notifyComment

protected void notifyComment(java.lang.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

registerTypeConversionHandler

public void registerTypeConversionHandler(TypeConversionHandler handler)
Registers a type conversion handler.

Parameters:
handler - handler to register

unregisterTypeConversionHandler

public void unregisterTypeConversionHandler(TypeConversionHandler handler)
Unregisters a type conversion handler.

Parameters:
handler - handler to unregister

convert

protected java.lang.Object convert(int columnIndex,
                                   java.lang.String 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 convert(String, String).

Parameters:
columnIndex - index of column of this value
value - string representation of object
Returns:
object the converted object
See Also:
convert(String, String), registerTypeConversionHandler(TypeConversionHandler), getColumnType(int)

convert

protected java.lang.Object convert(java.lang.String type,
                                   java.lang.String value)
Converts the string back to correct object.

Parameters:
type - type of object being returned
value - string representation of object
Returns:
object

getTypeConversionHandler

protected TypeConversionHandler getTypeConversionHandler(java.lang.String type)
Returns a type conversion handler for the given type.

Parameters:
type - type to get a handler for
Returns:
conversion handler

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:
TableReader.close()

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:
TableReader.setMinimumColumnCount(int)

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 java.lang.Object[] convertArray(java.util.List<java.lang.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 java.lang.Object[] convertArray(java.lang.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

Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.

Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.