Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.jorphan.collections
Class Data  view Data download Data.java

java.lang.Object
  extended byorg.apache.jorphan.collections.Data
All Implemented Interfaces:
java.io.Serializable

public class Data
extends java.lang.Object
implements java.io.Serializable

Use this class to store database-like data. This class uses rows and columns to organize its data. It has some convenience methods that allow fast loading and retrieval of the data into and out of string arrays. It is also handy for reading CSV files.

Version:
$Revision: 1.12 $

Field Summary
(package private)  int currentPos
           
(package private)  java.util.Map data
           
(package private)  java.util.ArrayList header
           
private static Logger log
           
(package private)  int size
           
 
Constructor Summary
Data()
          Constructor - takes no arguments.
 
Method Summary
 void addColumnValue(java.lang.String column, java.lang.Object value)
          Adds a value into the Data set at the current row, using a column name to find the column in which to insert the new value.
 void addHeader(java.lang.String s)
          Adds a header name to the Data object.
 void addRow()
           
 void append(Data d)
          Adds the rows of the given Data object to this Data object.
 int findValue(java.lang.String column, java.lang.Object value)
          Returns the row number where a certain value is.
 java.lang.String[] getColumn(java.lang.String columnName)
          This method will retrieve every entry in a certain column.
 java.util.List getColumnAsObjectArray(java.lang.String columnName)
          This method will retrieve every entry in a certain column.
 java.lang.Object getColumnValue(int column)
          Gets the value in the current row of the given column.
 java.lang.Object getColumnValue(int column, int row)
           
 java.lang.Object getColumnValue(java.lang.String column)
          Gets the value in the current row of the given column.
 int getCurrentPos()
          Get the number of the current row.
 java.lang.String[] getDataAsText()
          Returns all the data in the Data set as an array of strings.
static Data getDataFromResultSet(java.sql.ResultSet rs)
          Gets a Data object from a ResultSet.
 java.lang.String[] getHeaders()
          Returns a String array of the column headers.
 boolean hasHeader(java.lang.String column)
          Checks to see if a column exists in the Data object.
 boolean next()
          Sets the current position of the Data set to the next row.
 boolean previous()
          Sets the current position of the Data set to the previous row.
 void removeColumn(int col)
           
 void removeRow()
          Removes the current row.
 void removeRow(int index)
           
 void replaceHeader(java.lang.String oldHeader, java.lang.String newHeader)
          Replaces the given header name with a new header name.
 void reset()
          Resets the current position of the data set to just before the first element.
 void setColumnData(int col, java.util.List data)
           
 void setColumnData(java.lang.String colName, java.lang.Object value)
          Sets the data for every row in the column.
 void setColumnValue(java.lang.String column, java.lang.Object value)
          Sets the value in the Data set at the current row, using a column name to find the column in which to insert the new value.
 void setCurrentPos(int r)
          Sets the current pos.
 void setData(java.lang.String[] contents, java.lang.String delimiter)
          Use this method to set the entire data set.
 void setHeaders(java.lang.String[] h)
          Sets the headers for the data set.
 void setLine(java.lang.String[] line)
          Sets a row of data using an array of strings as input.
 void setLine(java.lang.String[] line, java.lang.String deflt)
          Sets a row of data using an array of strings as input.
 int size()
          Gets the number of rows in the Data object.
 void sort(java.lang.String column, boolean asc)
          Sorts the data using a given row as the sorting criteria.
private  void sortData(java.lang.String column, int start, int end)
          Private method that implements the quicksort algorithm to sort the rows of the Data object.
private  void swapRows(int row1, int row2)
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static Logger log

data

java.util.Map data

header

java.util.ArrayList header

currentPos

int currentPos

size

int size
Constructor Detail

Data

public Data()
Constructor - takes no arguments.

Method Detail

replaceHeader

public void replaceHeader(java.lang.String oldHeader,
                          java.lang.String newHeader)
Replaces the given header name with a new header name.


