public class MathTable extends Object
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)
Constructs an empty table.
|
MathTable(String... headers)
Constructs an empty table by headers.
|
Modifier and Type | Method and Description |
---|---|
void |
addRow(double index,
double[] values)
Adds a row to the table.
|
void |
addRows(double[][] data)
Adds rows by a
double[][] . |
double |
get(double i,
int j)
Gets a particular table entry at [i,j].
|
double |
get(double i,
String header)
Gets a particular table entry at [i, "header"].
|
String[] |
getHeaders()
Gets the column names.
|
double[] |
getIndices()
Gets a copy of the row indices.
|
MathTable.Row |
getRowOnOrAfter(double i)
Gets the row corresponding to a row index.
|
MathTable.Row |
getRowOnOrBefore(double i)
Gets the row corresponding to a row index.
|
Iterator<MathTable.Row> |
getRowsOnOrAfter(double i)
Gets the rows having the row index value equal to or just bigger than
i . |
Iterator<MathTable.Row> |
getRowsOnOrBefore(double i)
Gets the rows having the row index value equal to or just smaller than
i . |
int |
nColumns()
Gets the number of columns in the table.
|
public MathTable(String... headers)
headers
- the column names; they must be uniquepublic MathTable(int nColumns)
nColumns
- the number of columnspublic 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 indexNoSuchElementException
- if i
is smaller than the first row indexpublic MathTable.Row getRowOnOrAfter(double i)
i
- a row indexNoSuchElementException
- if i
is bigger than the last row index valuepublic 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 Row
s at or above the matching rowpublic Iterator<MathTable.Row> getRowsOnOrAfter(double i)
i
.
The returned Iterator
allows iterating the rows starting from the matching row.i
- the row indexIterator
of Row
s 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 1NoSuchElementException
- if rowValue
is outside the table rangepublic double get(double i, 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 nameNoSuchElementException
- if i
is outside the table rangeCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.