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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations