ilog.cpl.util
Class IlpAttributeComparator

java.lang.Object
  extended by ilog.cpl.util.IlpAbstractComparator
      extended by ilog.cpl.util.IlpAttributeComparator
All Implemented Interfaces:
IlpMutableComparator, Comparator
Direct Known Subclasses:
IlpTableAttributeComparator

public class IlpAttributeComparator
extends IlpAbstractComparator

This comparator must have an attribute to base the comparison on, otherwise it will not provide an order and will not be a real comparator.

Since:
JTGO 3.0

Constructor Summary
IlpAttributeComparator(IlpAttribute attribute, boolean direction)
          Creates a new comparator instance based on the given business attribute.
 
Method Summary
 int compare(Object o1, Object o2)
          Compares the given objects according to the attributes defined in the sorting criteria and the directions.
protected  int compareObjectsByAttribute(Object ro1, Object ro2, IlpAttribute attribute)
          Compares the given objects according to the value of the attribute.
 int getDirectionAndOrder(IlpAttribute attribute)
          Gets the sorting direction and sorting order of the specified attribute.
 int getSortedAttributesCount()
          Returns the number of attributes used to sort the list.
 void removeSortedAttribute(IlpAttribute attribute)
          Removes an attribute from the sorted attributes in the list.
 void setDirectionAndOrder(IlpAttribute attribute, int order, boolean direction)
          Sets the sorting direction and sorting order of the specified attribute.
 
Methods inherited from class ilog.cpl.util.IlpAbstractComparator
addChangeListener, fireStateChanged, removeChangeListener
 
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
 

Constructor Detail

IlpAttributeComparator

public IlpAttributeComparator(IlpAttribute attribute,
                              boolean direction)
Creates a new comparator instance based on the given business attribute.

Parameters:
attribute - Business attribute used to sort the objects
direction - The sorting direction, true meaning ascending or false meaning descending
Throws:
IllegalArgumentException - if the given attribute equals null.
Method Detail

getSortedAttributesCount

public int getSortedAttributesCount()
Returns the number of attributes used to sort the list.

Returns:
The number of attributes used to sort the list.

removeSortedAttribute

public void removeSortedAttribute(IlpAttribute attribute)
Removes an attribute from the sorted attributes in the list.

Parameters:
attribute - The attribute to remove.
Throws:
UnsupportedOperationException - if the attribute to remove is the last one.

getDirectionAndOrder

public int getDirectionAndOrder(IlpAttribute attribute)
Gets the sorting direction and sorting order of the specified attribute.

Parameters:
attribute - The attribute.
Returns:
The direction (ascending or descending) and order of the sorting:
  • 0 - The attribute is not used to sort the list.
  • A positive number - The attribute is sorted in ascending order.
  • A negative number - The attribute is sorted in descending order.
In the last two cases, the absolute value returned corresponds to the position of the attribute in the sorting operation.

setDirectionAndOrder

public void setDirectionAndOrder(IlpAttribute attribute,
                                 int order,
                                 boolean direction)
Sets the sorting direction and sorting order of the specified attribute.

Parameters:
attribute - The attribute to sort.
order - The sorting order of the attribute. If order is less than or equals to 0 or equals to 1, the attribute is put in the first position. If order is greater than the current number of attributes used for the sort, the column is put in the last position. If the attribute is already sorted, its index or sorting direction is changed.
direction - The sorting direction: true meaning ascending, or false meaning descending.
Throws:
IllegalArgumentException - if the given attribute equals null.

compare

public int compare(Object o1,
                   Object o2)
Compares the given objects according to the attributes defined in the sorting criteria and the directions.

Returns:
A value 0 if both objects are equivalent. A value less than 0 if the first object is meant to be before the second object. A value greater than 0 if the first object is meant to be after the second object.
See Also:
setDirectionAndOrder(IlpAttribute, int, boolean)

compareObjectsByAttribute

protected int compareObjectsByAttribute(Object ro1,
                                        Object ro2,
                                        IlpAttribute attribute)
Compares the given objects according to the value of the attribute. This method assumes the given objects are IlpAttributeValueHolder instances.

Returns:
A value 0 if both objects are equivalent. A value less than 0 if the first object is meant to be before the second object. A value greater than 0 if the first object is meant to be after the second object.
See Also:
setDirectionAndOrder(IlpAttribute, int, boolean)


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.