com.pushtotest.tool.datasource
Class Xsv

java.lang.Object
  extended by com.pushtotest.tool.datasource.Xsv
All Implemented Interfaces:
Datasource
Direct Known Subclasses:
Csv, Tsv

public abstract class Xsv
extends java.lang.Object
implements Datasource

This is an implementation of a Datasource that allows you to access Comma Separated Values Files.


Field Summary
protected  boolean after
           
protected  boolean before
           
protected  int colcount
           
protected  java.util.List columns
           
protected  int currentrow
           
protected  java.lang.String[][] db
           
protected  boolean first
           
protected  boolean firstRowIsColumns
           
protected  boolean last
           
protected  java.lang.String lineTerminator
           
protected  int rowcount
           
 
Constructor Summary
Xsv()
          Default no-op constructor to allow you to override the default setting for things like line endings and column names.
Xsv(java.io.File file)
          Constructs a new 'x'sv Object by passing in a File object that has been instantiated to the file to open.
Xsv(java.lang.String path)
          Constructs a new 'x'sv Object by passing in a path to the file to open.
 
Method Summary
 int columnCount()
          Returns the number of columns in the current row.
 boolean getBoolean(int column)
          Returns the boolean value of the contents at the position of column.
 boolean getBoolean(java.lang.String name)
          Returns the boolean value found in the column of the given name.
 double getDouble(int column)
          Returns the double value of the contents at the position of column.
 double getDouble(java.lang.String name)
          Returns the double value found in the column of the given name.
 double[][] getDoubleData()
          Get the raw data as a matrix of double values.
 boolean getFirstRowIsColumnNames()
          Whether this parser will treat the first row as column names or not.
 float getFloat(int column)
          Returns the float value of the contents at the position of column.
 float getFloat(java.lang.String name)
          Returns the float value found in the column of the given name.
 int getInt(int column)
          Returns the int value of the contents at the position of column.
 int getInt(java.lang.String name)
          Returns the int value found in the column of the given name.
 int[][] getIntData()
          Get the raw data as a matrix of int values.
 java.lang.String getLineTeminator()
          Get the value of the line separator currently being used.
 long getLong(int column)
          Returns the long value of the contents at the position of column.
 long getLong(java.lang.String name)
          Returns the long value found in the column of the given name.
 java.lang.String[][] getRawData()
          Get the raw data of the parsed xSV file.
 java.lang.String getString(int column)
          Returns the string value of the contents at the position of column.
 java.lang.String getString(java.lang.String name)
          Returns the string value found in the column of the given name.
 boolean isAfterLast()
          Tells whether the cursor has moved past the last row or not.
 boolean isBeforeFirst()
          Tells whether the cursor position is before the first line.
 boolean isFirst()
          Tells whether the cursor is on the first row or not.
 boolean isLast()
          Tells whether the cursor is on the last row or not.
 boolean next()
          Moves the cursor to the next line.
 void parse(java.io.File file)
          Parse a source file into its components parts.
 void parse(java.lang.String path)
          Parse a source file into its components parts.
abstract  java.lang.String separator()
          The string that contains the characters that are used as separators.
 void setFirstRowIsColumnNames(boolean isColumns)
          Is the first row a column name?
 void setLineTerminator(java.lang.String lineTerminator)
          Set the value of the line terminator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

before

protected boolean before

first

protected boolean first

last

protected boolean last

after

protected boolean after

firstRowIsColumns

protected boolean firstRowIsColumns

lineTerminator

protected java.lang.String lineTerminator

currentrow

protected int currentrow

rowcount

protected int rowcount

colcount

protected int colcount

columns

protected java.util.List columns

db

protected java.lang.String[][] db
Constructor Detail

Xsv

public Xsv()
Default no-op constructor to allow you to override the default setting for things like line endings and column names.

See Also:
To parse a file into the component parts.

Xsv

public Xsv(java.io.File file)
    throws java.io.IOException
Constructs a new 'x'sv Object by passing in a File object that has been instantiated to the file to open.

Parameters:
file - The file object to open.
Throws:
java.io.IOException - If there is a problem opening the file and reading its contents.

Xsv

public Xsv(java.lang.String path)
    throws java.io.IOException
Constructs a new 'x'sv Object by passing in a path to the file to open.

Parameters:
path - The path to the file to open.
Throws:
java.io.IOException - If there is a problem creating the file from the given path or opening the file and reading its contents.
Method Detail

parse

public void parse(java.io.File file)
           throws java.io.IOException
Parse a source file into its components parts.

Parameters:
file - The File to parse.
Throws:
java.io.IOException - If there is an error reading or opening the file.

parse

public void parse(java.lang.String path)
           throws java.io.IOException
Parse a source file into its components parts.

Parameters:
path - The path to the file.
Throws:
java.io.IOException - If there is an error reading or opening the file.

separator

public abstract java.lang.String separator()
The string that contains the characters that are used as separators.

Returns:
Returns the string that should be used as the separator tokens.

next

public boolean next()
Moves the cursor to the next line. This must be called before the any of the get methods are called to move it to the first line.

Specified by:
next in interface Datasource
Returns:
Whether there is a line to process.

isBeforeFirst

public boolean isBeforeFirst()
Tells whether the cursor position is before the first line.

Specified by:
isBeforeFirst in interface Datasource
Returns:
If the cursor is beofore the first line.

isFirst

public boolean isFirst()
Tells whether the cursor is on the first row or not.

Specified by:
isFirst in interface Datasource
Returns:
Is the cursor on the first row.

