com.limegroup.gnutella.gui.tables
Class HashBasedDataLineModel

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended bycom.limegroup.gnutella.gui.tables.BasicDataLineModel
          extended bycom.limegroup.gnutella.gui.tables.HashBasedDataLineModel
All Implemented Interfaces:
java.util.Comparator, DataLineModel, java.io.Serializable, javax.swing.table.TableModel

public class HashBasedDataLineModel
extends BasicDataLineModel

This class extends the BasicDataLineModel by storing the 'initializing' object in a HashMap. Tables which need quick access to rows based on the initializing object should use this as the underlying TableModel.

See Also:
Serialized Form

Field Summary
protected  java.util.HashMap _indexes
          HashMap for quick access to indexes.
 
Fields inherited from class com.limegroup.gnutella.gui.tables.BasicDataLineModel
_isSorted
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
HashBasedDataLineModel(java.lang.Class dataLineClass)
          Constructor -- this HashBasedDataLineModel supports the the single param constructor of BasicDataLineModel.
 
Method Summary
 int add(DataLine dl, int row)
          Override of the add function so we can maintain a HashMap for quick access to the row an object is in.
 void clear()
          Overrides the default clear to erase the indexes HashMap.
 boolean contains(java.lang.Object o)
          Overrides the default contains to use the HashMap instead of a linear search.
protected  int forceAdd(DataLine dl, int row)
          Utility function that immediately calls super.add(dl, row) without checking if it exists.
 int getRow(java.lang.Object o)
          Overrides the default getRow to look in the HashMap instead of a linear search.
 void initializeObjectChanged(java.lang.Object old, java.lang.Object now)
          Notifies the model that the initialize object of a line has changed.
 void remapIndexes(int start)
          Remaps the indexes, starting at 'start' and going to the end of the list.
 void remove(int row)
          Overrides the default remove to remove the index from the hashmap.
 void resort()
          Overrides the default sort to maintain the indexes HashMap, according to the current sort column and order.
 
Methods inherited from class com.limegroup.gnutella.gui.tables.BasicDataLineModel
add, add, add, addSorted, addSorted, compare, contains, createDataLine, get, get, get, getColumnClass, getColumnCount, getColumnId, getColumnName, getNewDataLine, getRow, getRow, getRowCount, getSortColumn, getSortedPosition, getTableColumn, getToolTipArray, getValueAt, isSortAscending, isSorted, needsResort, refresh, remove, remove, setValueAt, sort, update
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, isCellEditable, removeTableModelListener
 

Field Detail

_indexes

protected java.util.HashMap _indexes
HashMap for quick access to indexes.

Constructor Detail

HashBasedDataLineModel

public HashBasedDataLineModel(java.lang.Class dataLineClass)
Constructor -- this HashBasedDataLineModel supports the the single param constructor of BasicDataLineModel.

Method Detail

forceAdd

protected int forceAdd(DataLine dl,
                       int row)
Utility function that immediately calls super.add(dl, row) without checking if it exists. Useful for extending classes that override add(DataLine, row).


add

public int add(DataLine dl,
               int row)
Override of the add function so we can maintain a HashMap for quick access to the row an object is in.

Specified by:
add in interface DataLineModel
Overrides:
add in class BasicDataLineModel

remove

public void remove(int row)
Overrides the default remove to remove the index from the hashmap.

Specified by:
remove in interface DataLineModel
Overrides:
remove in class BasicDataLineModel
Parameters:
row - the index of the row to remove.

getRow

public int getRow(java.lang.Object o)
Overrides the default getRow to look in the HashMap instead of a linear search.

Specified by:
getRow in interface DataLineModel
Overrides:
getRow in class BasicDataLineModel
Parameters:
o - the object whose index we want.
Returns:
the index of the DataLine initialized by object o.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if no dataline was initialized by o.

resort

public void resort()
Overrides the default sort to maintain the indexes HashMap, according to the current sort column and order.

Specified by:
resort in interface DataLineModel
Overrides:
resort in class BasicDataLineModel

contains

public boolean contains(java.lang.Object o)
Overrides the default contains to use the HashMap instead of a linear search.

Specified by:
contains in interface DataLineModel
Overrides:
contains in class BasicDataLineModel
Parameters:
o - The object which initialized a DataLine.
Returns:
true if the List contains a DataLine that was initialized by Object o.

clear

public void clear()
Overrides the default clear to erase the indexes HashMap.

Specified by:
clear in interface DataLineModel
Overrides:
clear in class BasicDataLineModel

remapIndexes

public void remapIndexes(int start)
Remaps the indexes, starting at 'start' and going to the end of the list. This is needed for when rows are added to the middle of the list to maintain the correct rows per objects.


initializeObjectChanged

public void initializeObjectChanged(java.lang.Object old,
                                    java.lang.Object now)
Notifies the model that the initialize object of a line has changed.