com.ibm.itim.common
Class AttributeValueComparator

java.lang.Object
  |
  +--com.ibm.itim.common.AttributeValueComparator
All Implemented Interfaces:
java.util.Comparator, java.io.Serializable

public class AttributeValueComparator
extends java.lang.Object
implements java.util.Comparator, java.io.Serializable

Provides a comparison function for single or multi-valued AttributeValue.

This Comparator can be used in two ways: if the attribute's LDAP syntax OID is known (available), use the two-argument constructor; otherwise, the single-argument constructor is useful if the AttributeValue's values may be treated (compared) as Directory String to determine if the attributes being compared are equal or not. For example:

    AttributeValueComparator comparator1 =
        new AttributeValueComparator(av1);

    AttributeValueComparator comparator2 =
        new AttributeValueComparator(av2);

    boolean result = comparator1.equals(comparator2);
  if (result) System.out.println("av1 is equal to av2");

 
The result above is true if the sorted, concatenated String values of av1 are equal to the sorted, concatenated String values of av2.

Author:
A. Rodriguez
See Also:
Serialized Form

Field Summary
 AttributeValue av1
          The base AttributeValue to compare.
 java.lang.String syntaxOID
          The LDAP syntax OID for the AttributeValue to compare.
 java.util.Map syntaxToClassMap
          Defines an LDAP syntax to Java class mapping.
 
Constructor Summary
AttributeValueComparator(AttributeValue av)
          Creates a Comparator for AttributeValue whose values may be compared using String.compareTo().
AttributeValueComparator(AttributeValue av, java.lang.String syntaxOID)
          Creates a Comparator that maps the given LDAP syntax OID to a Java class.
AttributeValueComparator(java.lang.String syntaxOID)
          Creates a Comparator that maps the given LDAP syntax OID to a Java class.
 
Method Summary
 int compare(java.lang.Object av1, java.lang.Object av2)
          Compares its two arguments for order.
 boolean equals(AttributeValueComparator av2)
          Indicates whether some other AttributeValueComparator is "equal to" this Comparator.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

av1

public AttributeValue av1
The base AttributeValue to compare.

syntaxOID

public java.lang.String syntaxOID
The LDAP syntax OID for the AttributeValue to compare.

syntaxToClassMap

public java.util.Map syntaxToClassMap
Defines an LDAP syntax to Java class mapping.
Constructor Detail

AttributeValueComparator

public AttributeValueComparator(AttributeValue av)
Creates a Comparator for AttributeValue whose values may be compared using String.compareTo().
Parameters:
av - AttributeValue to compare.

AttributeValueComparator

public AttributeValueComparator(java.lang.String syntaxOID)
Creates a Comparator that maps the given LDAP syntax OID to a Java class. If the mapped Java class implements java.lang.Comparable, this Comparator's compare() behaves like the comparable Object's compareTo() and returns its int. Otherwise, the AttributeValue being compared are converted to Strings and the comparison function in this Comparator's equals() and compare() behaves like String.compareTo().
Parameters:
syntaxOID - the attribute's LDAP syntax OID.

AttributeValueComparator

public AttributeValueComparator(AttributeValue av,
                                java.lang.String syntaxOID)
Creates a Comparator that maps the given LDAP syntax OID to a Java class. If the mapped Java class implements java.lang.Comparable, this Comparator's compare() behaves like the comparable Object's compareTo() and returns its int. Otherwise, the AttributeValue being compared are converted to Strings and the comparison function in this Comparator's equals() and compare() behaves like String.compareTo().
Parameters:
av - AttributeValue to compare.
syntaxOID - the attribute's LDAP syntax OID.
Method Detail

compare

public int compare(java.lang.Object av1,
                   java.lang.Object av2)
            throws java.lang.ClassCastException
Compares its two arguments for order. Returns -1 if av1 is "less than" av2, 0 if av1 and av2 are "equal" or 1 if av1 is "greater than" av2.
Specified by:
compare in interface java.util.Comparator
Parameters:
av1 - the first AttributeValue to be compared.
av2 - the second AttributeValue to be compared.
Returns:
-1, 0, or 1 if av1 is less than, equal to or greater than av2.
Throws:
java.lang.ClassCastException - if either av1 or av2 are not instance of common.AttributeValue.

equals

public boolean equals(AttributeValueComparator av2)
Indicates whether some other AttributeValueComparator is "equal to" this Comparator.
Parameters:
av2 - AttributeValue the object with which to compare.
Returns:
true if compare(this, av2) returns 0.