/** * Add a new row to management. The lowest valued available row will be used. * * @return the row index of the newly added row */ public int addRow() { int r; if (m_openRows == null || m_openRows.isEmpty()) { r = (m_firstId == 0 ? ++m_curId : --m_firstId); } else { int key = m_openRows.firstKey(); r = m_openRows.remove(key); } return r; }
/** @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; }
/** @see prefuse.data.util.Index#rows(int, int, int) */ public IntIterator rows(int lo, int hi, int type) { if (!(m_index instanceof IntIntSortedMap)) throw new IllegalStateException(); boolean reverse = (type & Index.TYPE_DESCENDING) > 0; boolean linc = (type & Index.TYPE_LEFT_INCLUSIVE) > 0; boolean hinc = (type & Index.TYPE_RIGHT_INCLUSIVE) > 0; IntIntSortedMap index = (IntIntSortedMap) m_index; if (reverse) { return index.valueRangeIterator(hi, hinc, lo, linc); } else { return index.valueRangeIterator(lo, linc, hi, hinc); } }
/** * Release a row and mark it as free. * * @param row the row index of the released row * @return true if the row was successfully released, false if it was already free or if the input * is not a valid row index */ public boolean releaseRow(int row) { if (row < 0) { return false; } else if (m_openRows != null && m_openRows.containsKey(row)) { return false; } else if (row == m_curId) { --m_curId; } else if (row == m_firstId) { ++m_firstId; } else { if (m_openRows == null) m_openRows = new IntIntTreeMap(false); m_openRows.put(row, row); } return true; }
private void rowChanged(int row, boolean insert) { // make sure we access the right column value int crow = m_rows.getColumnRow(row, getColumnIndex()); if (m_index instanceof IntIntSortedMap) { IntIntSortedMap map = (IntIntSortedMap) m_index; int key = m_col.getInt(row); if (insert) map.put(key, row); else map.remove(key, row); } else if (m_index instanceof LongIntSortedMap) { LongIntSortedMap map = (LongIntSortedMap) m_index; long key = m_col.getLong(crow); if (insert) map.put(key, row); else map.remove(key, row); } else if (m_index instanceof FloatIntSortedMap) { FloatIntSortedMap map = (FloatIntSortedMap) m_index; float key = m_col.getFloat(crow); if (insert) map.put(key, row); else map.remove(key, row); } else if (m_index instanceof DoubleIntSortedMap) { DoubleIntSortedMap map = (DoubleIntSortedMap) m_index; double key = m_col.getDouble(crow); if (insert) map.put(key, row); else map.remove(key, row); } else if (m_index instanceof BooleanIntSortedMap) { BooleanIntSortedMap map = (BooleanIntSortedMap) m_index; boolean key = m_col.getBoolean(crow); if (insert) map.put(key, row); else map.remove(key, row); } else if (m_index instanceof ObjectIntSortedMap) { ObjectIntSortedMap map = (ObjectIntSortedMap) m_index; Object key = m_col.get(crow); if (insert) map.put(key, row); else map.remove(key, row); } else { throw new IllegalStateException(); } }
/** @see prefuse.data.util.Index#get(int) */ public int get(int x) { IntIntSortedMap index = (IntIntSortedMap) m_index; return index.get(x); }
/** @see prefuse.data.event.ColumnListener#columnChanged(prefuse.data.column.Column, int, int) */ public void columnChanged(Column src, int idx, int prev) { int row = m_rows.getTableRow(idx, getColumnIndex()); if (row < 0) return; // invalid row value ((IntIntSortedMap) m_index).remove(prev, row); ((IntIntSortedMap) m_index).put(src.getInt(idx), row); }
/** * Indicates if a given row value is a valid, occupied row of the table. * * @param row the row index to check * @return true if the row is valid and in use by the Table, false if it is an illegal value or is * currently free */ public boolean isValidRow(int row) { return (row >= m_firstId && row <= m_curId && (m_openRows == null || !m_openRows.containsKey(row))); }
/** * Get the total number of occupied rows * * @return the number of rows being used by the table */ public int getRowCount() { return 1 + m_curId - m_firstId - (m_openRows == null ? 0 : m_openRows.size()); }