Package jslx.tabularfiles
Class Row
- java.lang.Object
-
- jslx.tabularfiles.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 Summary
Constructors Constructor Description Row(TabularFile tabularFile)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]
asStringArray()
int
getBytes()
int
getColumn(java.lang.String name)
java.lang.String
getColumnName(int col)
java.util.List<java.lang.String>
getColumnNames()
java.util.LinkedHashMap<java.lang.String,DataType>
getColumnTypes()
DataType
getDataType(int colNum)
java.util.List<DataType>
getDataTypes()
java.lang.Object
getElement(int colNum)
java.lang.Object[]
getElements()
int
getNumberColumns()
double[]
getNumeric()
double
getNumeric(int colNum)
double
getNumeric(java.lang.String columnName)
int
getNumNumericColumns()
int
getNumTextColumns()
long
getRowNum()
java.lang.String[]
getText()
java.lang.String
getText(int colNum)
java.lang.String
getText(java.lang.String columnName)
DataType
getType(int col)
boolean
isAllNumeric()
boolean
isAllText()
boolean
isNumeric(int i)
boolean
isText(int i)
void
setElement(int colNum, java.lang.Object element)
void
setElements(java.lang.Object[] elements)
The row is filled with the elements.int
setNumeric(double[] data)
Sets the numeric columns according to the data in the array.void
setNumeric(int colNum, double value)
void
setNumeric(java.lang.String columnName, double value)
void
setText(int colNum, java.lang.String value)
int
setText(java.lang.String[] data)
Sets the text columns according to the data in the array.void
setText(java.lang.String columnName, java.lang.String value)
int
setText(java.util.List<java.lang.String> data)
Sets the text columns according to the data in the list.java.lang.String
toCSV()
java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jslx.tabularfiles.RowSetterIfc
setNumeric
-
-
-
-
Constructor Detail
-
Row
public Row(TabularFile tabularFile)
-
-
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 classjava.lang.Object
-
getBytes
public int getBytes()
-
getNumNumericColumns
public final int getNumNumericColumns()
- Specified by:
getNumNumericColumns
in interfaceRowIfc
- Returns:
- the total number of numeric columns
-
getNumTextColumns
public final int getNumTextColumns()
- Specified by:
getNumTextColumns
in interfaceRowIfc
- Returns:
- the total number of text columns
-
getColumnTypes
public final java.util.LinkedHashMap<java.lang.String,DataType> getColumnTypes()
- Specified by:
getColumnTypes
in interfaceRowIfc
- Returns:
- the map of columns associated with this row
-
getColumnNames
public final java.util.List<java.lang.String> getColumnNames()
- Specified by:
getColumnNames
in interfaceRowIfc
- Returns:
- an ordered list of the column names for the row
-
getDataTypes
public final java.util.List<DataType> getDataTypes()
- Specified by:
getDataTypes
in interfaceRowIfc
- Returns:
- an ordered list of the column data types
-
getDataType
public final DataType getDataType(int colNum)
- Specified by:
getDataType
in interfaceRowIfc
- Parameters:
colNum
- 0 based indexing- Returns:
- the data type of the column at the index
-
getNumberColumns
public final int getNumberColumns()
- Specified by:
getNumberColumns
in interfaceRowIfc
- Returns:
- the number of columns of tabular data
-
isAllNumeric
public final boolean isAllNumeric()
- Specified by:
isAllNumeric
in interfaceRowIfc
- Returns:
- true if all cells are NUMERIC
-
isAllText
public final boolean isAllText()
-
getType
public final DataType getType(int col)
-
getColumnName
public final java.lang.String getColumnName(int col)
- Specified by:
getColumnName
in interfaceRowIfc
- 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)
-
isNumeric
public final boolean isNumeric(int i)
-
isText
public final boolean isText(int i)
-
setNumeric
public final void setNumeric(int colNum, double value)
- Specified by:
setNumeric
in interfaceRowSetterIfc
- 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 interfaceRowSetterIfc
- 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 interfaceRowGetterIfc
- 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 interfaceRowGetterIfc
- Returns:
- the numeric columns as an array
-
getText
public final java.lang.String getText(int colNum)
- Specified by:
getText
in interfaceRowGetterIfc
- 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 interfaceRowGetterIfc
- 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 interfaceRowSetterIfc
- 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 interfaceRowSetterIfc
- 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 interfaceRowSetterIfc
- 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 interfaceRowGetterIfc
- 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 interfaceRowGetterIfc
- 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 interfaceRowSetterIfc
- Parameters:
columnName
- the name of the column to setvalue
- the value to set
-
setText
public final void setText(java.lang.String columnName, java.lang.String value)
- Specified by:
setText
in interfaceRowSetterIfc
- Parameters:
columnName
- the name of the column to setvalue
- the value to set
-
getElements
public final java.lang.Object[] getElements()
- Specified by:
getElements
in interfaceRowGetterIfc
- Returns:
- the elements of the row as Objects
-
toCSV
public final java.lang.String toCSV()
- Specified by:
toCSV
in interfaceRowGetterIfc
- 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 interfaceRowGetterIfc
- Returns:
- the row as an array of strings
-
getElement
public final java.lang.Object getElement(int colNum)
- Specified by:
getElement
in interfaceRowGetterIfc
- 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 interfaceRowSetterIfc
- 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 interfaceRowSetterIfc
- Parameters:
colNum
- the column number to setelement
- the element to set
-
-