|
CS 1705 Library | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcs1705.CSVDataTable
public class CSVDataTable
CSVDataTable is an implementation of DataTable that allows the user to interact with CSV Files. The CSVDataTable class loads a CSV file into a DataTable format that can be maniupulated using the methods of the DataTable class.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface cs1705.DataTable |
|---|
DataTable.HashedRow, DataTable.Row |
| Constructor Summary | |
|---|---|
CSVDataTable()
This constructor creates an empty DataTable with no columns. |
|
CSVDataTable(File file)
Create a new data table using CSV data from a file. |
|
CSVDataTable(File file,
boolean firstRowNames)
Create a new data table using CSV data from a file. |
|
CSVDataTable(File file,
boolean firstRowNames,
char delimiter)
Create a new data table using CSV data on a website. |
|
CSVDataTable(InputStream in,
boolean firstRowNames,
char delimiter)
Create a new data table using CSV data from an input stream. |
|
CSVDataTable(String url)
Create a new data table using CSV data on a website. |
|
CSVDataTable(String url,
boolean firstRowNames)
Create a new data table using CSV data on a website. |
|
CSVDataTable(String url,
boolean firstRowNames,
char delimiter)
Create a new data table using CSV data on a website. |
|
| Method Summary | |
|---|---|
void |
addColumn(String columnName)
This method adds a column to the table. |
void |
addColumn(String columnName,
String defaultValue)
This method adds a column to the table, setting this column to the specified default value in every row. |
void |
addRow(DataTable.Row row)
This method adds a row to the table. |
double |
avg(String column)
This method computes the average of a column that has numeric values. |
int |
colCount()
This method returns the number of columns in the data table. |
void |
copyRowsFrom(DataTable dataSet)
This method copies an existing DataTable's rows into the DataTable. |
int |
count(String column,
String value)
This method counts the number of rows in the specified column that have the value given by the value parameter. |
ArrayList<DataTable.Row> |
getAllRows()
This method returns a representation of the Data Table. |
String |
getCell(int row,
int column)
This method returns the String value in the table at a specified row/column location. |
String |
getCell(int row,
String column)
This method returns the String value in the table at a specified row/column location. |
String |
getCell(String row,
int column)
This method returns the String value in the table at a specified row/column location. |
String |
getCell(String row,
String column)
This method returns the String value in the table at a specified row/column location. |
ArrayList<String> |
getColumnNames()
This method returns a list of the names of all of the columns of the data table. |
char |
getDelimiter()
Get the delimiter used by this data set. |
double |
getDoubleCell(int row,
int column)
This method returns the double value in the table at a specified row/column location. |
double |
getDoubleCell(int row,
String column)
This method returns the double value in the table at a specified row/column location. |
double |
getDoubleCell(String row,
int column)
This method returns the double value in the table at a specified row/column location. |
double |
getDoubleCell(String row,
String column)
This method returns the double value in the table at a specified row/column location. |
int |
getIntCell(int row,
int column)
This method returns the int value in the table at a specified row/column location. |
int |
getIntCell(int row,
String column)
This method returns the int value in the table at a specified row/column location. |
int |
getIntCell(String row,
int column)
This method returns the int value in the table at a specified row/column location. |
int |
getIntCell(String row,
String column)
This method returns the int value in the table at a specified row/column location. |
String |
getPrimaryKey()
This method returns the column name that acts as the primary key for the table. |
DataTable.Row |
getRow(int row)
This method returns a map that represents the desired row (indicated by the primary key). |
DataTable.Row |
getRow(String row)
This method returns a Map that represents the desired row. |
String |
getUrl()
|
double |
max(String column)
This method computes the maximum value of a column that has numeric values. |
double |
min(String column)
This method computes the minimum value of a column that has numeric values. |
void |
remapColumnNames(Map<String,String> columnMap)
This method replaces each column name in the table with a matching key in columnMap with the value of the mapping. |
DataTable.Row |
removeRow(int row)
This method removes the row identified by row number. |
DataTable.Row |
removeRow(String row)
This method removes the row (to be determined by the key). |
int |
rowCount()
This method returns the number of rows in the data table. |
void |
save(String filename)
This method saves the CSVDataTable in a CSV file format with the first row the column names and the remaining rows the data in the table. |
void |
setCell(int row,
int column,
double value)
This method allows you to update a desired row and column with new data as a double. |
void |
setCell(int row,
int column,
int value)
This method allows you to update a desired row and column with new data as an int. |
void |
setCell(int row,
int column,
String value)
This method allows you to update a desired row and column with new data as a String. |
void |
setCell(int row,
String column,
double value)
This method allows you to update a desired row and column with new data as a double. |
void |
setCell(int row,
String column,
int value)
This method allows you to update a desired row and column with new data as an int. |
void |
setCell(int row,
String column,
String value)
This method allows you to update a desired row and column with new data as a String. |
void |
setCell(String row,
int column,
double value)
This method allows you to update a desired row and column with new data as a double. |
void |
setCell(String row,
int column,
int value)
This method allows you to update a desired row and column with new data as an int. |
void |
setCell(String row,
int column,
String value)
This method allows you to update a desired row and column with new data as a String. |
void |
setCell(String row,
String column,
double value)
This method allows you to update a desired row and column with new data as a double. |
void |
setCell(String row,
String column,
int value)
This method allows you to update a desired row and column with new data as an int. |
void |
setCell(String row,
String column,
String value)
This method allows you to update a desired row and column with new data as a String. |
void |
setColumnNames(ArrayList<String> columns)
This method sets an arbitrary name for each of the columns in the table. |
void |
setDelimiter(char delimiter)
Set the delimiter used by this data set, which will affect how this object will be written to a file in the future. |
void |
setPrimaryKey(String key)
This method sets the column name that acts as the primary key for the table. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CSVDataTable()
public CSVDataTable(String url)
url - the URL path to the CSV file.
public CSVDataTable(String url,
boolean firstRowNames)
url - the URL path to the CSV file.firstRowNames - If true, then the first row in the data source
should be treated as containing the names for the columns
in the data set.
public CSVDataTable(String url,
boolean firstRowNames,
char delimiter)
url - the URL path to the CSV file.firstRowNames - If true, then the first row in the data source
should be treated as containing the names for the columns
in the data set.delimiter - The separator between fields on the same line
(e.g., a comma, tab, colon, etc.).public CSVDataTable(File file)
file - the CSV file to read.
public CSVDataTable(File file,
boolean firstRowNames)
file - the CSV file to read.firstRowNames - If true, then the first row in the data source
should be treated as containing the names for the columns
in the data set.
public CSVDataTable(File file,
boolean firstRowNames,
char delimiter)
file - the CSV file to read.firstRowNames - If true, then the first row in the data source
should be treated as containing the names for the columns
in the data set.delimiter - The separator between fields on the same line
(e.g., a comma, tab, colon, etc.).
public CSVDataTable(InputStream in,
boolean firstRowNames,
char delimiter)
in - the input stream that contains the CSV data.firstRowNames - If true, then the first row in the data source
should be treated as containing the names for the columns
in the data set.delimiter - The separator between fields on the same line
(e.g., a comma, tab, colon, etc.).| Method Detail |
|---|
public int rowCount()
DataTable
rowCount in interface DataTablepublic int colCount()
DataTable
colCount in interface DataTable
public String getCell(int row,
String column)
DataTable
getCell in interface DataTablerow - index of row to retrieve (starting at zero)column - the name of the desired column
public String getCell(int row,
int column)
DataTable
getCell in interface DataTablerow - index of row to retrieve (starting at zero)column - index of column to retrieve (starting at zero)
public String getCell(String row,
String column)
DataTable
getCell in interface DataTablerow - primary key of rowcolumn - the name of the desired column
public String getCell(String row,
int column)
DataTable
getCell in interface DataTablerow - primary key of rowcolumn - index of column to retrieve (starting at zero)
public int getIntCell(int row,
String column)
throws NumberFormatException
DataTable
getIntCell in interface DataTablerow - index of row to retrieve (starting at zero)column - the name of the desired column
NumberFormatException - if the cell does not contain an int
value.
public int getIntCell(int row,
int column)
throws NumberFormatException
DataTable
getIntCell in interface DataTablerow - index of row to retrieve (starting at zero)column - index of column to retrieve (starting at zero)
NumberFormatException - if the cell does not contain an int
value.
public int getIntCell(String row,
String column)
throws NumberFormatException
DataTable
getIntCell in interface DataTablerow - primary key of rowcolumn - the name of the desired column
NumberFormatException - if the cell does not contain an int
value.
public int getIntCell(String row,
int column)
throws NumberFormatException
DataTable
getIntCell in interface DataTablerow - primary key of rowcolumn - index of column to retrieve (starting at zero)
NumberFormatException - if the cell does not contain an int
value.
public double getDoubleCell(int row,
String column)
throws NumberFormatException
DataTable
getDoubleCell in interface DataTablerow - index of row to retrieve (starting at zero)column - the name of the desired column
NumberFormatException - if the cell does not contain a double
value.
public double getDoubleCell(int row,
int column)
throws NumberFormatException
DataTable
getDoubleCell in interface DataTablerow - index of row to retrieve (starting at zero)column - index of column to retrieve (starting at zero)
NumberFormatException - if the cell does not contain a double
value.
public double getDoubleCell(String row,
String column)
throws NumberFormatException
DataTable
getDoubleCell in interface DataTablerow - primary key of rowcolumn - the name of the desired column
NumberFormatException - if the cell does not contain a double
value.
public double getDoubleCell(String row,
int column)
throws NumberFormatException
DataTable
getDoubleCell in interface DataTablerow - primary key of rowcolumn - index of column to retrieve (starting at zero)
NumberFormatException - if the cell does not contain a double
value.public DataTable.Row getRow(int row)
DataTable
getRow in interface DataTablerow - index of row to retrieve (starting from zero)
public DataTable.Row getRow(String row)
DataTable
getRow in interface DataTablerow - primary key of row to retrieve
public void setCell(int row,
String column,
String value)
DataTable
setCell in interface DataTablerow - index of row to change (starting from zero)column - name of the column to changevalue - the value that is to replace the current value
public void setCell(int row,
String column,
int value)
DataTable
setCell in interface DataTablerow - index of row to change (starting from zero)column - name of the column to changevalue - the value that is to replace the current value
public void setCell(int row,
String column,
double value)
DataTable
setCell in interface DataTablerow - index of row to change (starting from zero)column - name of the column to changevalue - the value that is to replace the current value
public void setCell(int row,
int column,
String value)
DataTable
setCell in interface DataTablerow - index of row to change (starting from zero)column - index of column to change (starting from zero)value - the value that is to replace the current value
public void setCell(int row,
int column,
int value)
DataTable
setCell in interface DataTablerow - index of row to change (starting from zero)column - index of column to change (starting from zero)value - the value that is to replace the current value
public void setCell(int row,
int column,
double value)
DataTable
setCell in interface DataTablerow - index of row to change (starting from zero)column - index of column to change (starting from zero)value - the value that is to replace the current value
public void setCell(String row,
String column,
String value)
DataTable
setCell in interface DataTablerow - primary key of the row to changecolumn - name of the column to changevalue - the value that is to replace the current value
public void setCell(String row,
String column,
int value)
DataTable
setCell in interface DataTablerow - primary key of the row to changecolumn - name of the column to changevalue - the value that is to replace the current value
public void setCell(String row,
String column,
double value)
DataTable
setCell in interface DataTablerow - primary key of the row to changecolumn - name of the column to changevalue - the value that is to replace the current value
public void setCell(String row,
int column,
String value)
DataTable
setCell in interface DataTablerow - primary key of the row to changecolumn - index of column to change (starting from zero)value - the value that is to replace the current value
public void setCell(String row,
int column,
int value)
DataTable
setCell in interface DataTablerow - primary key of the row to changecolumn - index of column to change (starting from zero)value - the value that is to replace the current value
public void setCell(String row,
int column,
double value)
DataTable
setCell in interface DataTablerow - primary key of the row to changecolumn - index of column to change (starting from zero)value - the value that is to replace the current valuepublic DataTable.Row removeRow(int row)
DataTable
removeRow in interface DataTablerow - table row to be deleted.
public DataTable.Row removeRow(String row)
DataTable
removeRow in interface DataTablerow - table row to be deleted.
public void addColumn(String columnName)
DataTable
addColumn in interface DataTablecolumnName - the name of the column to be added.
public void addColumn(String columnName,
String defaultValue)
DataTable
addColumn in interface DataTablecolumnName - the name of the column to be added.defaultValue - the default value to use for the column.public void addRow(DataTable.Row row)
DataTable
addRow in interface DataTablerow - The row to addpublic void setPrimaryKey(String key)
DataTable
setPrimaryKey in interface DataTablekey - the column name to be set as the primary key.public String getPrimaryKey()
DataTable
getPrimaryKey in interface DataTablepublic ArrayList<String> getColumnNames()
DataTable
getColumnNames in interface DataTablepublic void setColumnNames(ArrayList<String> columns)
DataTable
setColumnNames in interface DataTablecolumns - names of columns to be set in the table.public void remapColumnNames(Map<String,String> columnMap)
DataTable
remapColumnNames in interface DataTablecolumnMap - names of columns to be replaced with the
associated value to replace it with.public ArrayList<DataTable.Row> getAllRows()
DataTable
getAllRows in interface DataTablepublic String getUrl()
public void copyRowsFrom(DataTable dataSet)
DataTable
copyRowsFrom in interface DataTabledataSet - a DataTable object to copy into the current DataTable.
public int count(String column,
String value)
DataTable
count in interface DataTablecolumn - the desired column to count on.value - the desired value to count.
public double avg(String column)
throws NumberFormatException
DataTable
avg in interface DataTablecolumn - the column to compute the average of.
NumberFormatException - if the column has a string that cannot
be parsed as a number.
public double max(String column)
throws NumberFormatException
DataTable
max in interface DataTablecolumn - the column to compute the max number of.
NumberFormatException - if the column has a string that cannot
be parsed as a number.
public double min(String column)
throws NumberFormatException
DataTable
min in interface DataTablecolumn - the column to compute the min number of.
NumberFormatException - if the column has a string that cannot
be parsed as a number.public void save(String filename)
save in interface DataTablefilename - the path to the file to save the CSVDataTable to.
IOException - when there is a problem writing to the file.public void setDelimiter(char delimiter)
delimiter - The separator between fields on the same line
(e.g., a comma, tab, colon, etc.).public char getDelimiter()
|
Last updated: Wed, Apr 1, 2009 12:29 AM EDT | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||