public static <T> Comparator<T> buildCriteriaComparator(
            final FieldComparators<T> fieldComparatorsMap,
            final BaseCriteria criteria,
            final String... defaultSortFields) {

        Objects.requireNonNull(fieldComparatorsMap);
        Objects.requireNonNull(criteria);

        Comparator<T> comparator = null;

        if (NullSafe.hasItems(criteria.getSortList())) {
            for (final CriteriaFieldSort sort : criteria.getSortList()) {
                final String field = sort.getId();

                Comparator<T> fieldComparator = fieldComparatorsMap.get(field, sort.isIgnoreCase());

                Objects.requireNonNull(fieldComparator, () ->
                        "Missing comparator for field " + field);

                fieldComparator = CompareUtil.reverseIf(fieldComparator, sort.isDesc());

                comparator = CompareUtil.combine(comparator, fieldComparator);
            }
        } else {
            for (final String defaultField : defaultSortFields) {

                final Comparator<T> fieldComparator = fieldComparatorsMap.get(defaultField, true);

                Objects.requireNonNull(fieldComparator, () ->
                        "Missing comparator for field " + defaultField);

                comparator = CompareUtil.combine(comparator, fieldComparator);
            }
        }
        return CompareUtil.nonNull(comparator);
    }
Convert a BaseCriteria into a Comparator
<p>
e.g.

<pre>{@code
private static final FieldComparators<DBTableStatus> FIELD_COMPARATORS = FieldComparators.builder(
    DBTableStatus.class)
  .addStringComparator(DBTableStatus.FIELD_DATABASE, DBTableStatus::getDb)
  .addStringComparator(DBTableStatus.FIELD_TABLE, DBTableStatus::getTable)
  .addCaseLessComparator(DBTableStatus.FIELD_ROW_COUNT, DBTableStatus::getCount)
  .addCaseLessComparator(DBTableStatus.FIELD_DATA_SIZE, DBTableStatus::getDataSize)
  .addCaseLessComparator(DBTableStatus.FIELD_INDEX_SIZE, DBTableStatus::getIndexSize)
  .build();
}</pre>
stroom-util-shared/src/main/java/stroom/util/shared/CompareUtil.java