Package org.forgerock.opendj.ldap
Class SortKey
java.lang.Object
org.forgerock.opendj.ldap.SortKey
A search result sort key as defined in RFC 2891 is used to specify how search
result entries should be ordered. Sort keys are used with the server side
sort request control
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classComparator derived from a sort key which can be used to compare entries. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new sort key using the provided attribute description.Creates a new sort key using the provided attribute description.Creates a new sort key using the provided attribute description.SortKey(AttributeDescription attributeDescription, boolean isReverseOrder, MatchingRule orderingMatchingRule) Creates a new sort key using the provided attribute description. -
Method Summary
Modifier and TypeMethodDescriptionReturns aComparatorwhich can be used to compare entries using this sort key.static Comparator<Entry>comparator(String sortKeys) Returns aComparatorwhich can be used to compare entries using the provided string representation of a list of sort keys.static Comparator<Entry>comparator(Collection<SortKey> keys) Returns aComparatorwhich can be used to compare entries using the provided list of sort keys.comparator(Schema schema) Returns aComparatorwhich can be used to compare entries using this sort key.static Comparator<Entry>comparator(Schema schema, Collection<SortKey> keys) Returns aComparatorwhich can be used to compare entries using the provided list of sort keys.static Comparator<Entry>comparator(Schema schema, SortKey... keys) Returns aComparatorwhich can be used to compare entries using the provided list of sort keys.static Comparator<Entry>comparator(SortKey... keys) Returns aComparatorwhich can be used to compare entries using the provided list of sort keys.booleanReturns the name of the attribute to be sorted using this sort key.Returns the name or OID of the ordering matching rule, if specified, which should be used when comparing attributes using this sort key.inthashCode()booleanReturnstrueif this sort key should be evaluated in reverse (descending) order.toString()Returns a string representation of this sort key using the format defined invalueOf(String).static SortKeyParses the provided string representation of a sort key as aSortKey.
-
Constructor Details
-
SortKey
public SortKey(AttributeDescription attributeDescription, boolean isReverseOrder, MatchingRule orderingMatchingRule) Creates a new sort key using the provided attribute description. The returned sort key will compare attributes in the order specified using the named ordering matching rule.- Parameters:
attributeDescription- The name of the attribute to be sorted using this sort key.isReverseOrder-trueif 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, ornullif the default ordering matching rule associated with the attribute should be used.- Throws:
NullPointerException- IfAttributeDescriptionwasnull.
-
SortKey
Creates a new sort key using the provided attribute description. The returned sort key will compare attributes in ascending order using the default ordering matching rule associated with the attribute.- Parameters:
attributeDescription- The name of the attribute to be sorted using this sort key.- Throws:
NullPointerException- IfAttributeDescriptionwasnull.
-
SortKey
Creates a new sort key using the provided attribute description. The returned sort key will compare attributes in the order specified using the default ordering matching rule associated with the attribute.- Parameters:
attributeDescription- The name of the attribute to be sorted using this sort key.isReverseOrder-trueif this sort key should be evaluated in reverse (descending) order.- Throws:
NullPointerException- IfAttributeDescriptionwasnull.
-
SortKey
Creates a new sort key using the provided attribute description. The returned sort key will compare attributes in the order specified using the named ordering matching rule.- Parameters:
attributeDescription- The name of the attribute to be sorted using this sort key.isReverseOrder-trueif 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, ornullif the default ordering matching rule associated with the attribute should be used.- Throws:
NullPointerException- IfAttributeDescriptionwasnull.
-
-
Method Details
-
comparator
Returns aComparatorwhich can be used to compare entries using the provided list of sort keys. The sort keys will be decoded using the default schema.- Parameters:
keys- The list of sort keys.- Returns:
- The
Comparator. - Throws:
LdapException- If one of the sort keys could not be converted to a comparator.IllegalArgumentException- Ifkeyswas empty.NullPointerException- Ifkeyswasnull.
-
comparator
public static Comparator<Entry> comparator(Schema schema, Collection<SortKey> keys) throws LdapException Returns aComparatorwhich can be used to compare entries using the provided list of sort keys. The sort keys will be decoded using the provided schema.- Parameters:
schema- The schema which should be used for decoding the sort keys.keys- The list of sort keys.- Returns:
- The
Comparator. - Throws:
LdapException- If one of the sort keys could not be converted to a comparator.IllegalArgumentException- Ifkeyswas empty.NullPointerException- Ifschemaorkeyswasnull.
-
comparator
Returns aComparatorwhich can be used to compare entries using the provided list of sort keys. The sort keys will be decoded using the provided schema.- Parameters:
schema- The schema which should be used for decoding the sort keys.keys- The list of sort keys.- Returns:
- The
Comparator. - Throws:
LdapException- If one of the sort keys could not be converted to a comparator.IllegalArgumentException- Ifkeyswas empty.NullPointerException- Ifschemaorkeyswasnull.
-
comparator
Returns aComparatorwhich can be used to compare entries using the provided list of sort keys. The sort keys will be decoded using the default schema.- Parameters:
keys- The list of sort keys.- Returns:
- The
Comparator. - Throws:
LdapException- If one of the sort keys could not be converted to a comparator.IllegalArgumentException- Ifkeyswas empty.NullPointerException- Ifkeyswasnull.
-
comparator
Returns aComparatorwhich 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 consists of a comma-separated list of sort keys as defined invalueOf(String). There must be at least one sort key present in the string representation.- Parameters:
sortKeys- The list of sort keys.- Returns:
- The
Comparator. - Throws:
LdapException- IfsortKeysis 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- IfsortKeyswasnull.
-
valueOf
Parses the provided string representation of a sort key as aSortKey. 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"
- Parameters:
sortKey- The string representation of a sort key.- Returns:
- The parsed
SortKey. - Throws:
LocalizedIllegalArgumentException- IfsortKeyis not a valid string representation of a sort key.NullPointerException- IfsortKeywasnull.
-
comparator
Returns aComparatorwhich 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.- Returns:
- The
Comparator. - Throws:
LdapException- If attributeDescription is not a valid LDAP string representation of an attribute description, or if no ordering matching rule was found.
-
comparator
Returns aComparatorwhich 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.- Parameters:
schema- The schema which should be used for decoding the attribute description and matching rule.- Returns:
- The
Comparator. - Throws:
LdapException- If attributeDescription is not a valid LDAP string representation of an attribute description, or if no ordering matching rule was found.NullPointerException- Ifschemawasnull.
-
getAttributeDescription
Returns the name of the attribute to be sorted using this sort key.- Returns:
- The name of the attribute to be sorted using this sort key.
-
getOrderingMatchingRule
Returns the name or OID of the ordering matching rule, if specified, which should be used when comparing attributes using this sort key.- Returns:
- The name or OID of the ordering matching rule, if specified,
which should be used when comparing attributes using this sort
key, or
nullif the default ordering matching rule associated with the attribute should be used.
-
isReverseOrder
public boolean isReverseOrder()Returnstrueif 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.- Returns:
trueif this sort key should be evaluated in reverse (descending) order.
-
hashCode
public int hashCode() -
equals
-
toString
Returns a string representation of this sort key using the format defined invalueOf(String).
-