Package org.forgerock.opendj.ldap
Class SortKey
- java.lang.Object
-
- org.forgerock.opendj.ldap.SortKey
-
public final class SortKey extends Object
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 controlServerSideSortRequestControl, 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
cnattribute as the sort key:
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.Connection connection = ...; SearchRequest request = ...; Comparator<Entry> comparator = SortKey.comparator("cn"); Set<SearchResultEntry>; results = new TreeSet<>(comparator); connection.search(request, results);
-
-
Constructor Summary
Constructors Constructor 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.SortKey(AttributeDescription attributeDescription, boolean isReverseOrder, MatchingRule orderingMatchingRule)Creates a new sort key using the provided attribute description.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Comparator<Entry>comparator()Returns 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<Entry>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.booleanequals(Object o)StringgetAttributeDescription()Returns the name of the attribute to be sorted using this sort key.StringgetOrderingMatchingRule()Returns the name or OID of the ordering matching rule, if specified, which should be used when comparing attributes using this sort key.inthashCode()booleanisReverseOrder()Returnstrueif this sort key should be evaluated in reverse (descending) order.StringtoString()Returns a string representation of this sort key using the format defined invalueOf(String).static SortKeyvalueOf(String sortKey)Parses the provided string representation of a sort key as aSortKey.
-
-
-
Constructor Detail
-
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
public SortKey(String attributeDescription)
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
public SortKey(String attributeDescription, boolean isReverseOrder)
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
public SortKey(String attributeDescription, boolean isReverseOrder, String 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.
-
-
Method Detail
-
comparator
public static Comparator<Entry> comparator(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 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
public static Comparator<Entry> comparator(Schema schema, 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
public static Comparator<Entry> comparator(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 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(String sortKeys) throws LdapException
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 is comprised of a comma separate 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
public static SortKey valueOf(String sortKey)
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
public Comparator<Entry> comparator() throws LdapException
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
public Comparator<Entry> comparator(Schema schema) throws LdapException
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
public String 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
public 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.- 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.
-
toString
public String toString()
Returns a string representation of this sort key using the format defined invalueOf(String).
-
-