public class Data
class |
Data.Row
Contains one row of values. |
void |
addCol (String hdr)
Modify column headers to add new column. |
void |
addCol (String hdr, Formula<?> calc)
Modify column headers to add new column. |
void |
addCol (String hdr, String value)
Modify column headers to add new column. |
Data.Row |
addRow ()
Create new empty data row. |
Data.Row |
addRow (String... vs)
Create new data row and initialise with values. |
void |
append (Data other)
Append data from another table respecting column names. |
void |
appendMarked (Data other, String markHdr, String mark)
Append and mark data from another table respecting column names. |
void |
clear ()
Remove all data rows. |
int |
colCount ()
Get number of columns. |
Data |
copy ()
|
Data |
copyCols (String[] headers)
|
int |
count ()
Get count of data rows. |
Data |
filter (Filter filter)
|
int |
findCol (String hdr)
Find column index by column name. |
Data.Row |
firstRow ()
Get the first data row or null if the table is empty. |
<T>void |
fold (Formula.Var<T> acc, Formula<T> calc)
|
String |
getHeader (int index)
Get column name by column index. |
Data |
groupBy (String hdr, String[] headers, Fold<?>... folds)
|
int[] |
indexMap (String[] hdrs)
Find column indices by column names. |
Data.Row |
lastRow ()
Get the last data row or null if the table is empty. |
Data |
limit (int count)
|
int[] |
optionalIndexMap (String[] hdrs)
Find column indices by column names without throwing an exception. |
void |
print ()
|
void |
print (PrintStream out, boolean withHeaders)
|
void |
printCols (PrintStream out, boolean withHeaders, String... cols)
|
void |
printCols (String... cols)
|
void |
printHeaders (PrintStream out)
|
void |
printHeaders (PrintStream out, String[] cols)
|
void |
recalc (String hdr, Formula<?> calc)
Recalculate contents of a column using formula. |
void |
renameHeader (String oldName, String newName)
Rename column. |
void |
renameHeaders (String[] headers)
Rename all headers. |
void |
replaceAll (String hdr, String oldValue, String newValue)
Find and replace values in a column. |
Iterable<Data.Row> |
rows ()
Get data rows as unmodifiable iterable. |
void |
sort (boolean asc, Formula<?>... calc)
|
void |
sort (boolean asc, String... hdr)
|
void |
sort (Formula<?>... calc)
|
void |
sort (String... hdr)
|
| Show all inherited methods (11 more) | |
static Data |
range (String hdr, int min, int max)
|
static Data |
range (String hdr, int min, int max, int step)
|
static Data |
range (String hdr, String fmt, double min, double max, double step)
|
static Data |
read (File file)
|
static Data |
read (File file, String[] headers)
|
static Data |
read (File file, String[] headers, String sepRegex)
|
static void |
write (Data data, File file)
|
public Data ( String... headers );
Class constructor.
headersInvalidParameterExceptionpublic void renameHeaders ( String[] headers );
Rename all headers.
headersInvalidParameterExceptionheaders does not match the number of columnsInvalidParameterExceptionpublic void renameHeader ( String oldName, String newName );
Rename column.
oldNamenewNameNoSuchElementExceptionoldNameInvalidParameterExceptionnewName already existspublic String getHeader ( int index );
Get column name by column index.
indexcolumn name
ArrayIndexOutOfBoundsExceptionindex<0 or index>=colCount()public Data.Row addRow ( String... vs );
Create new data row and initialise with values.
Copying is range-safe in case the number of values in vs does not match the number of columns.
vsnew row
public Data.Row firstRow ();
Get the first data row or null if the table is empty.
data row
public Data.Row lastRow ();
Get the last data row or null if the table is empty.
data row
public int findCol ( String hdr );
Find column index by column name. Lookup is relatively fast as it uses a hash map.
hdrcolumn index
NoSuchElementExceptionpublic int[] indexMap ( String[] hdrs );
Find column indices by column names. Throws an exception if any of the names is not found.
hdrsnullarray of column indices in the order of hdrs
NoSuchElementExceptionNullPointerExceptionhdrs is nullpublic int[] optionalIndexMap ( String[] hdrs );
Find column indices by column names without throwing an exception. If a column name does not exist, -1 index is returned.
hdrsnullarray of column indices in the order of hdrs
NullPointerExceptionhdrs is nullpublic void addCol ( String hdr, Formula<?> calc );
Modify column headers to add new column.
Values of the new column can be calculated using calc or initalised to null if formula is not provided.
hdrcalcnullpublic void addCol ( String hdr, String value );
Modify column headers to add new column. Values of the new column are initialised to the given constant.
hdrvaluenullpublic void addCol ( String hdr );
Modify column headers to add new column. Values of the new column are initialised to null.
hdrpublic void recalc ( String hdr, Formula<?> calc );
Recalculate contents of a column using formula. If formula is not provided, column values are set to null.
hdrcalcnullpublic void replaceAll ( String hdr, String oldValue, String newValue );
Find and replace values in a column. Uses case-sensitive string comparison for non-null values.
hdroldValuenullnewValuenullpublic void append ( Data other );
Append data from another table respecting column names.
otherNullPointerExceptionnullpublic void appendMarked ( Data other, String markHdr, String mark );
Append and mark data from another table respecting column names. Appended rows are marked with a specified value.
Typical use for this method is to keep track of data sources when combining data from multiple tables. For example:
Data data = Data.read(new File("data1.csv"));
data.addCol("source", "data1");
data.appendMarked(Data.read(new File("data2.csv")), "source", "data2");
data.appendMarked(Data.read(new File("data3.csv")), "source", "data3");othermarkHdrmarknullNullPointerExceptionnullNoSuchElementExceptionmarkHdr does not exist
Data table.
Values are stored as nullable strings in rows and columns. Columns can be accessed by name (header).