javanpst.data.structures.dataTable
Class DataTable
- java.lang.Object
-
- javanpst.data.structures.dataTable.DataTable
-
public class DataTable extends java.lang.ObjectA general purpose data table. Support null values treatment.
-
-
Constructor Summary
Constructors Constructor and Description DataTable()Default builderDataTable(double[][] data)Builder.DataTable(double[][] data, boolean[][] nullV)Builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Clear method.doubleget(int row, int col)Get a value.double[][]getBody()Get the data matrixdouble[]getColumn(int col)Get a column (no null values are considered)intgetColumnNulls(int col)Get the number of null values in the selected columnintgetColumns()Get the number of columnsboolean[][]getNulls()Get the matrix of nullsdouble[]getRow(int row)Get a row (no null values are considered)intgetRowNulls(int row)Get the number of null values in the selected rowintgetRows()Get the number of rowsbooleanisNull(int row, int col)Returns if the selected value is null of notstatic DataTablenewInstance(DataTable aTable)Copy constructorvoidreadCSV(java.lang.String file)Loads a table from a CSV filevoidreadTXT(java.lang.String file)Loads a table from a TXT filevoidreadXML(java.lang.String file)Loads a table from a XML filevoidsetColumn(int col, double[] array)Sets a entire columnvoidsetColumns(int col)Set new number of columnsvoidsetDimensions(int row, int col)Set new dimensions.voidsetNull(int row, int col)Sets a null valuevoidsetRow(int row, double[] array)Sets a entire rowvoidsetRows(int row)Set new number of rowsvoidsetValue(int row, int col, double value)Sets a new valuejava.lang.StringtoString()To String methodvoidwriteCSV(java.lang.String file, boolean useComma)Writes a table to a CSV filevoidwriteTXT(java.lang.String file)Writes a table to a TXT filevoidwriteXML(java.lang.String file)Writes a table to a XML file
-
-
-
Constructor Detail
-
DataTable
public DataTable()
Default builder
-
DataTable
public DataTable(double[][] data)
Builder. Built a new table from a data matrix Both matrixes must have the same dimensions, else a void table is created- Parameters:
data- contents of the table
-
DataTable
public DataTable(double[][] data, boolean[][] nullV)Builder. Allows to specify which values are null. Both matrixes must have the same dimensions, else a void table is created- Parameters:
data- contents of the tablenullV- null values matrix
-
-
Method Detail
-
newInstance
public static DataTable newInstance(DataTable aTable)
Copy constructor- Parameters:
aTable- old table- Returns:
- a copy of aTable
-
getBody
public double[][] getBody()
Get the data matrix- Returns:
- values of the table
-
getNulls
public boolean[][] getNulls()
Get the matrix of nulls- Returns:
- null values of the table
-
isNull
public boolean isNull(int row, int col)Returns if the selected value is null of not- Returns:
- true if it is null, false otherwise
-
getRows
public int getRows()
Get the number of rows- Returns:
- number of rows of the table
-
getColumns
public int getColumns()
Get the number of columns- Returns:
- number of columns of the table
-
clear
public void clear()
Clear method. Set all values of the table to null
-
setDimensions
public void setDimensions(int row, int col)Set new dimensions. Table is cleared after resizing- Parameters:
row- new number of rowscol- new number of columns
-
setRows
public void setRows(int row)
Set new number of rows- Parameters:
row- new number of rows
-
setColumns
public void setColumns(int col)
Set new number of columns- Parameters:
col- new number of columns
-
setValue
public void setValue(int row, int col, double value)Sets a new value- Parameters:
row- row indexcol- col indexvalue- value to set
-
setNull
public void setNull(int row, int col)Sets a null value- Parameters:
row- row indexcol- col index
-
setRow
public void setRow(int row, double[] array)Sets a entire row- Parameters:
row- row to setarray- array of values
-
setColumn
public void setColumn(int col, double[] array)Sets a entire column- Parameters:
col- column to setarray- array of values
-
getRowNulls
public int getRowNulls(int row)
Get the number of null values in the selected row- Parameters:
row- row selected- Returns:
- number of null values
-
getColumnNulls
public int getColumnNulls(int col)
Get the number of null values in the selected column- Parameters:
col- column selected- Returns:
- number of null values
-
get
public double get(int row, int col)Get a value. Returns NULL_VALUE if null.- Parameters:
row- row indexcol- col index- Returns:
- value stored
-
getRow
public double[] getRow(int row)
Get a row (no null values are considered)- Parameters:
row- row index- Returns:
- array with values stored
-
getColumn
public double[] getColumn(int col)
Get a column (no null values are considered)- Parameters:
col- column index- Returns:
- array with values stored
-
toString
public java.lang.String toString()
To String method- Overrides:
toStringin classjava.lang.Object
-
readXML
public void readXML(java.lang.String file)
Loads a table from a XML file- Parameters:
file- path of the file
-
writeXML
public void writeXML(java.lang.String file)
Writes a table to a XML file- Parameters:
file- path of the file
-
readCSV
public void readCSV(java.lang.String file)
Loads a table from a CSV file- Parameters:
file- path of the file
-
writeCSV
public void writeCSV(java.lang.String file, boolean useComma)Writes a table to a CSV file- Parameters:
file- path of the fileuseComma- true true if "," is used as separator, false if ";" is used instead
-
readTXT
public void readTXT(java.lang.String file)
Loads a table from a TXT file- Parameters:
file- path of the file
-
writeTXT
public void writeTXT(java.lang.String file)
Writes a table to a TXT file- Parameters:
file- path of the file
-
-
DMelt 3.0 © DataMelt by jWork.ORG