public final class SortKey extends Object
ServerSideSortRequestControl
, but
could also be used for performing client side sorting as well.
The following example illustrates how a single sort key may be used to sort
entries as they are returned from a search operation using the cn
attribute as the sort key:
Connection connection = ...;
SearchRequest request = ...;
Comparator<Entry> comparator = SortKey.comparator("cn");
Set<SearchResultEntry>; results = new TreeSet<>(comparator);
connection.search(request, results);
A sort key includes an attribute description and a boolean value that
indicates whether the sort should be ascending or descending. It may also
contain a specific ordering matching rule that should be used for the sorting
process, although if none is provided it will use the default ordering
matching rule for the attribute type.Constructor and Description |
---|
SortKey(AttributeDescription attributeDescription,
boolean isReverseOrder,
MatchingRule orderingMatchingRule)
Creates a new sort key using the provided attribute description.
|
SortKey(String attributeDescription)
Creates a new sort key using the provided attribute description.
|
SortKey(String attributeDescription,
boolean isReverseOrder)
Creates a new sort key using the provided attribute description.
|
SortKey(String attributeDescription,
boolean isReverseOrder,
String orderingMatchingRule)
Creates a new sort key using the provided attribute description.
|
Modifier and Type | Method and Description |
---|---|
Comparator<Entry> |
comparator()
Returns a
Comparator which can be used to compare entries using
this sort key. |
static Comparator<Entry> |
comparator(Collection<SortKey> keys)
Returns a
Comparator which can be used to compare entries using
the provided list of sort keys. |
Comparator<Entry> |
comparator(Schema schema)
Returns a
Comparator which can be used to compare entries using
this sort key. |
static Comparator<Entry> |
comparator(Schema schema,
Collection<SortKey> keys)
Returns a
Comparator which can be used to compare entries using
the provided list of sort keys. |
static Comparator<Entry> |
comparator(Schema schema,
SortKey... keys)
Returns a
Comparator which can be used to compare entries using
the provided list of sort keys. |
static Comparator<Entry> |
comparator(SortKey... keys)
Returns a
Comparator which can be used to compare entries using
the provided list of sort keys. |
static Comparator<Entry> |
comparator(String sortKeys)
Returns a
Comparator which can be used to compare entries using
the provided string representation of a list of sort keys. |
boolean |
equals(Object o) |
String |
getAttributeDescription()
Returns the name of the attribute to be sorted using this sort key.
|
String |
getOrderingMatchingRule()
Returns the name or OID of the ordering matching rule, if specified,
which should be used when comparing attributes using this sort key.
|
int |
hashCode() |
boolean |
isReverseOrder()
Returns
true if this sort key should be evaluated in reverse
(descending) order. |
String |
toString()
Returns a string representation of this sort key using the format defined
in
valueOf(String) . |
static SortKey |
valueOf(String sortKey)
Parses the provided string representation of a sort key as a
SortKey . |
public SortKey(AttributeDescription attributeDescription, boolean isReverseOrder, MatchingRule orderingMatchingRule)
attributeDescription
- The name of the attribute to be sorted using this sort key.isReverseOrder
- true
if this sort key should be evaluated in reverse
(descending) order.orderingMatchingRule
- The name or OID of the ordering matching rule, which should be
used when comparing attributes using this sort key, or
null
if the default ordering matching rule associated
with the attribute should be used.NullPointerException
- If AttributeDescription
was null
.public SortKey(String attributeDescription)
attributeDescription
- The name of the attribute to be sorted using this sort key.NullPointerException
- If AttributeDescription
was null
.public SortKey(String attributeDescription, boolean isReverseOrder)
attributeDescription
- The name of the attribute to be sorted using this sort key.isReverseOrder
- true
if this sort key should be evaluated in reverse
(descending) order.NullPointerException
- If AttributeDescription
was null
.public SortKey(String attributeDescription, boolean isReverseOrder, String orderingMatchingRule)
attributeDescription
- The name of the attribute to be sorted using this sort key.isReverseOrder
- true
if this sort key should be evaluated in reverse
(descending) order.orderingMatchingRule
- The name or OID of the ordering matching rule, which should be
used when comparing attributes using this sort key, or
null
if the default ordering matching rule associated
with the attribute should be used.NullPointerException
- If AttributeDescription
was null
.public static Comparator<Entry> comparator(Collection<SortKey> keys)
Comparator
which can be used to compare entries using
the provided list of sort keys. The sort keys will be decoded using the
default schema.keys
- The list of sort keys.Comparator
.LocalizedIllegalArgumentException
- If one of the sort keys could not be converted to a
comparator.IllegalArgumentException
- If keys
was empty.NullPointerException
- If keys
was null
.public static Comparator<Entry> comparator(Schema schema, Collection<SortKey> keys)
Comparator
which can be used to compare entries using
the provided list of sort keys. The sort keys will be decoded using the
provided schema.schema
- The schema which should be used for decoding the sort keys.keys
- The list of sort keys.Comparator
.LocalizedIllegalArgumentException
- If one of the sort keys could not be converted to a
comparator.IllegalArgumentException
- If keys
was empty.NullPointerException
- If schema
or keys
was null
.public static Comparator<Entry> comparator(Schema schema, SortKey... keys)
Comparator
which can be used to compare entries using
the provided list of sort keys. The sort keys will be decoded using the
provided schema.schema
- The schema which should be used for decoding the sort keys.keys
- The list of sort keys.Comparator
.LocalizedIllegalArgumentException
- If one of the sort keys could not be converted to a
comparator.IllegalArgumentException
- If keys
was empty.NullPointerException
- If schema
or keys
was null
.public static Comparator<Entry> comparator(SortKey... keys)
Comparator
which can be used to compare entries using
the provided list of sort keys. The sort keys will be decoded using the
default schema.keys
- The list of sort keys.Comparator
.LocalizedIllegalArgumentException
- If one of the sort keys could not be converted to a
comparator.IllegalArgumentException
- If keys
was empty.NullPointerException
- If keys
was null
.public static Comparator<Entry> comparator(String sortKeys)
Comparator
which can be used to compare entries using
the provided string representation of a list of sort keys. The sort keys
will be decoded using the default schema. The string representation is
comprised of a comma separate list of sort keys as defined in
valueOf(String)
. There must be at least one sort key present in
the string representation.sortKeys
- The list of sort keys.Comparator
.LocalizedIllegalArgumentException
- If sortKeys
is not a valid string representation of a
list of sort keys, or if one of the sort keys could not be
converted to a comparator.NullPointerException
- If sortKeys
was null
.public static SortKey valueOf(String sortKey)
SortKey
. The string representation has the following ABNF (see
RFC 4512 for definitions of the elements below):
SortKey = [ PLUS / HYPHEN ] ; order specifier attributedescription ; attribute description [ COLON oid ] ; ordering matching rule OIDExamples:
cn ; case ignore ascending sort on "cn" -cn ; case ignore descending sort on "cn" +cn;lang-fr ; case ignore ascending sort on "cn;lang-fr" -cn;lang-fr:caseExactMatch ; case exact ascending sort on "cn;lang-fr"
sortKey
- The string representation of a sort key.SortKey
.LocalizedIllegalArgumentException
- If sortKey
is not a valid string representation of a
sort key.NullPointerException
- If sortKey
was null
.public Comparator<Entry> comparator()
Comparator
which can be used to compare entries using
this sort key. The attribute description and matching rule, if present,
will be decoded using the default schema.Comparator
.LocalizedIllegalArgumentException
- If attributeDescription is not a valid LDAP string
representation of an attribute description, or if no ordering
matching rule was found.public Comparator<Entry> comparator(Schema schema)
Comparator
which can be used to compare entries using
this sort key. The attribute description and matching rule, if present,
will be decoded using the provided schema.schema
- The schema which should be used for decoding the attribute
description and matching rule.Comparator
.LocalizedIllegalArgumentException
- If attributeDescription is not a valid LDAP string
representation of an attribute description, or if no ordering
matching rule was found.NullPointerException
- If schema
was null
.public String getAttributeDescription()
public String getOrderingMatchingRule()
null
if the default ordering matching rule
associated with the attribute should be used.public boolean isReverseOrder()
true
if this sort key should be evaluated in reverse
(descending) order. More specifically, comparisons performed using the
ordering matching rule associated with this sort key will have their
results inverted.true
if this sort key should be evaluated in reverse
(descending) order.public String toString()
valueOf(String)
.Copyright 2010-2022 ForgeRock AS.