SortKey[] sortKeys = sortOrder.getSortKeys();
values = new AttributeValue[sortKeys.length];
for (int i=0; i < sortKeys.length; i++)
{
SortKey sortKey = sortKeys[i];
AttributeType attrType = sortKey.getAttributeType();
List<Attribute> attrList = entry.getAttribute(attrType);
if (attrList != null)
{
AttributeValue sortValue = null;
// There may be multiple versions of this attribute in the target entry
// (e.g., with different sets of options), and it may also be a
// multivalued attribute. In that case, we need to find the value that
// is the best match for the corresponding sort key (i.e., for sorting
// in ascending order, we want to find the lowest value; for sorting in
// descending order, we want to find the highest value). This is
// handled by the SortKey.compareValues method.
for (Attribute a : attrList)
{
for (AttributeValue v : a)
{
if (sortValue == null)
{
sortValue = v;
}
else if (sortKey.compareValues(v, sortValue) < 0)
{
sortValue = v;
}
}
}