public <T> Comparator<T> buildComparator() {
        if (sortedAttributes.isEmpty()) {
            return (o1, o2) -> 0;
        } else {
            Comparator<T> comparator = null;
            for (SortedAttribute sortedAttribute : sortedAttributes) {
                if (comparator == null) {
                    comparator = buildComparator(sortedAttribute);
                } else {
                    comparator = comparator.thenComparing(buildComparator(sortedAttribute));
                }
            }
            return comparator;
        }
    }
public < T > Comparator < T > buildComparator ( ) { if ( sortedAttributes . isEmpty ( ) ) { return ( o1 , o2 ) -> 0 ; } else { Comparator < T > comparator = null ; for ( SortedAttribute sortedAttribute : sortedAttributes ) { if ( comparator == null ) { comparator = buildComparator ( sortedAttribute ) ; } else { comparator = comparator . thenComparing ( buildComparator ( sortedAttribute ) ) ; } } return comparator ; } }
Builds a comparator allowing the sorting of objects according to the sort criteria.

@param <T> the type of the object to compare.
@return the comparator.