@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class EntrySorter extends java.lang.Object implements java.util.Comparator<Entry>, java.io.Serializable
SearchResult
object.
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.
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.
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());
Constructor and Description |
---|
EntrySorter()
Creates a new entry sorter that will sort entries based only on hierarchy.
|
EntrySorter(boolean sortByHierarchy,
java.util.List<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,
Schema schema,
SortKey... sortKeys)
Creates a new entry sorter with the provided information.
|
EntrySorter(boolean sortByHierarchy,
SortKey... sortKeys)
Creates a new entry sorter with the provided information.
|
Modifier and Type | Method and 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.
|
public EntrySorter()
public EntrySorter(boolean sortByHierarchy, @NotNull SortKey... sortKeys)
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 never null
) if sorting should be done
only based on hierarchy.public EntrySorter(boolean sortByHierarchy, @Nullable Schema schema, @NotNull SortKey... sortKeys)
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 be null
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 never null
) if sorting should be done
only based on hierarchy.public EntrySorter(boolean sortByHierarchy, @Nullable java.util.List<SortKey> sortKeys)
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 or
null
if sorting should be done only based
on hierarchy.public EntrySorter(boolean sortByHierarchy, @Nullable Schema schema, @Nullable java.util.List<SortKey> sortKeys)
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 be null
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 or
null
if sorting should be done only based
on hierarchy.@NotNull public java.util.SortedSet<Entry> sort(@NotNull java.util.Collection<? extends Entry> entries)
entries
- The collection of entries to be sorted.public int compare(@NotNull Entry e1, @NotNull Entry e2)
compare
in interface java.util.Comparator<Entry>
e1
- The first entry to be compared.e2
- The second entry to be compared.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(@Nullable java.lang.Object o)
equals
in interface java.util.Comparator<Entry>
equals
in class java.lang.Object
o
- The object for which to make the determination.true
if the provided object is equal to this entry sorter,
or false
if not.@NotNull public java.lang.String toString()
toString
in class java.lang.Object