Search in sources :

Example 1 with QuerySortOrder

use of com.amplifyframework.core.model.query.QuerySortOrder in project amplify-android by aws-amplify.

the class ModelSorter method getComparator.

private Comparator<T> getComparator(List<QuerySortBy> sortByList, Class<T> itemClass, Consumer<DataStoreException> onObservationError) {
    QuerySortBy sortBy = sortByList.get(0);
    Comparator<T> comparator = new ModelComparator<T>(sortBy, itemClass, onObservationError);
    QuerySortOrder sortOrder = sortBy.getSortOrder();
    if (sortOrder == QuerySortOrder.DESCENDING) {
        comparator = comparator.reversed();
    }
    for (int i = 1; i < sortByList.size(); i++) {
        QuerySortBy nextSortBy = sortByList.get(i);
        Comparator<T> nextComparator = comparator.thenComparing(new ModelComparator<T>(nextSortBy, itemClass, onObservationError));
        if (nextSortBy.getSortOrder() == QuerySortOrder.DESCENDING) {
            nextComparator.reversed();
        }
    }
    return comparator;
}
Also used : QuerySortBy(com.amplifyframework.core.model.query.QuerySortBy) QuerySortOrder(com.amplifyframework.core.model.query.QuerySortOrder)

Aggregations

QuerySortBy (com.amplifyframework.core.model.query.QuerySortBy)1 QuerySortOrder (com.amplifyframework.core.model.query.QuerySortOrder)1