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()intgetBytes()intgetColumn(java.lang.String name)java.lang.StringgetColumnName(int col)java.util.List<java.lang.String>getColumnNames()java.util.LinkedHashMap<java.lang.String,DataType>getColumnTypes()DataTypegetDataType(int colNum)java.util.List<DataType>getDataTypes()java.lang.ObjectgetElement(int colNum)java.lang.Object[]getElements()intgetNumberColumns()double[]getNumeric()doublegetNumeric(int colNum)doublegetNumeric(java.lang.String columnName)intgetNumNumericColumns()intgetNumTextColumns()longgetRowNum()java.lang.String[]getText()java.lang.StringgetText(int colNum)java.lang.StringgetText(java.lang.String columnName)DataTypegetType(int col)booleanisAllNumeric()booleanisAllText()booleanisNumeric(int i)booleanisText(int i)voidsetElement(int colNum, java.lang.Object element)voidsetElements(java.lang.Object[] elements)The row is filled with the elements.intsetNumeric(double[] data)Sets the numeric columns according to the data in the array.voidsetNumeric(int colNum, double value)voidsetNumeric(java.lang.String columnName, double value)voidsetText(int colNum, java.lang.String value)intsetText(java.lang.String[] data)Sets the text columns according to the data in the array.voidsetText(java.lang.String columnName, java.lang.String value)intsetText(java.util.List<java.lang.String> data)Sets the text columns according to the data in the list.java.lang.StringtoCSV()java.lang.StringtoString()-
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:
toStringin classjava.lang.Object
-
getBytes
public int getBytes()
-
getNumNumericColumns
public final int getNumNumericColumns()
- Specified by:
getNumNumericColumnsin interfaceRowIfc- Returns:
- the total number of numeric columns
-
getNumTextColumns
public final int getNumTextColumns()
- Specified by:
getNumTextColumnsin interfaceRowIfc- Returns:
- the total number of text columns
-
getColumnTypes
public final java.util.LinkedHashMap<java.lang.String,DataType> getColumnTypes()
- Specified by:
getColumnTypesin interfaceRowIfc- Returns:
- the map of columns associated with this row
-
getColumnNames
public final java.util.List<java.lang.String> getColumnNames()
- Specified by:
getColumnNamesin interfaceRowIfc- Returns:
- an ordered list of the column names for the row
-
getDataTypes
public final java.util.List<DataType> getDataTypes()
- Specified by:
getDataTypesin interfaceRowIfc- Returns:
- an ordered list of the column data types
-
getDataType
public final DataType getDataType(int colNum)
- Specified by:
getDataTypein interfaceRowIfc- Parameters:
colNum- 0 based indexing- Returns:
- the data type of the column at the index
-
getNumberColumns
public final int getNumberColumns()
- Specified by:
getNumberColumnsin interfaceRowIfc- Returns:
- the number of columns of tabular data
-
isAllNumeric
public final boolean isAllNumeric()
- Specified by:
isAllNumericin 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:
getColumnNamein 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:
setNumericin 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:
setTextin 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:
getNumericin 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:
getNumericin interfaceRowGetterIfc- Returns:
- the numeric columns as an array
-
getText
public final java.lang.String getText(int colNum)
- Specified by:
getTextin 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:
getTextin interfaceRowGetterIfc- Returns:
- the text columns in order of appearance as an array
-
setNumeric
public final int setNumeric(double[] data)
Description copied from interface:RowSetterIfcSets 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:
setNumericin 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:RowSetterIfcSets 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:
setTextin 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:RowSetterIfcSets 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:
setTextin 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:
getNumericin 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:
getTextin 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:
setNumericin 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:
setTextin interfaceRowSetterIfc- Parameters:
columnName- the name of the column to setvalue- the value to set
-
getElements
public final java.lang.Object[] getElements()
- Specified by:
getElementsin interfaceRowGetterIfc- Returns:
- the elements of the row as Objects
-
toCSV
public final java.lang.String toCSV()
- Specified by:
toCSVin 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:
asStringArrayin interfaceRowGetterIfc- Returns:
- the row as an array of strings
-
getElement
public final java.lang.Object getElement(int colNum)
- Specified by:
getElementin 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:RowSetterIfcThe 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:
setElementsin 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:
setElementin interfaceRowSetterIfc- Parameters:
colNum- the column number to setelement- the element to set
-
-