org.apache.jorphan.collections

## Class Data

- java.lang.Object
- - org.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. WARNING: the class assumes that column names are unique, but does not enforce this.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Data()` Constructor - takes no arguments.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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<java.lang.Object>` | `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.
    `int` | `getHeaderCount()`
    `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)` Sorts the data using a given row as the sorting criteria.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### 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.
      Parameters:
        `oldHeader` - Old header name.
        `newHeader` - New header name.

    - #### append

          public void append(Data d)

      Adds the rows of the given Data object to this Data object.
      Parameters:
        `d` - data object to be appended to this one

    - #### getCurrentPos

          public int getCurrentPos()

      Get the number of the current row.
      Returns:
        integer representing 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.
      Parameters:
        `r` - position to set to.

    - #### sort

          public void sort(java.lang.String column)

      Sorts the data using a given row as the sorting criteria. A boolean value indicates whether to sort ascending or descending.
      Parameters:
        `column` - name of column to use as sorting criteria.

    - #### size

          public int size()

      Gets the number of rows in the Data object.
      Returns:
        number of rows in 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.
      Parameters:
        `column` - the name of the column to set.
        `value` - value to set into column.

    - #### findValue

          public int findValue(java.lang.String column,
                               java.lang.Object value)

      Returns the row number where a certain value is.
      Parameters:
        `column` - column to be searched for value.
        `value` - object in Search of.
      Returns:
        row # where value exists.

    - #### 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.
      Parameters:
        `column` - the name of the column to set.
        `value` - value to set into column.

    - #### hasHeader

          public boolean hasHeader(java.lang.String column)

      Checks to see if a column exists in the Data object.
      Parameters:
        `column` - Name of column header to check for.
      Returns:
        True or False depending on whether the column exists.

    - #### next

          public boolean next()

      Sets the current position of the Data set to the next row.
      Returns:
        True if there is another row. False if there are no more rows.

    - #### previous

          public boolean previous()

      Sets the current position of the Data set to the previous row.
      Returns:
        True if there is another row. False if there are no more rows.

    - #### 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.
      Parameters:
        `column` - name of the column.
      Returns:
        an Object which holds the value of the column.

    - #### getColumnValue

          public java.lang.Object getColumnValue(int column)

      Gets the value in the current row of the given column.
      Parameters:
        `column` - index of the column (starts at 0).
      Returns:
        an Object which holds the value of the 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.
      Parameters:
        `h` - array of strings representing the column headers. these must be distinct - duplicates will cause incorrect behaviour

    - #### getHeaders

          public java.lang.String[] getHeaders()

      Returns a String array of the column headers.
      Returns:
        array of strings of the column headers.

    - #### getHeaderCount

          public int getHeaderCount()

    - #### getColumnAsObjectArray

          public java.util.List<java.lang.Object> getColumnAsObjectArray(java.lang.String columnName)

      This method will retrieve every entry in a certain column. It returns an array of Objects from the column.
      Parameters:
        `columnName` - name of the column.
      Returns:
        array of Objects representing the data.

    - #### 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.
      Parameters:
        `columnName` - name of the column.
      Returns:
        array of Strings representing the data.

    - #### 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.
      Parameters:
        `contents` - array of strings, the first element is a list of the column headers, the next elements each represent a single row of data.
        `delimiter` - the delimiter character that separates columns within the string array.

    - #### setColumnData

          public void setColumnData(java.lang.String colName,
                                    java.lang.Object value)

      Sets the data for every row in the column.
      Parameters:
        `colName` - name of the column
        `value` - value to be set

    - #### 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.
      Parameters:
        `s` - name of header.

    - #### 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.
      Parameters:
        `line` - array of strings representing column values.

    - #### 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.
      Parameters:
        `line` - array of strings representing column values.
        `deflt` - default value to be placed in data if line is not as long as headers.

    - #### 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.
      Returns:
        array of strings.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

Copyright © 1998-2019 Apache Software Foundation. All Rights Reserved.