Example usage for org.apache.commons.collections ComparatorUtils chainedComparator

List of usage examples for org.apache.commons.collections ComparatorUtils chainedComparator

Introduction

In this page you can find the example usage for org.apache.commons.collections ComparatorUtils chainedComparator.

Prototype

public static Comparator chainedComparator(Collection comparators) 

Source Link

Document

Gets a comparator that compares using a collection of Comparator s, applied in (default iterator) sequence until one returns not equal or the collection is exhausted.

Usage

From source file:com.egt.ejb.toolkit.ColUtils.java

public static <T> Collection<T> sort(Collection<T> collection, Comparator<T>... comparators) {
    Comparator<T> comparator = ComparatorUtils.chainedComparator(comparators);
    if (collection instanceof List) {
        List<T> list = (List<T>) collection;
        Collections.sort(list, comparator);
    }/*from   w w w. j  ava2s  .c o m*/
    return collection;
}

From source file:adalid.commons.util.ColUtils.java

@SuppressWarnings("unchecked") // unchecked cast
public static <T> Collection<T> sort(Collection<T> collection, Comparator<T>... comparators) {
    if (collection instanceof List && !collection.isEmpty() && comparators != null) {
        List<T> list = (List<T>) collection;
        Comparator<T> comparator = (Comparator<T>) ComparatorUtils.chainedComparator(comparators); // unchecked cast
        Collections.sort(list, comparator);
    }//from w  w w  . ja va 2 s .c  om
    return collection;
}

From source file:ips1ap101.lib.base.util.ColUtils.java

@SuppressWarnings("unchecked") // unchecked cast
public static <T> Collection<T> sort(Collection<T> collection, Comparator<T>... comparators) {
    if (collection instanceof List && !collection.isEmpty() && comparators != null) {
        List<T> list = (List<T>) collection;
        Comparator<T> comparator = (Comparator<T>) ComparatorUtils.chainedComparator(comparators); // unchecked cast
        //          Collections.sort(list, comparator);
        wolfgangFahlSort(list, comparator);
    }//from  w  ww .  ja v a 2  s  .c  o  m
    return collection;
}

From source file:com.redhat.rhn.domain.channel.ReleaseChannelMap.java

/**
 * compare to ReleaseChannelMap/*from   w w  w. j a  v  a2s  . co m*/
 * @param o the other object
 * @return the compare return
 */
public int compareTo(ReleaseChannelMap o) {
    List<Comparator> compar = new ArrayList<Comparator>();

    compar.add(new DynamicComparator("channel", true));
    compar.add(new DynamicComparator("channelArch", true));
    compar.add(new DynamicComparator("product", true));
    compar.add(new DynamicComparator("version", true));
    compar.add(new DynamicComparator("release", true));

    Comparator com = ComparatorUtils.chainedComparator((Comparator[]) compar.toArray());
    return com.compare(this, o);
}

From source file:org.apache.cayenne.query.Ordering.java

/**
 * Orders a given list of objects, using a List of Orderings applied
 * according the default iteration order of the Orderings list. I.e. each
 * Ordering with lower index is more significant than any other Ordering
 * with higher index. List being ordered is modified in place.
 *
 * @param objects elements to sort/*from  w w  w. ja  v  a2 s .c  om*/
 * @param orderings list of Orderings to be applied
 */
@SuppressWarnings("unchecked")
public static void orderList(List<?> objects, List<? extends Ordering> orderings) {
    Collections.sort(objects, ComparatorUtils.chainedComparator(orderings));
}

From source file:org.objectstyle.cayenne.query.Ordering.java

/**
 * Orders a given list of objects, using a List of Orderings
 * applied according the default iteration order of the Orderings list. 
 * I.e. each Ordering with lower index is more significant than any other
 * Ordering with higer index. List being ordered is modified in place.
 *///from w  ww .j  a  va  2  s . co m
public static void orderList(List objects, List orderings) {
    Collections.sort(objects, ComparatorUtils.chainedComparator(orderings));
}