package prefuse.data.util;
import prefuse.data.CascadedTable;
import prefuse.data.Table;
import prefuse.data.column.IntColumn;
import prefuse.util.collections.IntIntSortedMap;
import prefuse.util.collections.IntIntTreeMap;
/**
* RowManager that additionally manages mappings between the managed
* rows and those of a parent table.
*
* @author jeffrey heer
*/
public class FilteredRowManager extends RowManager {
protected IntColumn m_childToParent;
protected IntIntSortedMap m_parentToChild;
/**
* Create a new FilteredRowManager.
* @param table the table to manage
*/
public FilteredRowManager(Table table) {
super(table);
m_childToParent = new IntColumn(table.getRowCount());
m_parentToChild = new IntIntTreeMap(false);
clear();
}
/**
* @see prefuse.data.util.RowManager#clear()
*/
public void clear() {
super.clear();
m_parentToChild.clear();
for ( int i=0; i= m_childToParent.getRowCount() ) {
return -1;
} else {
return m_childToParent.getInt(childRow);
}
}
/**
* Given a row in the parent table, return the corresponding row managed
* by this manager.
* @param parentRow a row in the parent table
* @return the managed row corresponding to the parent row
*/
public int getChildRow(int parentRow) {
int val = m_parentToChild.get(parentRow);
return ( val == Integer.MIN_VALUE ? -1 : val );
}
/**
* Add a mapping between the given managed row and parent row.
* @param childRow a row managed by this manager
* @param parentRow a row in the parent table
*/
public void put(int childRow, int parentRow) {
// ensure capacity of IntColumn
if ( childRow >= m_childToParent.getRowCount() )
m_childToParent.setMaximumRow(childRow+1);
// add mapping
m_childToParent.setInt(parentRow, childRow);
m_parentToChild.put(parentRow, childRow);
}
/**
* Remove a mapping between the given managed row and the corresponding
* parent row.
* @param childRow a row managed by this manager
*/
public void remove(int childRow) {
int parentRow = m_childToParent.getInt(childRow);
m_childToParent.setInt(-1, childRow);
m_parentToChild.remove(parentRow);
}
} // end of class FilteredRowManager