use of org.apache.commons.collections.comparators.NullComparator 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.NullComparator in project vaadin-jsf-integration by alejandro-du.
the class BasePage method sort.
/**
* Sort list according to which column has been clicked on.
* @param list the java.util.List to sort
* @return ordered list
*/
@SuppressWarnings("unchecked")
protected List sort(List list) {
Comparator comparator = new BeanComparator(sortColumn, new NullComparator(nullsAreHigh));
if (!ascending) {
comparator = new ReverseComparator(comparator);
}
Collections.sort(list, comparator);
return list;
}
use of org.apache.commons.collections.comparators.NullComparator 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);
}
use of org.apache.commons.collections.comparators.NullComparator 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.NullComparator in project motech by motech.
the class InMemoryQueryFilter method order.
/**
* Orders the provided collection using the provided ordering information.
* @param collection the collection to order
* @param orderList list of orders that should be applied to the collection
* @param <T> the type of the collection to order
* @return a new list with ordered objects from the provided collection
*/
private static <T> List<T> order(Collection<T> collection, List<Order> orderList) {
List<Comparator<T>> comparatorList = new ArrayList<>();
for (Order order : orderList) {
Comparator<T> comparator = new BeanComparator<>(order.getField(), new NullComparator());
// reverse it if order is descending
if (order.getDirection() == Order.Direction.DESC) {
comparator = new ReverseComparator(comparator);
}
comparatorList.add(comparator);
}
// we use a compound comparator to chain comparators for each provided order
CompoundComparator<T> compoundComparator = new CompoundComparator<>(comparatorList.toArray(new Comparator[comparatorList.size()]));
// convert to a list and sort it
List<T> result = new ArrayList<>(collection);
Collections.sort(result, compoundComparator);
return result;
}
Aggregations