append

public void append(Data d)
Adds the rows of the given Data object to this Data object.


getCurrentPos

public int getCurrentPos()
Get the number of the current row.


removeRow

public void removeRow()
Removes the current row.


removeRow

public void removeRow(int index)

addRow

public void addRow()

setCurrentPos

public void setCurrentPos(int r)
Sets the current pos. If value sent to method is not a valid number, the current position is set to one higher than the maximum.


sort

public void sort(java.lang.String column,
                 boolean asc)
Sorts the data using a given row as the sorting criteria. A boolean value indicates whether to sort ascending or descending.


swapRows

private void swapRows(int row1,
                      int row2)

sortData

private void sortData(java.lang.String column,
                      int start,
                      int end)
Private method that implements the quicksort algorithm to sort the rows of the Data object.


size

public int size()
Gets the number of rows in the Data object.


addColumnValue

public void addColumnValue(java.lang.String column,
                           java.lang.Object value)
Adds a value into the Data set at the current row, using a column name to find the column in which to insert the new value.


findValue

public int findValue(java.lang.String column,
                     java.lang.Object value)
Returns the row number where a certain value is.


setColumnValue

public void setColumnValue(java.lang.String column,
                           java.lang.Object value)
Sets the value in the Data set at the current row, using a column name to find the column in which to insert the new value.


hasHeader

public boolean hasHeader(java.lang.String column)
Checks to see if a column exists in the Data object.


next

public boolean next()
Sets the current position of the Data set to the next row.


getDataFromResultSet

public static Data getDataFromResultSet(java.sql.ResultSet rs)
                                 throws java.sql.SQLException
Gets a Data object from a ResultSet.


previous

public boolean previous()
Sets the current position of the Data set to the previous row.


reset

public void reset()
Resets the current position of the data set to just before the first element.


getColumnValue

public java.lang.Object getColumnValue(java.lang.String column)
Gets the value in the current row of the given column.


getColumnValue

public java.lang.Object getColumnValue(int column)
Gets the value in the current row of the given column.


getColumnValue

public java.lang.Object getColumnValue(int column,
                                       int row)

removeColumn

public void removeColumn(int col)

setHeaders

public void setHeaders(java.lang.String[] h)
Sets the headers for the data set. Each header represents a column of data. Each row's data can be gotten with the column header name, which will always be a string.


getHeaders

public java.lang.String[] getHeaders()
Returns a String array of the column headers.


getColumnAsObjectArray

public java.util.List getColumnAsObjectArray(java.lang.String columnName)
This method will retrieve every entry in a certain column. It returns an array of Objects from the column.


getColumn

public java.lang.String[] getColumn(java.lang.String columnName)
This method will retrieve every entry in a certain column. It returns an array of strings from the column. Even if the data are not strings, they will be returned as strings in this method.


setData

public void setData(java.lang.String[] contents,
                    java.lang.String delimiter)
Use this method to set the entire data set. It takes an array of strings. It uses the first row as the headers, and the next rows as the data elements. Delimiter represents the delimiting character(s) that separate each item in a data row.


setColumnData

public void setColumnData(java.lang.String colName,
                          java.lang.Object value)
Sets the data for every row in the column.


setColumnData

public void setColumnData(int col,
                          java.util.List data)

addHeader

public void addHeader(java.lang.String s)
Adds a header name to the Data object.


setLine

public void setLine(java.lang.String[] line)
Sets a row of data using an array of strings as input. Each value in the array represents a column's value in that row. Assumes the order will be the same order in which the headers were added to the data set.


setLine

public void setLine(java.lang.String[] line,
                    java.lang.String deflt)
Sets a row of data using an array of strings as input. Each value in the array represents a column's value in that row. Assumes the order will be the same order in which the headers were added to the data set.


getDataAsText

public java.lang.String[] getDataAsText()
Returns all the data in the Data set as an array of strings. Each array gives a row of data, each column separated by tabs.


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).