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
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);
-
-
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 aComparator
which can be used to compare entries using this sort key.static Comparator<Entry>
comparator(String sortKeys)
Returns aComparator
which 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 aComparator
which can be used to compare entries using the provided list of sort keys.Comparator<Entry>
comparator(Schema schema)
Returns aComparator
which can be used to compare entries using this sort key.static Comparator<Entry>
comparator(Schema schema, Collection<SortKey> keys)
Returns aComparator
which can be used to compare entries using the provided list of sort keys.static Comparator<Entry>
comparator(Schema schema, SortKey... keys)
Returns aComparator
which can be used to compare entries using the provided list of sort keys.static Comparator<Entry>
comparator(SortKey... keys)
Returns aComparator
which can be used to compare entries using the provided 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()
Returnstrue
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 invalueOf(String)
.static SortKey
valueOf(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
-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, ornull
if the default ordering matching rule associated with the attribute should be used.- Throws:
NullPointerException
- IfAttributeDescription
wasnull
.
-
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
- IfAttributeDescription
wasnull
.
-
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
-true
if this sort key should be evaluated in reverse (descending) order.- Throws:
NullPointerException
- IfAttributeDescription
wasnull
.
-
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
-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, ornull
if the default ordering matching rule associated with the attribute should be used.- Throws:
NullPointerException
- IfAttributeDescription
wasnull
.
-
-
Method Detail
-
comparator
public static Comparator<Entry> comparator(Collection<SortKey> keys)
Returns aComparator
which 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:
LocalizedIllegalArgumentException
- If one of the sort keys could not be converted to a comparator.IllegalArgumentException
- Ifkeys
was empty.NullPointerException
- Ifkeys
wasnull
.
-
comparator
public static Comparator<Entry> comparator(Schema schema, Collection<SortKey> keys)
Returns aComparator
which 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:
LocalizedIllegalArgumentException
- If one of the sort keys could not be converted to a comparator.IllegalArgumentException
- Ifkeys
was empty.NullPointerException
- Ifschema
orkeys
wasnull
.
-
comparator
public static Comparator<Entry> comparator(Schema schema, SortKey... keys)
Returns aComparator
which 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:
LocalizedIllegalArgumentException
- If one of the sort keys could not be converted to a comparator.IllegalArgumentException
- Ifkeys
was empty.NullPointerException
- Ifschema
orkeys
wasnull
.
-
comparator
public static Comparator<Entry> comparator(SortKey... keys)
Returns aComparator
which 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:
LocalizedIllegalArgumentException
- If one of the sort keys could not be converted to a comparator.IllegalArgumentException
- Ifkeys
was empty.NullPointerException
- Ifkeys
wasnull
.
-
comparator
public static Comparator<Entry> comparator(String sortKeys)
Returns aComparator
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 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:
LocalizedIllegalArgumentException
- IfsortKeys
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
- IfsortKeys
wasnull
.
-
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 OID
Examples: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
- IfsortKey
is not a valid string representation of a sort key.NullPointerException
- IfsortKey
wasnull
.
-
comparator
public Comparator<Entry> comparator()
Returns aComparator
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.- Returns:
- The
Comparator
. - Throws:
LocalizedIllegalArgumentException
- 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)
Returns aComparator
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.- Parameters:
schema
- The schema which should be used for decoding the attribute description and matching rule.- Returns:
- The
Comparator
. - Throws:
LocalizedIllegalArgumentException
- If attributeDescription is not a valid LDAP string representation of an attribute description, or if no ordering matching rule was found.NullPointerException
- Ifschema
wasnull
.
-
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
null
if the default ordering matching rule associated with the attribute should be used.
-
isReverseOrder
public boolean isReverseOrder()
Returnstrue
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.- Returns:
true
if 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)
.
-
-