Package com.unboundid.ldap.sdk
Class EntrySorter
java.lang.Object
com.unboundid.ldap.sdk.EntrySorter
- All Implemented Interfaces:
Serializable,Comparator<Entry>
@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class EntrySorter
extends Object
implements Comparator<Entry>, Serializable
This class provides a mechanism for client-side entry sorting. Sorting may
be based on attributes contained in the entry, and may also be based on the
hierarchical location of the entry in the DIT. The sorting may be applied
to any collection of entries, including the entries included in a
This class provides a client-side alternative to the use of the
For best results, a
SearchResult object.
This class provides a client-side alternative to the use of the
ServerSideSortRequestControl.
Client-side sorting is most appropriate for small result sets, as it requires
all entries to be held in memory at the same time. It is a good alternative
to server-side sorting when the overhead of sorting should be distributed
across client systems rather than on the server, and in cases in which the
target directory server does not support the use of the server-side sort
request control.
For best results, a
Schema object may be used to provide an
indication as to which matching rules should be used to perform the ordering.
If no Schema object is provided, then all ordering will be performed
using case-ignore string matching.
Example
The following example may be used to obtain a sorted set of search result entries, ordered first by sn and then by givenName, without consideration for hierarchy:
SearchResult searchResult = connection.search("dc=example,dc=com",
SearchScope.SUB, Filter.createEqualityFilter("sn", "Smith"));
EntrySorter entrySorter = new EntrySorter(false,
new SortKey("sn"), new SortKey("givenName"));
SortedSet<Entry> sortedEntries =
entrySorter.sort(searchResult.getSearchEntries());
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new entry sorter that will sort entries based only on hierarchy.EntrySorter(boolean sortByHierarchy, SortKey... sortKeys) Creates a new entry sorter with the provided information.EntrySorter(boolean sortByHierarchy, Schema schema, SortKey... sortKeys) Creates a new entry sorter with the provided information.EntrySorter(boolean sortByHierarchy, Schema schema, List<SortKey> sortKeys) Creates a new entry sorter with the provided information.EntrySorter(boolean sortByHierarchy, List<SortKey> sortKeys) Creates a new entry sorter with the provided information. -
Method Summary
Modifier and TypeMethodDescriptionintCompares the provided entries to determine the order in which they should be placed in a sorted list.booleanIndicates whether the provided object is equal to this entry sorter.inthashCode()Retrieves a hash code for this entry sorter.sort(Collection<? extends Entry> entries) Sorts the provided collection of entries according to the criteria defined in this entry sorter.toString()Retrieves a string representation of this entry sorter.voidtoString(StringBuilder buffer) Appends a string representation of this entry sorter to the provided buffer.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
EntrySorter
public EntrySorter()Creates a new entry sorter that will sort entries based only on hierarchy. Superior entries (that is, entries closer to the root of the DIT) will be ordered before subordinate entries. Entries below the same parent will be sorted lexicographically based on their normalized DNs. -
EntrySorter
Creates a new entry sorter with the provided information.- Parameters:
sortByHierarchy- Indicates whether entries should be sorted hierarchically, such that superior entries will be ordered before subordinate entries.sortKeys- A list of sort keys that define the order in which attributes should be compared. It may be empty (but nevernull) if sorting should be done only based on hierarchy.
-
EntrySorter
Creates a new entry sorter with the provided information.- Parameters:
sortByHierarchy- Indicates whether entries should be sorted hierarchically, such that superior entries will be ordered before subordinate entries.schema- The schema to use to make the determination. It may benullif no schema is available.sortKeys- A list of sort keys that define the order in which attributes should be compared. It may be empty (but nevernull) if sorting should be done only based on hierarchy.
-
EntrySorter
Creates a new entry sorter with the provided information.- Parameters:
sortByHierarchy- Indicates whether entries should be sorted hierarchically, such that superior entries will be ordered before subordinate entries.sortKeys- A list of sort keys that define the order in which attributes should be compared. It may be empty ornullif sorting should be done only based on hierarchy.
-
EntrySorter
public EntrySorter(boolean sortByHierarchy, @Nullable Schema schema, @Nullable List<SortKey> sortKeys) Creates a new entry sorter with the provided information.- Parameters:
sortByHierarchy- Indicates whether entries should be sorted hierarchically, such that superior entries will be ordered before subordinate entries.schema- The schema to use to make the determination. It may benullif no schema is available.sortKeys- A list of sort keys that define the order in which attributes should be compared. It may be empty ornullif sorting should be done only based on hierarchy.
-
-
Method Details
-
sort
Sorts the provided collection of entries according to the criteria defined in this entry sorter.- Parameters:
entries- The collection of entries to be sorted.- Returns:
- A sorted set, ordered in accordance with this entry sorter.
-
compare
Compares the provided entries to determine the order in which they should be placed in a sorted list.- Specified by:
comparein interfaceComparator<Entry>- Parameters:
e1- The first entry to be compared.e2- The second entry to be compared.- Returns:
- A negative value if the first entry should be ordered before the second, a positive value if the first entry should be ordered after the second, or zero if the entries should have an equivalent order.
-
hashCode
Retrieves a hash code for this entry sorter. -
equals
Indicates whether the provided object is equal to this entry sorter.- Specified by:
equalsin interfaceComparator<Entry>- Overrides:
equalsin classObject- Parameters:
o- The object for which to make the determination.- Returns:
trueif the provided object is equal to this entry sorter, orfalseif not.
-
toString
Retrieves a string representation of this entry sorter. -
toString
Appends a string representation of this entry sorter to the provided buffer.- Parameters:
buffer- The buffer to which the string representation should be appended.
-