com.oakgrovesystems.util
Class CSV

java.lang.Object
  |
  +--com.oakgrovesystems.util.CSV

public class CSV
extends java.lang.Object

This class represents the Comma Separated Value (CSV) object. This class provides methods to access the CSV data as well as methods to modify the data viz., addRow and removeRow methods.

Version:
1.0
Author:
Chandrasekar Ramamurthy

Field Summary
static int HEADER
          The Row number of the header row (if header is applicable)
 
Constructor Summary
CSV()
           
 
Method Summary
 void addRow(java.util.ArrayList rowToken)
          This method adds a row, at the end of the existing matrix, to the CSV object
 java.util.ArrayList getColumn(int columnNumber)
          This method returns the column from the CSV matrix
 java.util.ArrayList[] getCSVData()
          This method returns the complete CSV matrix
 java.util.ArrayList getHeader()
          This method returns the first row of the CSV matrix
 java.util.ArrayList getRow(int rowNumber)
          This method returns the specified row of the CSV matrix
 int getTotalRows()
          This method returns the total number of rows in the CSV object
static com.oakgrovesystems.util.CSV parse(java.io.Reader reader)
          This method is the final parsing bolck for parsing CSV values
 void removeRow(int rowNumber)
          This method removes a row, if it exists, from the CSV object
 void setCSVData(java.util.ArrayList[] finalTokens)
          This method sets the data for this object.
 java.lang.String toString()
          This method overrides the default toString() method to return the CSV matrix as CSV text
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HEADER

public static final int HEADER
The Row number of the header row (if header is applicable)

See Also:
Constant Field Values
Constructor Detail

CSV

public CSV()
Method Detail

setCSVData

public void setCSVData(java.util.ArrayList[] finalTokens)
This method sets the data for this object. This clears any pre-existing data and fills up with the supplied data. The values are supplied as an array of ArrayList for 2 reasons. 1. Handling particular object types like String will make the process costlier and induce unnecessary overheads. 2. Every row can have number of elements different from the other. By making this flexible by using ArrayList, the accessing routines have the flexibility and can also avoid costlier overheads.

Parameters:
finalTokens - This is an array of ArrayList values. Each ArrayList contains the values for each row.

addRow

public void addRow(java.util.ArrayList rowToken)
This method adds a row, at the end of the existing matrix, to the CSV object

Parameters:
rowToken - The ArrayList containing the row values

removeRow

public void removeRow(int rowNumber)
This method removes a row, if it exists, from the CSV object

Parameters:
rowNumber - The row number of the row to be removed

getTotalRows

public int getTotalRows()
This method returns the total number of rows in the CSV object

Returns:
The total number of rows in the CSV object

getHeader

public java.util.ArrayList getHeader()
This method returns the first row of the CSV matrix

Returns:
An ArrayList containing the first row of the CSV matrix

getRow

public java.util.ArrayList getRow(int rowNumber)
This method returns the specified row of the CSV matrix

Parameters:
rowNumber - The row number of the CSV matrix
Returns:
An ArrayList containing the specified row of the CSV matrix

getCSVData

public java.util.ArrayList[] getCSVData()
This method returns the complete CSV matrix

Returns:
An array of ArrayList containing al the rows of the CSV matrix

getColumn

public java.util.ArrayList getColumn(int columnNumber)
This method returns the column from the CSV matrix

Parameters:
columnNumber - The column number of the CSV matrix
Returns:
An ArrayList containing the specifed column of the CSV matrix

toString

public java.lang.String toString()
This method overrides the default toString() method to return the CSV matrix as CSV text

Overrides:
toString in class java.lang.Object
Returns:
A CommaSeparatedValue text

parse

public static com.oakgrovesystems.util.CSV parse(java.io.Reader reader)
                                          throws java.io.IOException
This method is the final parsing bolck for parsing CSV values

Parameters:
reader - This method reads the CSV values from a Reader object
Returns:
A CSV object containing the parsed CSV matrix
java.io.IOException


Copyright (c) 1999-2004 Oak Grove Systems. All Rights Reserved.