public class MathTable
extends java.lang.Object
implements java.io.Serializable
| Modifier and Type | Class and Description |
|---|---|
class |
MathTable.Row
A row is indexed by a number and contains multiple values.
|
| Constructor and Description |
|---|
MathTable(int nColumns)
Construct an empty table.
|
MathTable(java.lang.String... headers)
Construct an empty table by headers.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRow(double index,
double[] values)
Add a row to the table.
|
void |
addRows(double[][] data)
Add rows by a
double[][]. |
double |
get(double i,
int j)
Get a particular table entry at [i,j].
|
double |
get(double i,
java.lang.String header)
Get a particular table entry at [i, "header"].
|
java.lang.String[] |
getHeaders()
Get the column names.
|
double[] |
getIndices()
Get a copy of the row indices.
|
MathTable.Row |
getRowOnOrAfter(double i)
Get the row corresponding to a row index.
|
MathTable.Row |
getRowOnOrBefore(double i)
Get the row corresponding to a row index.
|
java.util.Iterator<MathTable.Row> |
getRowsOnOrAfter(double i)
Get the rows having the row index value equal to or just bigger than
i. |
java.util.Iterator<MathTable.Row> |
getRowsOnOrBefore(double i)
Get the rows having the row index value equal to or just smaller than
i. |
int |
nColumns()
Get the number of columns in the table.
|
public MathTable(java.lang.String... headers)
headers - the column names; they must be uniquepublic MathTable(int nColumns)
nColumns - the number of columnspublic java.lang.String[] getHeaders()
public int nColumns()
public void addRow(double index,
double[] values)
index - the row indexvalues - the row valuespublic void addRows(double[][] data)
double[][].
The first number in each row/double[] is the row index.
For example,
new double[][]{
{1.0, 1.1, 1.2, 1.3},
{2.0, 2.1, 2.2, 2.3},
{3.0, 3.1, 3.2, 3.3},
{4.0, 4.1, 4.2, 4.3}
};
represents
1.0: {1.1, 1.2, 1.3}//row 1
2.0: {2.1, 2.2, 2.3}//row 2
3.0: {3.1, 3.2, 3.3}//row 3
4.0: {4.1, 4.2, 4.3}//row 4
data - a double[][] of table entries.public double[] getIndices()
public MathTable.Row getRowOnOrBefore(double i)
i - a row indexjava.util.NoSuchElementException - if i is smaller than the first row indexpublic MathTable.Row getRowOnOrAfter(double i)
i - a row indexjava.util.NoSuchElementException - if i is bigger than the last row index valuepublic java.util.Iterator<MathTable.Row> getRowsOnOrBefore(double i)
i.
The returned Iterator allows iterating the rows in reversed order starting from the matching row.i - the row indexIterator of Rows at or above the matching rowpublic java.util.Iterator<MathTable.Row> getRowsOnOrAfter(double i)
i.
The returned Iterator allows iterating the rows starting from the matching row.i - the row indexIterator of Rows at or below the matching rowpublic double get(double i,
int j)
i, by default, we use linear interpolation between the row above and below.
If i is smaller than the first row index, we return the value at [1,j].
A subclass may override this behavior to customize interpolation.i - a row indexj - a column index, counting from 1java.util.NoSuchElementException - if rowValue is outside the table rangepublic double get(double i,
java.lang.String header)
i, by default, we use linear interpolation between the row above and below.
If i is smaller than the first row index, we return the value at [1,"header"].
A subclass may override this behavior to customize interpolation.i - a row value indexheader - the column namejava.util.NoSuchElementException - if i is outside the table range