Class Row

  • All Implemented Interfaces:
    RowGetterIfc, RowIfc, RowSetterIfc

    public class Row
    extends java.lang.Object
    implements RowGetterIfc, RowSetterIfc, RowIfc
    An abstraction for a row within a tabular file. The access to the columns is 0-based. Why? Because most if not all of java's data containers (arrays, lists, etc.) are 0-based. The the first column has index 0, 2nd column has index 1, etc.
    • Constructor Detail

    • Method Detail

      • getRowNum

        public final long getRowNum()
        Returns:
        the number of this row if it was returned from a tabular file
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getBytes

        public int getBytes()
        Specified by:
        getBytes in interface RowIfc
        Returns:
        the number of bytes stored in the row
      • getNumNumericColumns

        public final int getNumNumericColumns()
        Specified by:
        getNumNumericColumns in interface RowIfc
        Returns:
        the total number of numeric columns
      • getNumTextColumns

        public final int getNumTextColumns()
        Specified by:
        getNumTextColumns in interface RowIfc
        Returns:
        the total number of text columns
      • getColumnTypes

        public final java.util.LinkedHashMap<java.lang.String,​DataType> getColumnTypes()
        Specified by:
        getColumnTypes in interface RowIfc
        Returns:
        the map of columns associated with this row
      • getColumnNames

        public final java.util.List<java.lang.String> getColumnNames()
        Specified by:
        getColumnNames in interface RowIfc
        Returns:
        an ordered list of the column names for the row
      • getDataTypes

        public final java.util.List<DataType> getDataTypes()
        Specified by:
        getDataTypes in interface RowIfc
        Returns:
        an ordered list of the column data types
      • getDataType

        public final DataType getDataType​(int colNum)
        Specified by:
        getDataType in interface RowIfc
        Parameters:
        colNum - 0 based indexing
        Returns:
        the data type of the column at the index
      • getNumberColumns

        public final int getNumberColumns()
        Specified by:
        getNumberColumns in interface RowIfc
        Returns:
        the number of columns of tabular data
      • isAllNumeric

        public final boolean isAllNumeric()
        Specified by:
        isAllNumeric in interface RowIfc
        Returns:
        true if all cells are NUMERIC
      • isAllText

        public final boolean isAllText()
        Specified by:
        isAllText in interface RowIfc
        Returns:
        true if all cells are TEXT
      • getType

        public final DataType getType​(int col)
        Specified by:
        getType in interface RowIfc
        Parameters:
        col - the index of the column, 0 based
        Returns:
        the data type of the column associated with this cell
      • getColumnName

        public final java.lang.String getColumnName​(int col)
        Specified by:
        getColumnName in interface RowIfc
        Parameters:
        col - the index of the column, 0 based
        Returns:
        the name of the column associated with this cell
      • getColumn

        public final int getColumn​(java.lang.String name)
        Specified by:
        getColumn in interface RowIfc
        Parameters:
        name - the name to look up
        Returns:
        the index or -1 if not found
      • isNumeric

        public final boolean isNumeric​(int i)
        Specified by:
        isNumeric in interface RowIfc
        Parameters:
        i - the index into the row (0 based)
        Returns:
        true if the cell at location i is NUMERIC
      • isText

        public final boolean isText​(int i)
        Specified by:
        isText in interface RowIfc
        Parameters:
        i - i the index into the row (0 based)
        Returns:
        true if the cell at location i is TEXT
      • setNumeric

        public final void setNumeric​(int colNum,
                                     double value)
        Specified by:
        setNumeric in interface RowSetterIfc
        Parameters:
        colNum - the index into the row (0 based)
        value - the value to set, will throw an exception of the cell is not NUMERIC
      • setText

        public final void setText​(int colNum,
                                  java.lang.String value)
        Specified by:
        setText in interface RowSetterIfc
        Parameters:
        colNum - the index into the row (0 based)
        value - the value to set, will throw an exception of the cell is not TEXT
      • getNumeric

        public final double getNumeric​(int colNum)
        Specified by:
        getNumeric in interface RowGetterIfc
        Parameters:
        colNum - the index into the row (0 based)
        Returns:
        the value as a double, will throw an exception if the cell is not NUMERIC
      • getNumeric

        public final double[] getNumeric()
        Specified by:
        getNumeric in interface RowGetterIfc
        Returns:
        the numeric columns as an array
      • getText

        public final java.lang.String getText​(int colNum)
        Specified by:
        getText in interface RowGetterIfc
        Parameters:
        colNum - the index into the row (0 based)
        Returns:
        the value as a double, will throw an exception if the cell is not TEXT
      • getText

        public final java.lang.String[] getText()
        Specified by:
        getText in interface RowGetterIfc
        Returns:
        the text columns in order of appearance as an array
      • setNumeric

        public final int setNumeric​(double[] data)
        Description copied from interface: RowSetterIfc
        Sets the numeric columns according to the data in the array. If the array has more elements than the number of columns, then the columns are filled with first elements of the array up to the number of columns. If the array has less elements than the number of columns, then only the first data.length columns are set.
        Specified by:
        setNumeric in interface RowSetterIfc
        Parameters:
        data - an array of data for the numeric rows. The array must not be null.
        Returns:
        the number of columns that were set
      • setText

        public final int setText​(java.lang.String[] data)
        Description copied from interface: RowSetterIfc
        Sets the text columns according to the data in the array. If the array has more elements than the number of columns, then the columns are filled with first elements of the array up to the number of columns. If the array has less elements than the number of columns, then only the first data.length columns are set.
        Specified by:
        setText in interface RowSetterIfc
        Parameters:
        data - an array of data for the text rows. The array must not be null.
        Returns:
        the number of columns that were set
      • setText

        public final int setText​(java.util.List<java.lang.String> data)
        Description copied from interface: RowSetterIfc
        Sets the text columns according to the data in the list. If the list has more elements than the number of columns, then the columns are filled with first elements of the list up to the number of columns. If the list has less elements than the number of columns, then only the first data.size() columns are set.
        Specified by:
        setText in interface RowSetterIfc
        Parameters:
        data - a list of data for the text rows. The list must not be null.
        Returns:
        the number of columns that were set
      • getNumeric

        public final double getNumeric​(java.lang.String columnName)
        Specified by:
        getNumeric in interface RowGetterIfc
        Parameters:
        columnName - the name of the column
        Returns:
        the value of the column
      • getText

        public final java.lang.String getText​(java.lang.String columnName)
        Specified by:
        getText in interface RowGetterIfc
        Parameters:
        columnName - the name of the column
        Returns:
        the value of the column
      • setNumeric

        public final void setNumeric​(java.lang.String columnName,
                                     double value)
        Specified by:
        setNumeric in interface RowSetterIfc
        Parameters:
        columnName - the name of the column to set
        value - the value to set
      • setText

        public final void setText​(java.lang.String columnName,
                                  java.lang.String value)
        Specified by:
        setText in interface RowSetterIfc
        Parameters:
        columnName - the name of the column to set
        value - the value to set
      • getElements

        public final java.lang.Object[] getElements()
        Specified by:
        getElements in interface RowGetterIfc
        Returns:
        the elements of the row as Objects
      • toCSV

        public final java.lang.String toCSV()
        Specified by:
        toCSV in interface RowGetterIfc
        Returns:
        the row as comma separated values. The row does not contain a line separator.
      • asStringArray

        public final java.lang.String[] asStringArray()
        Specified by:
        asStringArray in interface RowGetterIfc
        Returns:
        the row as an array of strings
      • getElement

        public final java.lang.Object getElement​(int colNum)
        Specified by:
        getElement in interface RowGetterIfc
        Parameters:
        colNum - the column number
        Returns:
        an object representation of the element at the column
      • setElements

        public final void setElements​(java.lang.Object[] elements)
        Description copied from interface: RowSetterIfc
        The row is filled with the elements. Numeric elements are saved in numeric columns in the order presented. Non-numeric elements are all converted to strings and stored in the order presented. Numeric elements are of types {Double, Long, Integer, Boolean, Float, Short, Byte}. Any other type is converted to text via toString().

        The order and types of the elements must match the order and types associated with the columns.

        Specified by:
        setElements in interface RowSetterIfc
        Parameters:
        elements - the elements to add to the row. The number of elements must be equal to the number of columns
      • setElement

        public final void setElement​(int colNum,
                                     java.lang.Object element)
        Specified by:
        setElement in interface RowSetterIfc
        Parameters:
        colNum - the column number to set
        element - the element to set