Search in sources :

Example 1 with ComparatorChain

use of org.apache.commons.collections.comparators.ComparatorChain in project BIMserver by opensourceBIM.

the class ServiceImpl method sort.

@SuppressWarnings("unchecked")
private List<SServiceDescriptor> sort(List<SServiceDescriptor> sServiceDescriptors) {
    ComparatorChain comparatorChain = new ComparatorChain();
    comparatorChain.addComparator(new Comparator<SServiceDescriptor>() {

        @Override
        public int compare(SServiceDescriptor o1, SServiceDescriptor o2) {
            return o1.getProviderName().compareTo(o2.getProviderName());
        }
    });
    comparatorChain.addComparator(new Comparator<SServiceDescriptor>() {

        @Override
        public int compare(SServiceDescriptor o1, SServiceDescriptor o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    Collections.sort(sServiceDescriptors, comparatorChain);
    return sServiceDescriptors;
}
Also used : ComparatorChain(org.apache.commons.collections.comparators.ComparatorChain) SServiceDescriptor(org.bimserver.interfaces.objects.SServiceDescriptor)

Example 2 with ComparatorChain

use of org.apache.commons.collections.comparators.ComparatorChain in project mondrian by pentaho.

the class FunUtil method sortMembers.

/**
 * Sorts a list of members according to a list of SortKeySpecs.
 * An in-place, Stable sort.
 * Helper function for MDX OrderSet function.
 *
 * <p>NOTE: Does not preserve the contents of the validator.
 */
static List<Member> sortMembers(Evaluator evaluator, Iterable<Member> memberIter, List<Member> memberList, List<SortKeySpec> keySpecList) {
    if ((memberList != null) && (memberList.size() <= 1)) {
        return memberList;
    }
    if (memberList == null) {
        memberList = new ArrayList<Member>();
        for (Member member : memberIter) {
            memberList.add(member);
        }
        if (memberList.size() <= 1) {
            return memberList;
        }
    }
    ComparatorChain chain = new ComparatorChain();
    for (SortKeySpec key : keySpecList) {
        boolean brk = key.direction.brk;
        MemberComparator comp;
        if (brk) {
            comp = new BreakMemberComparator(evaluator, key.key, key.direction.descending);
        } else {
            comp = new HierarchicalMemberComparator(evaluator, key.key, key.direction.descending);
        }
        comp.preloadValues(memberList);
        chain.addComparator(comp.wrap(), false);
    }
    Collections.sort(memberList, chain);
    return memberList;
}
Also used : ComparatorChain(org.apache.commons.collections.comparators.ComparatorChain)

Example 3 with ComparatorChain

use of org.apache.commons.collections.comparators.ComparatorChain in project mondrian by pentaho.

the class FunUtil method sortTuples.

/**
 * Helper function to sort a list of tuples according to a list
 * of expressions and a list of sorting flags.
 *
 * <p>NOTE: This function does not preserve the contents of the validator.
 */
static TupleList sortTuples(Evaluator evaluator, TupleIterable tupleIter, TupleList tupleList, List<SortKeySpec> keySpecList, int arity) {
    if (tupleList == null) {
        tupleList = TupleCollections.createList(arity);
        TupleCursor cursor = tupleIter.tupleCursor();
        while (cursor.forward()) {
            tupleList.addCurrent(cursor);
        }
    }
    if (tupleList.size() <= 1) {
        return tupleList;
    }
    ComparatorChain chain = new ComparatorChain();
    for (SortKeySpec key : keySpecList) {
        boolean brk = key.direction.brk;
        boolean orderByKey = key.key.isWrapperFor(MemberOrderKeyFunDef.CalcImpl.class);
        if (brk) {
            TupleExpMemoComparator comp = new BreakTupleComparator(evaluator, key.key, arity);
            comp.preloadValues(tupleList);
            chain.addComparator(comp, key.direction.descending);
        } else if (orderByKey) {
            TupleExpMemoComparator comp = new HierarchicalTupleKeyComparator(evaluator, key.key, arity);
            comp.preloadValues(tupleList);
            chain.addComparator(comp, key.direction.descending);
        } else {
            TupleExpComparator comp = new HierarchicalTupleComparator(evaluator, key.key, arity, key.direction.descending);
            chain.addComparator(comp, false);
        }
    }
    Collections.sort(tupleList, chain);
    if (LOGGER.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder("FunUtil.sortTuples returned:");
        for (List<Member> tuple : tupleList) {
            sb.append("\n");
            sb.append(tuple.toString());
        }
        LOGGER.debug(sb.toString());
    }
    return tupleList;
}
Also used : ComparatorChain(org.apache.commons.collections.comparators.ComparatorChain)

Example 4 with ComparatorChain

use of org.apache.commons.collections.comparators.ComparatorChain in project coprhd-controller by CoprHD.

the class CreationTimeComparator method getComparator.

private ComparatorChain getComparator() {
    if (COMPARATOR == null) {
        COMPARATOR = new ComparatorChain();
        COMPARATOR.addComparator(new BeanComparator(CREATION_TIME, new NullComparator()), reverseOrder);
    }
    return COMPARATOR;
}
Also used : ComparatorChain(org.apache.commons.collections.comparators.ComparatorChain) NullComparator(org.apache.commons.collections.comparators.NullComparator) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 5 with ComparatorChain

use of org.apache.commons.collections.comparators.ComparatorChain in project ma-core-public by infiniteautomation.

the class DeltamationCommon method beanSort.

/**
 * Sorts a list of Bean objects by multiple SortOptions
 * @param list
 * @param sort
 */
@SuppressWarnings("unchecked")
public static void beanSort(List<?> list, SortOption... sort) {
    ComparatorChain cc = new ComparatorChain();
    // always sort so that the offset/limit work as intended
    if (sort.length == 0) {
        sort = new SortOption[] { new SortOption("id", false) };
    }
    // TODO catch exceptions?
    NullComparator nullComparator = new NullComparator();
    for (SortOption option : sort) {
        if (option == null)
            continue;
        cc.addComparator(new BeanComparator(option.getAttribute(), nullComparator), option.isDesc());
    }
    Collections.sort(list, cc);
}
Also used : ComparatorChain(org.apache.commons.collections.comparators.ComparatorChain) NullComparator(org.apache.commons.collections.comparators.NullComparator) SortOption(com.infiniteautomation.mango.db.query.SortOption) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Aggregations

ComparatorChain (org.apache.commons.collections.comparators.ComparatorChain)8 BeanComparator (org.apache.commons.beanutils.BeanComparator)3 NullComparator (org.apache.commons.collections.comparators.NullComparator)3 Map (java.util.Map)2 Material (com.bc.pmpheep.back.po.Material)1 Textbook (com.bc.pmpheep.back.po.Textbook)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 SortOption (com.infiniteautomation.mango.db.query.SortOption)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Pattern (java.util.regex.Pattern)1 QName (javax.xml.namespace.QName)1 ProcessConf (org.apache.ode.bpel.iapi.ProcessConf)1