olg.csv.base
Class AbstractSheetReader

Package class diagram package AbstractSheetReader
java.lang.Object
  extended by olg.csv.base.AbstractSheetReader
All Implemented Interfaces:
Closeable, Iterator<Row>, IReader
Direct Known Subclasses:
ODSReader

public abstract class AbstractSheetReader
extends Object
implements IReader

Abstract class which embeds sheet reader characteristics.


Field Summary
protected  Integer beginAtColumn
          First cell to read in each row.
protected  Integer beginAtRow
          First row to read.
protected  Integer endAtColumn
          Last cell to read in each row.
protected  Integer endAtRow
          last row to read.
protected  int recordIndex
          Record index. first is 1.
protected  int rowSize
          Record size.
protected  String sheetName
          Sheet name.
protected  int sheetNum
          the sheet num. 0 is the first.
protected  boolean skipEmptyCell
          Indicate if emtpy cells are skipping.
protected  boolean withHeaders
          Indicate if an header row must be skipped.
 
Constructor Summary
AbstractSheetReader(AbstractSheetSettings<? extends AbstractSheetSettings<?>> settings)
           
 
Method Summary
private  void checkParameters(Integer beginAtRow, Integer endAtRow, String beginAtColumn, String endAtColumn)
          Check and set parameters.
abstract  void close()
          
protected abstract  int defineRowSize()
          Returns the expected rows length of each line.
protected abstract  void doOnInitSheet()
          Method called by initSheet() to allow concret SheetReader to do some stuff on its instanciation.
protected abstract  int getRows()
          Get the row count of this sheet.
 String getSheetName()
          Returns sheet name corresponding to the sheet this reader has opened.
 int getSheetNum()
          Returns the index of the current sheet this reader has opened.
 boolean hasNext()
          
protected  void initSheet()
          Method to call by concret constructor to initialize some stuff.
 boolean isWithHeaders()
          Indicates if the file has a headers line.
 Row next()
          
protected  List<Cell> padding(List<Cell> cells, int columnBegin, int columnEnd)
          Complete cell lists in parameter with empty cells.
 void remove()
          Unsupported Operation.
protected abstract  Row setNext()
          Returns the next Row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

skipEmptyCell

protected boolean skipEmptyCell
Indicate if emtpy cells are skipping.


sheetNum

protected int sheetNum
the sheet num. 0 is the first.


recordIndex

protected int recordIndex
Record index. first is 1.


rowSize

protected int rowSize
Record size.


sheetName

protected String sheetName
Sheet name.


withHeaders

protected boolean withHeaders
Indicate if an header row must be skipped.


beginAtRow

protected Integer beginAtRow
First row to read.


endAtRow

protected Integer endAtRow
last row to read.


beginAtColumn

protected Integer beginAtColumn
First cell to read in each row.


endAtColumn

protected Integer endAtColumn
Last cell to read in each row.

Constructor Detail

AbstractSheetReader

public AbstractSheetReader(AbstractSheetSettings<? extends AbstractSheetSettings<?>> settings)
Parameters:
settings - the reader settings. Must not be null.
Method Detail

hasNext

public final boolean hasNext()

Specified by:
hasNext in interface Iterator<Row>

next

public final Row next()

Specified by:
next in interface Iterator<Row>

remove

public final void remove()
Unsupported Operation. Throw UnsupportedOperationException

Specified by:
remove in interface Iterator<Row>

isWithHeaders

public boolean isWithHeaders()
Indicates if the file has a headers line.

Specified by:
isWithHeaders in interface IReader
Returns:
true if the file has a headers line.

close

public abstract void close()

Specified by:
close in interface Closeable

setNext

protected abstract Row setNext()
Returns the next Row.

Returns:
the next row.

doOnInitSheet

protected abstract void doOnInitSheet()
                               throws IOException
Method called by initSheet() to allow concret SheetReader to do some stuff on its instanciation.

Throws:
IOException - if I/O error occurs.

padding

protected List<Cell> padding(List<Cell> cells,
                             int columnBegin,
                             int columnEnd)
Complete cell lists in parameter with empty cells.

Parameters:
cells - list to complete
columnBegin - index colum from which begins the padding (inclusive)
columnEnd - index column to which ends the padding (exclusive).
Returns:
the completed list

getSheetNum

public int getSheetNum()
Returns the index of the current sheet this reader has opened.

Returns:
the index.

getSheetName

public String getSheetName()
Returns sheet name corresponding to the sheet this reader has opened.

Returns:
the sheet name

getRows

protected abstract int getRows()
Get the row count of this sheet.

Returns:
total count of rows

initSheet

protected void initSheet()
                  throws IOException
Method to call by concret constructor to initialize some stuff. By default, skip headers if specified, and define row size. If redefined by concret child class, initSheet must call parent initSheet to guaranty correct initialization

Throws:
IOException - if I/O error occurs during initialization.
See Also:
doOnInitSheet()

defineRowSize

protected abstract int defineRowSize()
Returns the expected rows length of each line.

Returns:
the rows size.

checkParameters

private void checkParameters(Integer beginAtRow,
                             Integer endAtRow,
                             String beginAtColumn,
                             String endAtColumn)
Check and set parameters.

Throws IllegalArgumentException if one of these parameters.

Parameters:
beginAtRow - the row index from which begins the reading. lines number begin at 1
endAtRow - the last index to which ends the reading.
beginAtColumn - the cell num from which begins the row reading. columns begin at 0. Could be in sheet cell format or a number.
endAtColumn - the cell num to which ends the row reading. Could be null.


Copyright © 2014. All Rights Reserved.