Example usage for org.apache.commons.collections4.comparators ReverseComparator ReverseComparator

List of usage examples for org.apache.commons.collections4.comparators ReverseComparator ReverseComparator

Introduction

In this page you can find the example usage for org.apache.commons.collections4.comparators ReverseComparator ReverseComparator.

Prototype

@SuppressWarnings("unchecked")
public ReverseComparator(final Comparator<? super E> comparator) 

Source Link

Document

Creates a comparator that inverts the comparison of the given comparator.

Usage

From source file:org.openvpms.component.business.service.archetype.helper.sort.IMObjectSorter.java

/**
 * Sorts objects on a node name.//from www  .  ja va  2 s.  c om
 *
 * @param list the list to sort. This list is modified
 * @param name the name of the node to sort on
 * @return {@code list}
 */
public <T extends IMObject> List<T> sort(List<T> list, String name, boolean ascending) {
    Comparator<T> comparator;
    if ("id".equals(name)) {
        comparator = getIdComparator();
    } else if ("name".equals(name)) {
        comparator = getNameComparator();
    } else {
        comparator = new TransformingComparator<T, Object>(new NodeTransformer<T>(name));
    }
    if (!ascending) {
        comparator = new ReverseComparator<T>(comparator);
    }
    Collections.sort(list, comparator);
    return list;
}