📄 table.java
字号:
*/
public final boolean canSetString(String field) {
Column col = getColumn(field);
return ( col==null ? false : col.canSetString() );
}
/**
* Get the data value at the given row and field as a
* <code>String</code>.
* @param row the table row to retrieve
* @param field the data field to retrieve
* @see #canGetString(String)
*/
public final String getString(int row, String field) {
int col = getColumnNumber(field);
row = getColumnRow(row, col);
return getColumn(col).getString(row);
}
/**
* Set the data value of the given row and field as a
* <code>String</code>.
* @param row the table row to set
* @param field the data field to set
* @param val the value to set
* @see #canSetString(String)
*/
public final void setString(int row, String field, String val) {
int col = getColumnNumber(field);
row = getColumnRow(row, col);
getColumn(col).setString(val, row);
}
/**
* Get the data value at the given row and field as a
* <code>String</code>.
* @param row the table row to retrieve
* @param col the column number of the data field to retrieve
* @see #canGetString(String)
*/
public final String getString(int row, int col) {
row = getColumnRow(row, col);
return getColumn(col).getString(row);
}
/**
* Set the data value of the given row and field as a
* <code>String</code>.
* @param row the table row to set
* @param col the column number of the data field to set
* @param val the value to set
* @see #canSetString(String)
*/
public final void setString(int row, int col, String val) {
row = getColumnRow(row, col);
getColumn(col).setString(val, row);
}
// --------------------------------------------------------------
/**
* Check if the given data field can return primitive <code>Date</code>
* values.
* @param field the data field to check
* @return true if the data field can return primitive <code>Date</code>
* values, false otherwise. If true, the {@link #getDate(int, String)}
* method can be used safely.
*/
public final boolean canGetDate(String field) {
Column col = getColumn(field);
return ( col==null ? false : col.canGetDate() );
}
/**
* Check if the <code>setDate</code> method can safely be used for the
* given data field.
* @param field the data field to check
* @return true if the {@link #setDate(int, String, Date)} method can
* safely be used for the given field, false otherwise.
*/
public final boolean canSetDate(String field) {
Column col = getColumn(field);
return ( col==null ? false : col.canSetDate() );
}
/**
* Get the data value at the given row and field as a
* <code>Date</code>.
* @param row the table row to retrieve
* @param field the data field to retrieve
* @see #canGetDate(String)
*/
public final Date getDate(int row, String field) {
int col = getColumnNumber(field);
row = getColumnRow(row, col);
return getColumn(col).getDate(row);
}
/**
* Set the data value of the given row and field as a
* <code>Date</code>.
* @param row the table row to set
* @param field the data field to set
* @param val the value to set
* @see #canSetDate(String)
*/
public final void setDate(int row, String field, Date val) {
int col = getColumnNumber(field);
row = getColumnRow(row, col);
getColumn(col).setDate(val, row);
}
/**
* Get the data value at the given row and field as a
* <code>Date</code>.
* @param row the table row to retrieve
* @param col the column number of the data field to retrieve
* @see #canGetDate(String)
*/
public final Date getDate(int row, int col) {
row = getColumnRow(row, col);
return getColumn(col).getDate(row);
}
/**
* Set the data value of the given row and field as a
* <code>Date</code>.
* @param row the table row to set
* @param col the column number of the data field to set
* @param val the value to set
* @see #canSetDate(String)
*/
public final void setDate(int row, int col, Date val) {
row = getColumnRow(row, col);
getColumn(col).setDate(val, row);
}
// ------------------------------------------------------------------------
// Query Operations
/**
* Query this table for a filtered, sorted subset of this table. This
* operation creates an entirely new table independent of this table.
* If a filtered view of this same table is preferred, use the
* {@link CascadedTable} class.
* @param filter the predicate filter determining which rows to include
* in the new table. If this value is null, all rows will be included.
* @param sort the sorting criteria determining the order in which
* rows are added to the new table. If this value is null, the rows
* will not be sorted.
* @return a new table meeting the query specification
*/
public Table select(Predicate filter, Sort sort) {
Table t = getSchema().instantiate();
Iterator tuples = tuples(filter, sort);
while ( tuples.hasNext() ) {
t.addTuple((Tuple)tuples.next());
}
return t;
}
/**
* Removes all table rows that meet the input predicate filter.
* @param filter a predicate specifying which rows to remove from
* the table.
*/
public void remove(Predicate filter) {
for ( IntIterator ii = rows(filter); ii.hasNext(); )
removeRow(ii.nextInt());
}
// ------------------------------------------------------------------------
// Iterators
/**
* Return a TableIterator over the rows of this table.
* @return a TableIterator over this table
*/
public TableIterator iterator() {
return iterator(rows());
}
/**
* Return a TableIterator over the given rows of this table.
* @param rows an iterator over the table rows to visit
* @return a TableIterator over this table
*/
public TableIterator iterator(IntIterator rows) {
return new TableIterator(this, rows);
}
/**
* Get an iterator over the tuples in this table.
* @return an iterator over the table tuples
* @see prefuse.data.tuple.TupleSet#tuples()
*/
public Iterator tuples() {
return m_tuples.iterator(rows());
}
/**
* Get an iterator over the tuples in this table in reverse order.
* @return an iterator over the table tuples in reverse order
*/
public Iterator tuplesReversed() {
return m_tuples.iterator(rows(true));
}
/**
* Get an iterator over the tuples for the given rows in this table.
* @param rows an iterator over the table rows to visit
* @return an iterator over the selected table tuples
*/
public Iterator tuples(IntIterator rows) {
return m_tuples.iterator(rows);
}
/**
* Get an interator over the row numbers of this table.
* @return an iterator over the rows of this table
*/
public IntIterator rows() {
return m_rows.rows();
}
/**
* Get a filtered iterator over the row numbers of this table, returning
* only the rows whose tuples match the given filter predicate.
* @param filter the filter predicate to apply
* @return a filtered iterator over the rows of this table
*/
public IntIterator rows(Predicate filter) {
return FilterIteratorFactory.rows(this, filter);
}
/**
* Get an interator over the row numbers of this table.
* @param reverse true to iterate in rever order, false for normal order
* @return an iterator over the rows of this table
*/
public IntIterator rows(boolean reverse) {
return m_rows.rows(reverse);
}
/**
* Get an iterator over the rows of this table, sorted by the given data
* field. This method will create an index over the field if one does
* not yet exist.
* @param field the data field to sort by
* @param ascend true if the iteration should proceed in an ascending
* (lowest to highest) sort order, false for a descending order
* @return the sorted iterator over rows of this table
*/
public IntIterator rowsSortedBy(String field, boolean ascend) {
Class type = getColumnType(field);
Index index = getIndex(field, type, true);
int t = ascend ? Index.TYPE_ASCENDING : Index.TYPE_DESCENDING;
return index.allRows(t);
}
/**
* Return an iterator over a range of rwos in this table, determined
* by a bounded range for a given data field. A new index over the
* data field will be created if it doesn't already exist.
* @param field the data field for determining the bounded range
* @param lo the minimum range value
* @param hi the maximum range value
* @param indexType indicate the sort order and inclusivity/exclusivity
* of the range bounds, using the constants of the
* {@link prefuse.data.util.Index} class.
* @return an iterator over a range of table rows, determined by a
* sorted bounded range of a data field
*/
public IntIterator rangeSortedBy(String field, int lo, int hi, int indexType) {
Index index = getIndex(field, int.class, true);
return index.rows(lo, hi, indexType);
}
/**
* Return an iterator over a range of rwos in this table, determined
* by a bounded range for a given data field. A new index over the
* data field will be created if it doesn't already exist.
* @param field the data field for determining the bounded range
* @param lo the minimum range value
* @param hi the maximum range value
* @param indexType indicate the sort order and inclusivity/exclusivity
* of the range bounds, using the constants of the
* {@link prefuse.data.util.Index} class.
* @return an iterator over a range of table rows, determined by a
* sorted bounded range of a data field
*/
public IntIterator rangeSortedBy(String field, long lo, long hi, int indexType) {
Index index = getIndex(field, long.class, true);
return index.rows(lo, hi, indexType);
}
/**
* Return an iterator over a range of rwos in this table, determined
* by a bounded range for a given data field. A new index over the
* data field will be created if it doesn't already exist.
* @param field the data field for determining the bounded range
* @param lo the minimum range value
* @param hi the maximum range value
* @param indexType indicate the sort order and inclusivity/exclusivity
* of the range bounds, using the constants of the
* {@link prefuse.data.util.Index} class.
* @return an iterator over a range of table rows, determined by a
* sorted bounded range of a data field
*/
public IntIterator rangeSortedBy(String field, float lo, float hi, int indexType) {
Index index = getIndex(field, float.class, true);
return index.rows(lo, hi, indexType);
}
/**
* Return an iterator over a range of rwos in this table, determined
* by a bounded range for a given data field. A new index over the
* data field will be created if it doesn't already exist.
* @param field the data field for determining the bounded range
* @param lo the minimum range value
* @param hi the maximum range value
* @param indexType indicate the sort order and inclusivity/exclusivity
* of the range bounds, using the constants of the
* {@link prefuse.data.util.Index} class.
* @return an iterator over a range of table rows, determined by a
* sorted bounded range of a data field
*/
public IntIterator rangeSortedBy(String field, double lo, double hi, int indexType) {
Index index = getIndex(field, double.class, true);
return index.rows(lo, hi, indexType);
}
/**
* Return an iterator over a range of rwos in this table, determined
* by a bounded range for a given data field. A new index over the
* data field will be created if it doesn't already exist.
* @param field the data field for determining the bounded range
* @param lo the minimum range value
* @param hi the maximum range value
* @param indexType indicate the sort order and inclusivity/exclusivity
* of the range bounds, using the constants of the
* {@link prefuse.data.util.Index} class.
* @return an iterator over a range of table rows, determined by a
* sorted bounded range of a data field
*/
public IntIterator rangeSortedBy(String field, Object lo, Object hi, int indexType) {
Class type = TypeLib.getSharedType
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -