QJCC homepage

biz.chitec.quarterback.util
Class MapComparator

java.lang.Object
  extended bybiz.chitec.quarterback.util.MapComparator
All Implemented Interfaces:
java.util.Comparator

public class MapComparator
extends java.lang.Object
implements java.util.Comparator

Comparator class for Maps. Gets array of keys which should be compared. Can get special comparators for each key also.

Version:
$Id: c48b87a4b0245ab6cd55e63e6bc419e1e0a1584a $
Author:
chitec/Dirk Hillbrecht 2002, cantamen/Dirk Hillbrecht 2004. Distributed under the terms of the GNU LGPL.

Field Summary
private  boolean[] ascending
           
private  java.lang.Object[] compkey
           
private  java.util.Comparator[] elementcomparator
           
 
Constructor Summary
MapComparator()
          Create a MapComparator with empty key list.
MapComparator(java.util.List compkeyx)
           
MapComparator(java.lang.Object compkeyx)
          Create a MapComparator with one key, default comparator and ascending sorting order.
MapComparator(java.lang.Object[] compkeyx)
          Create a MapComparator with multiple keys with decreasing relevance, generally ascending order and default comparators.
MapComparator(java.lang.Object[] compkeyx, boolean[] ascendingx)
           
MapComparator(java.lang.Object[] compkeyx, boolean[] ascendingx, java.util.Comparator[] elementcomparatorx)
           
MapComparator(java.lang.Object[] compkeyx, java.util.Comparator[] elementcomparatorx)
           
MapComparator(java.lang.Object compkeyx, boolean ascendingx)
          Create a MapComparator with one key, given sorting order and standard comparator.
MapComparator(java.lang.Object compkeyx, boolean ascendingx, java.util.Comparator elementcomparatorx)
          Create a MapComparator with one key, arbitrary order and special comparator
MapComparator(java.lang.Object compkeyx, java.util.Comparator elementcomparatorx)
          Create a MapComparator with one key, given comparator for the values and ascending sorting order.
 
Method Summary
 int compare(java.lang.Object o1, java.lang.Object o2)
          Compares two maps by the given keys.
 boolean equals(java.lang.Object o)
           
 void setCompareConstraints(java.util.List compkeyx)
           
 void setCompareKey(java.lang.Object compkeyx)
           
 void setCompareKey(java.lang.Object compkeyx, boolean ascendingx)
           
 void setCompareKey(java.lang.Object compkeyx, boolean ascendingx, java.util.Comparator elementcomparatorx)
           
 void setCompareKey(java.lang.Object compkeyx, java.util.Comparator elementcomparatorx)
           
 void setCompareKeys(java.lang.Object[] compkeyx)
           
 void setCompareKeys(java.lang.Object[] compkeyx, boolean[] ascendingx)
           
 void setCompareKeys(java.lang.Object[] compkeyx, boolean[] ascendingx, java.util.Comparator[] elementcomparatorx)
           
 void setCompareKeys(java.lang.Object[] compkeyx, java.util.Comparator[] elementcomparatorx)
           
 void setElementComparator(java.util.Comparator elementcomparatorx)
           
 void setElementComparators(java.util.Comparator[] elementcomparatorx)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compkey

private java.lang.Object[] compkey

ascending

private boolean[] ascending

elementcomparator

private java.util.Comparator[] elementcomparator
Constructor Detail

MapComparator

public MapComparator()
Create a MapComparator with empty key list. To actually use this comparator, call a setCompareKey() method.


MapComparator

public MapComparator(java.lang.Object compkeyx)
Create a MapComparator with one key, default comparator and ascending sorting order.

Parameters:
compkeyx - Key for the values to compare the maps by

MapComparator

public MapComparator(java.lang.Object compkeyx,
                     boolean ascendingx)
Create a MapComparator with one key, given sorting order and standard comparator.

Parameters:
compkeyx - Key for the values to compare the maps by
ascendingx - Flag to indicate ascending (true) or descending (false) sorting order

MapComparator

public MapComparator(java.lang.Object compkeyx,
                     java.util.Comparator elementcomparatorx)
Create a MapComparator with one key, given comparator for the values and ascending sorting order.

Parameters:
compkeyx - Key for the values to compare the maps by
elementcomparatorx - Comparator for the values

MapComparator

public MapComparator(java.lang.Object compkeyx,
                     boolean ascendingx,
                     java.util.Comparator elementcomparatorx)
Create a MapComparator with one key, arbitrary order and special comparator

Parameters:
compkeyx - Key for the values to compare the maps by
ascendingx - Flag to indicate ascending (true) or descending (false) sorting order
elementcomparatorx - Comparator for the values

MapComparator

public MapComparator(java.lang.Object[] compkeyx)
Create a MapComparator with multiple keys with decreasing relevance, generally ascending order and default comparators. The sorting order for the maps is controlled by the values of the entries in the tables for the given keys. If values for the first key are equal, the second key is tested, then the third and so on.

Parameters:
compkeyx - Keys for the values to compare the maps by, each key is evaluated seperately on both maps.

MapComparator

public MapComparator(java.lang.Object[] compkeyx,
                     boolean[] ascendingx)

MapComparator

public MapComparator(java.lang.Object[] compkeyx,
                     java.util.Comparator[] elementcomparatorx)

MapComparator

public MapComparator(java.lang.Object[] compkeyx,
                     boolean[] ascendingx,
                     java.util.Comparator[] elementcomparatorx)

MapComparator

public MapComparator(java.util.List compkeyx)
Method Detail

setCompareKey

public void setCompareKey(java.lang.Object compkeyx,
                          boolean ascendingx,
                          java.util.Comparator elementcomparatorx)

setCompareKey

public void setCompareKey(java.lang.Object compkeyx,
                          boolean ascendingx)

setCompareKey

public void setCompareKey(java.lang.Object compkeyx,
                          java.util.Comparator elementcomparatorx)

setCompareKey

public void setCompareKey(java.lang.Object compkeyx)

setCompareKeys

public void setCompareKeys(java.lang.Object[] compkeyx,
                           boolean[] ascendingx,
                           java.util.Comparator[] elementcomparatorx)

setCompareKeys

public void setCompareKeys(java.lang.Object[] compkeyx,
                           java.util.Comparator[] elementcomparatorx)

setCompareKeys

public void setCompareKeys(java.lang.Object[] compkeyx,
                           boolean[] ascendingx)

setCompareKeys

public void setCompareKeys(java.lang.Object[] compkeyx)

setElementComparator

public void setElementComparator(java.util.Comparator elementcomparatorx)

setElementComparators

public void setElementComparators(java.util.Comparator[] elementcomparatorx)

setCompareConstraints

public void setCompareConstraints(java.util.List compkeyx)

compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Compares two maps by the given keys. The keys to be compared are examined in the given order. For each key, the elements in the maps are taken. Null elements are always smaller than anything else. Next is to look at the special comparators for the key. Then, if the first object implements the Comparable interface, it is compared with the second one. If no decision could be met until here, both objects are converted into Strings and compared on that base.

If the elements for this key are equal upon the first possible mentioned tests, the next key in the list is taken.

Specified by:
compare in interface java.util.Comparator

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Comparator

QJCC homepage