LDAP Classes
Implements Java LDAP

com.novell.ldap
Class LDAPCompareAttrNames

java.lang.Object
  extended bycom.novell.ldap.LDAPCompareAttrNames
All Implemented Interfaces:
java.util.Comparator

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

Compares LDAP entries based on attribute name.

An object of this class defines ordering when sorting LDAPEntries, usually from search results. When using this Comparator, LDAPEntry objects are sorted by the attribute names(s) passed in on the constructor, in ascending or descending order. The object is typically supplied to an implementation of the collection interfaces such as java.util.TreeSet which performs sorting.

Comparison is performed via locale-sensitive Java String comparison, which may not correspond to the LDAP ordering rules by which an LDAP server would sort them.


Constructor Summary
LDAPCompareAttrNames(java.lang.String attrName)
          Constructs an object that sorts results by a single attribute, in ascending order.
LDAPCompareAttrNames(java.lang.String[] attrNames)
          Constructs an object that sorts by one or more attributes, in the order provided, in ascending order.
LDAPCompareAttrNames(java.lang.String[] attrNames, boolean[] ascendingFlags)
          Constructs an object that sorts by one or more attributes, in the order provided, in either ascending or descending order for each attribute.
LDAPCompareAttrNames(java.lang.String attrName, boolean ascendingFlag)
          Constructs an object that sorts results by a single attribute, in either ascending or descending order.
 
Method Summary
 int compare(java.lang.Object object1, java.lang.Object object2)
          Compares the the attributes of the first LDAPEntry to the second.
 boolean equals(java.lang.Object comparator)
          Determines if this comparator is equal to the comparator passed in.
 java.util.Locale getLocale()
          Returns the locale to be used for sorting, if a locale has been specified.
 void setLocale(java.util.Locale locale)
          Sets the locale to be used for sorting.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LDAPCompareAttrNames

public LDAPCompareAttrNames(java.lang.String attrName)
Constructs an object that sorts results by a single attribute, in ascending order.

Parameters:
attrName - Name of an attribute by which to sort.

LDAPCompareAttrNames

public LDAPCompareAttrNames(java.lang.String attrName,
                            boolean ascendingFlag)
Constructs an object that sorts results by a single attribute, in either ascending or descending order.

Parameters:
attrName - Name of an attribute to sort by.

ascendingFlag - True specifies ascending order; false specifies descending order.

LDAPCompareAttrNames

public LDAPCompareAttrNames(java.lang.String[] attrNames)
Constructs an object that sorts by one or more attributes, in the order provided, in ascending order.

Note: Novell eDirectory allows sorting by one attribute only. The direcctory server must also be configured to index the specified attribute.

Parameters:
attrNames - Array of names of attributes to sort by.

LDAPCompareAttrNames

public LDAPCompareAttrNames(java.lang.String[] attrNames,
                            boolean[] ascendingFlags)
                     throws LDAPException
Constructs an object that sorts by one or more attributes, in the order provided, in either ascending or descending order for each attribute.

Note: Novell eDirectory supports only ascending sort order (A,B,C ...) and allows sorting only by one attribute. The directory server must be configured to index this attribute.

Parameters:
attrNames - Array of names of attributes to sort by.

ascendingFlags - Array of flags, one for each attrName, where true specifies ascending order and false specifies descending order. An LDAPException is thrown if the length of ascendingFlags is not greater than or equal to the length of attrNames.
Throws:
LDAPException - A general exception which includes an error message and an LDAP error code.
Method Detail

getLocale

public java.util.Locale getLocale()
Returns the locale to be used for sorting, if a locale has been specified.

If locale is null, a basic String.compareTo method is used for collation. If non-null, a locale-specific collation is used.

Returns:
The locale if one has been specified

setLocale

public void setLocale(java.util.Locale locale)
Sets the locale to be used for sorting.

Parameters:
locale - The locale to be used for sorting.

compare

public int compare(java.lang.Object object1,
                   java.lang.Object object2)
Compares the the attributes of the first LDAPEntry to the second.

Only the values of the attributes named at the construction of this object will be compared. Multi-valued attributes compare on the first value only.

Specified by:
compare in interface java.util.Comparator
Parameters:
object1 - Target entry for comparison.
object2 - Entry to be compared to.
Returns:
Negative value if the first entry is less than the second and positive if the first is greater than the second. Zero is returned if all attributes to be compared are the same.

equals

public boolean equals(java.lang.Object comparator)
Determines if this comparator is equal to the comparator passed in.

This will return true if the comparator is an instance of LDAPCompareAttrNames and compares the same attributes names in the same order.

Specified by:
equals in interface java.util.Comparator
Returns:
true the comparators are equal

LDAP Classes
Implements Java LDAP

Copyright © 2002 Novell, Inc. All Rights Reserved.
Novell, Inc.
1800 South Novell Place
Provo, Ut 84606
Phone: (801) 861-5000