com.jamonapi.utils
Class JAMonArrayComparator

java.lang.Object
  extended by com.jamonapi.utils.JAMonArrayComparator
All Implemented Interfaces:
java.util.Comparator

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

This class allows you to compare Object[] arrays by multiple columns. It can also compare any Object that implements the ToArray interface. Each column will use the underlying Compareable interface in natural or reverse order depending on how it is added, or will use the passed in Comparator.

Note I took this code from fdsapi.com, and would like to eventually merge these 2 projects, so this class will eventually be replaced by the one in FDS.


Constructor Summary
JAMonArrayComparator()
           
JAMonArrayComparator(int sortCol, boolean naturalOrder)
          Sort/compare the passed in col number starting at 0 in natural (true) or reverse (false) order based on the columns Compareable interface being called.
 
Method Summary
 void addCompareCol(int sortCol)
          Compare the passed in col in natural order
 void addCompareCol(int sortCol, boolean naturalOrder)
          Compare the passed in col in natural or reverse order
 void addCompareCol(int sortCol, java.util.Comparator comparator)
          Compare the passed in col based on the passed in Comparator
 int compare(java.lang.Object o1, java.lang.Object o2)
          Method used by the comparator interface.
 
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

JAMonArrayComparator

public JAMonArrayComparator()

JAMonArrayComparator

public JAMonArrayComparator(int sortCol,
                            boolean naturalOrder)
Sort/compare the passed in col number starting at 0 in natural (true) or reverse (false) order based on the columns Compareable interface being called.

Parameters:
sortCol -
naturalOrder -
Method Detail

addCompareCol

public void addCompareCol(int sortCol)
Compare the passed in col in natural order


addCompareCol

public void addCompareCol(int sortCol,
                          boolean naturalOrder)
Compare the passed in col in natural or reverse order


addCompareCol

public void addCompareCol(int sortCol,
                          java.util.Comparator comparator)
Compare the passed in col based on the passed in Comparator


compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Method used by the comparator interface.
   o1 < o2 - returns a negative integer
   o1 == o2 - returns zero
   o1 > o2 - returns a postitive integer
 

Iterate through all columns that should be compared (in the proper order) and call the Comparator for each of the column elements.

Specified by:
compare in interface java.util.Comparator