Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.treetable
Class DefaultTreeTableComparator

java.lang.Object
  extended by com.sciapp.treetable.DefaultTreeTableComparator
All Implemented Interfaces:
TreeTableComparator, Serializable, Comparator

public class DefaultTreeTableComparator
extends Object
implements TreeTableComparator, Serializable

DefaultTreeTableComparator compares row data based on a single column. This column is passed as an argument in the constructor and can also be changed with the setColumn method.

See Also:
Serialized Form

Field Summary
protected  boolean alwaysCreateGroup
          a boolean which is true if group nodes are always to be created.
protected  int column
          the column to use when comparing rows
protected  DynamicTreeTableModel model
          the associated dynamic treetablemodel
 
Constructor Summary
DefaultTreeTableComparator(DynamicTreeTableModel model, int column)
          Constructs a DefaultTreeTableComparator object with column as the column to use when comparing rows and the request to always create group nodes.
DefaultTreeTableComparator(DynamicTreeTableModel model, int column, boolean alwaysCreateGroup)
          Constructs a DefaultTreeTableComparator object with column as the column to use when comparing rows.
 
Method Summary
 int compare(Object o1, Object o2)
          Compares its two arguments for order.
 boolean getAlwaysCreateGroup()
          Returns true if a group node should be used if there is only one child at the this comparator's tree level.
 int getColumn()
          Returns the column to use when comparing rows.
 DynamicTreeTableModel getModel()
          Returns the associated dynamic treetable model instance.
 boolean isGroupedByColumn(int column)
          Returns true if column was used by this comparator in order to group the rows of a TreeTable component.
 void setAlwaysCreateGroup(boolean alwaysCreateGroup)
          Determines whether a group node should be used if there is only one child at the this comparator's tree level.
 void setColumn(int column)
          Sets the column to use when comparing rows.
 void setModel(DynamicTreeTableModel model)
          Sets model as the DynamicTreeTableModel of this object.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

column

protected int column
the column to use when comparing rows


model

protected transient DynamicTreeTableModel model
the associated dynamic treetablemodel


alwaysCreateGroup

protected boolean alwaysCreateGroup
a boolean which is true if group nodes are always to be created.

Constructor Detail

DefaultTreeTableComparator

public DefaultTreeTableComparator(DynamicTreeTableModel model,
                                  int column)
Constructs a DefaultTreeTableComparator object with column as the column to use when comparing rows and the request to always create group nodes.


DefaultTreeTableComparator

public DefaultTreeTableComparator(DynamicTreeTableModel model,
                                  int column,
                                  boolean alwaysCreateGroup)
Constructs a DefaultTreeTableComparator object with column as the column to use when comparing rows. If alwaysCreateGroup is true, the comparator requests that group nodes should always be created.

Method Detail

compare

public int compare(Object o1,
                   Object o2)
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementer must ensure that compare(x, y)==0 implies that sgn(compare(x, z))==sgn(compare(y, z)) for all z.

It is generally the case, but not strictly required that (compare(x, y)==0) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact. The recommended language is "Note: this comparator imposes orderings that are inconsistent with equals."

Specified by:
compare in interface Comparator
Parameters:
o1 - the first object to be compared.
o2 - the second object to be compared.
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

getAlwaysCreateGroup

public boolean getAlwaysCreateGroup()
Returns true if a group node should be used if there is only one child at the this comparator's tree level. This method is used by ComparableTreeTableModel when a new node is added to the model.

Specified by:
getAlwaysCreateGroup in interface TreeTableComparator
Returns:
true if a group node should always be created, false otherwise.

getColumn

public int getColumn()
Returns the column to use when comparing rows.

Returns:
the column

getModel

public DynamicTreeTableModel getModel()
Returns the associated dynamic treetable model instance.

Returns:
the associated dynamic treetable model

isGroupedByColumn

public boolean isGroupedByColumn(int column)
Returns true if column was used by this comparator in order to group the rows of a TreeTable component.

Specified by:
isGroupedByColumn in interface TreeTableComparator
Parameters:
column - the index of the column
Returns:
true if the column was used in grouping, false otherwise

setAlwaysCreateGroup

public void setAlwaysCreateGroup(boolean alwaysCreateGroup)
Determines whether a group node should be used if there is only one child at the this comparator's tree level. This method is used by DynamicTreeTableModel when a new node is added to the model.

Parameters:
alwaysCreateGroup - true if a group node should always be created, false otherwise.

setColumn

public void setColumn(int column)
Sets the column to use when comparing rows.

Parameters:
column - the column

setModel

public void setModel(DynamicTreeTableModel model)
Sets model as the DynamicTreeTableModel of this object.

Parameters:
model - the dynamic treetablemodel to assign

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString in class Object
Returns:
a string representation of the object.

Copyright © 2005 Scientific Applications. All Rights Reserved.