Beispiel #1
0
  /**
   * Create a new TreeIndex.
   *
   * @param t the ITable containing the data column to index
   * @param rows the RowManager of the ITable
   * @param col the Column instance to index
   * @param cmp the Comparator to use to sort data values
   * @throws IncompatibleComparatorException if the comparator is not compatible with the column's
   *     data type
   */
  public TreeIndex(ITable t, RowManager rows, Column col, Comparator cmp)
      throws IncompatibleComparatorException {
    m_table = t;
    m_rows = rows;
    m_col = col;

    m_index = SortedMapFactory.getMap(col.getColumnType(), cmp, false);
    index();

    m_col.addColumnListener(this);
    m_table.addTableListener(this);
  }
Beispiel #2
0
  /** @see prefuse.data.util.Index#index() */
  public void index() {
    m_index.clear();

    // iterate over all valid values, adding them to the index
    int idx = getColumnIndex();
    m_colidx = idx;
    IntIterator rows = m_rows.rows();

    if (m_index instanceof IntIntSortedMap) {
      IntIntSortedMap map = (IntIntSortedMap) m_index;
      while (rows.hasNext()) {
        int r = rows.nextInt();
        map.put(m_col.getInt(m_table.getColumnRow(r, idx)), r);
      }
    } else if (m_index instanceof LongIntSortedMap) {
      LongIntSortedMap map = (LongIntSortedMap) m_index;
      while (rows.hasNext()) {
        int r = rows.nextInt();
        map.put(m_col.getLong(m_table.getColumnRow(r, idx)), r);
      }
    } else if (m_index instanceof FloatIntSortedMap) {
      FloatIntSortedMap map = (FloatIntSortedMap) m_index;
      while (rows.hasNext()) {
        int r = rows.nextInt();
        map.put(m_col.getFloat(m_table.getColumnRow(r, idx)), r);
      }
    } else if (m_index instanceof DoubleIntSortedMap) {
      DoubleIntSortedMap map = (DoubleIntSortedMap) m_index;
      while (rows.hasNext()) {
        int r = rows.nextInt();
        map.put(m_col.getDouble(m_table.getColumnRow(r, idx)), r);
      }
    } else if (m_index instanceof BooleanIntSortedMap) {
      BooleanIntSortedMap map = (BooleanIntSortedMap) m_index;
      while (rows.hasNext()) {
        int r = rows.nextInt();
        map.put(m_col.getBoolean(m_table.getColumnRow(r, idx)), r);
      }
    } else if (m_index instanceof ObjectIntSortedMap) {
      ObjectIntSortedMap map = (ObjectIntSortedMap) m_index;
      while (rows.hasNext()) {
        int r = rows.nextInt();
        map.put(m_col.get(m_table.getColumnRow(r, idx)), r);
      }
    } else {
      throw new IllegalStateException();
    }

    m_reindex = false;
  }
Beispiel #3
0
 private int getColumnIndex() {
   if (!(m_table.getColumn(m_colidx) == m_col)) {
     m_colidx = m_table.getColumnNumber(m_col);
   }
   return m_colidx;
 }
Beispiel #4
0
 /** @see prefuse.data.util.Index#dispose() */
 public void dispose() {
   m_col.removeColumnListener(this);
   m_table.removeTableListener(this);
 }