isAfterLast

public boolean isAfterLast()
Tells whether the cursor has moved past the last row or not.

Specified by:
isAfterLast in interface Datasource
Returns:
Is the cursor past the last row?

isLast

public boolean isLast()
Tells whether the cursor is on the last row or not.

Specified by:
isLast in interface Datasource
Returns:
Is the cursor on the last row.

getString

public java.lang.String getString(int column)
                           throws DatasourceException
Returns the string value of the contents at the position of column.

Specified by:
getString in interface Datasource
Parameters:
column - The position of the column in the row. Value is 0 - (columns-1) inclusive.
Returns:
The string stored at that position.
Throws:
DatasourceException - If something goes wrong.

getString

public java.lang.String getString(java.lang.String name)
                           throws DatasourceException
Returns the string value found in the column of the given name.

Specified by:
getString in interface Datasource
Parameters:
name - The name of the column in the row.
Returns:
The string stored at that posisition.
Throws:
DatasourceException - If something goes wrong.

getLong

public long getLong(int column)
             throws DatasourceException
Returns the long value of the contents at the position of column.

Specified by:
getLong in interface Datasource
Parameters:
column - The position of the column in the row. Value is 0 - (columns-1) inclusive.
Returns:
The long value stored at that position.
Throws:
DatasourceException - If something goes wrong.

getLong

public long getLong(java.lang.String name)
             throws DatasourceException
Returns the long value found in the column of the given name.

Specified by:
getLong in interface Datasource
Parameters:
name - The name of the column in the row.
Returns:
The long value stored at that posisition.
Throws:
DatasourceException - If something goes wrong.

getInt

public int getInt(int column)
           throws DatasourceException
Returns the int value of the contents at the position of column.

Specified by:
getInt in interface Datasource
Parameters:
column - The position of the column in the row. Value is 0 - (columns-1) inclusive.
Returns:
The int value stored at that position.
Throws:
DatasourceException - If something goes wrong.

getInt

public int getInt(java.lang.String name)
           throws DatasourceException
Returns the int value found in the column of the given name.

Specified by:
getInt in interface Datasource
Parameters:
name - The name of the column in the row.
Returns:
The int value stored at that posisition.
Throws:
DatasourceException - If something goes wrong.

getDouble

public double getDouble(int column)
                 throws DatasourceException
Returns the double value of the contents at the position of column.

Specified by:
getDouble in interface Datasource
Parameters:
column - The position of the column in the row. Value is 0 - (columns-1) inclusive.
Returns:
The double value stored at that position.
Throws:
DatasourceException - If something goes wrong.

getDouble

public double getDouble(java.lang.String name)
                 throws DatasourceException
Returns the double value found in the column of the given name.

Specified by:
getDouble in interface Datasource
Parameters:
name - The name of the column in the row.
Returns:
The double value stored at that posisition.
Throws:
DatasourceException - If something goes wrong.

getFloat

public float getFloat(int column)
               throws DatasourceException
Returns the float value of the contents at the position of column.

Specified by:
getFloat in interface Datasource
Parameters:
column - The position of the column in the row. Value is 0 - (columns-1) inclusive.
Returns:
The float value stored at that position.
Throws:
DatasourceException - If something goes wrong.

getFloat

public float getFloat(java.lang.String name)
               throws DatasourceException
Returns the float value found in the column of the given name.

Specified by:
getFloat in interface Datasource
Parameters:
name - The name of the column in the row.
Returns:
The float value stored at that posisition.
Throws:
DatasourceException - If something goes wrong.

getBoolean

public boolean getBoolean(int column)
                   throws DatasourceException
Returns the boolean value of the contents at the position of column.

Specified by:
getBoolean in interface Datasource
Parameters:
column - The position of the column in the row. Value is 0 - (columns-1) inclusive.
Returns:
The boolean value stored at that position.
Throws:
DatasourceException - If something goes wrong.

getBoolean

public boolean getBoolean(java.lang.String name)
                   throws DatasourceException
Returns the boolean value found in the column of the given name.

Specified by:
getBoolean in interface Datasource
Parameters:
name - The name of the column in the row.
Returns:
The boolean value stored at that posisition.
Throws:
DatasourceException - If something goes wrong.

columnCount

public int columnCount()
                throws DatasourceException
Returns the number of columns in the current row.

Specified by:
columnCount in interface Datasource
Throws:
DatasourceException - If called on an invalid row.

setLineTerminator

public void setLineTerminator(java.lang.String lineTerminator)
Set the value of the line terminator. Generally will ge something like "\n" or "\r\n"

Parameters:
lineTerminator - The string that terminates lines.

getLineTeminator

public java.lang.String getLineTeminator()
Get the value of the line separator currently being used.

Returns:
The line terminator value.

setFirstRowIsColumnNames

public void setFirstRowIsColumnNames(boolean isColumns)
Is the first row a column name?

Parameters:
isColumns - True if the first row is column names.

getFirstRowIsColumnNames

public boolean getFirstRowIsColumnNames()
Whether this parser will treat the first row as column names or not.

Returns:
True if the first row will be treated as column names.

getRawData

public java.lang.String[][] getRawData()
Get the raw data of the parsed xSV file.

Returns:
The two-dimensional array of data.

getDoubleData

public double[][] getDoubleData()
Get the raw data as a matrix of double values.

Returns:
The double values.

getIntData

public int[][] getIntData()
Get the raw data as a matrix of int values.

Returns:
The int values.