for(int depth = 0; depth < criteria.getElements().size(); depth++) {
Field field = schema.getField(depth);
Field.Type type = field.getType();
SortElement sortElement = criteria.getElements().get(depth);
Order sort = sortElement.getOrder();
RawComparator comparator = sortElement.getCustomComparator();
if(comparator != null) {
// Provided specific Comparator. Some field types has different
// header length and field length.
int[] lengths1 = getHeaderLengthAndFieldLength(b1, o.offset1, type);
int[] lengths2 = getHeaderLengthAndFieldLength(b2, o.offset2, type);
int dataSize1 = lengths1[1];
int dataSize2 = lengths2[1];
int totalField1Size = lengths1[0] + dataSize1; // Header size + data
// size
int totalField2Size = lengths2[0] + dataSize2; // Header size + data
// size
int comparison = comparator.compare(b1, o.offset1, totalField1Size, b2,
o.offset2, totalField2Size);
o.offset1 += totalField1Size;
o.offset2 += totalField2Size;
if(comparison != 0) {
return (sort == Order.ASC) ? comparison : -comparison;