Package com.unboundid.ldap.sdk
Class EntrySorter
- java.lang.Object
-
- com.unboundid.ldap.sdk.EntrySorter
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.Comparator<Entry>
@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class EntrySorter extends java.lang.Object implements java.util.Comparator<Entry>, java.io.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 aSearchResult
object.
This class provides a client-side alternative to the use of theServerSideSortRequestControl
. 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, aSchema
object may be used to provide an indication as to which matching rules should be used to perform the ordering. If noSchema
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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description EntrySorter()
Creates 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, java.util.List<SortKey> sortKeys)
Creates a new entry sorter with the provided information.EntrySorter(boolean sortByHierarchy, java.util.List<SortKey> sortKeys)
Creates a new entry sorter with the provided information.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(Entry e1, Entry e2)
Compares the provided entries to determine the order in which they should be placed in a sorted list.boolean
equals(java.lang.Object o)
Indicates whether the provided object is equal to this entry sorter.int
hashCode()
Retrieves a hash code for this entry sorter.java.util.SortedSet<Entry>
sort(java.util.Collection<? extends Entry> entries)
Sorts the provided collection of entries according to the criteria defined in this entry sorter.java.lang.String
toString()
Retrieves a string representation of this entry sorter.void
toString(java.lang.StringBuilder buffer)
Appends a string representation of this entry sorter to the provided buffer.
-
-
-
Constructor Detail
-
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
public EntrySorter(boolean sortByHierarchy, @NotNull 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.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
public EntrySorter(boolean sortByHierarchy, @Nullable Schema schema, @NotNull 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 benull
if 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
public EntrySorter(boolean sortByHierarchy, @Nullable java.util.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.sortKeys
- A list of sort keys that define the order in which attributes should be compared. It may be empty ornull
if sorting should be done only based on hierarchy.
-
EntrySorter
public EntrySorter(boolean sortByHierarchy, @Nullable Schema schema, @Nullable java.util.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 benull
if no schema is available.sortKeys
- A list of sort keys that define the order in which attributes should be compared. It may be empty ornull
if sorting should be done only based on hierarchy.
-
-
Method Detail
-
sort
@NotNull public java.util.SortedSet<Entry> sort(@NotNull java.util.Collection<? extends Entry> entries)
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
public int compare(@NotNull Entry e1, @NotNull Entry e2)
Compares the provided entries to determine the order in which they should be placed in a sorted list.- Specified by:
compare
in interfacejava.util.Comparator<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
public int hashCode()
Retrieves a hash code for this entry sorter.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A hash code for this entry sorter.
-
equals
public boolean equals(@Nullable java.lang.Object o)
Indicates whether the provided object is equal to this entry sorter.- Specified by:
equals
in interfacejava.util.Comparator<Entry>
- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- The object for which to make the determination.- Returns:
true
if the provided object is equal to this entry sorter, orfalse
if not.
-
toString
@NotNull public java.lang.String toString()
Retrieves a string representation of this entry sorter.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representation of this entry sorter.
-
-