Search in sources :

Example 1 with NullComparator

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;
}
Also used : ComparatorChain(org.apache.commons.collections.comparators.ComparatorChain) NullComparator(org.apache.commons.collections.comparators.NullComparator) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 2 with NullComparator

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;
}
Also used : NullComparator(org.apache.commons.collections.comparators.NullComparator) BeanComparator(org.apache.commons.beanutils.BeanComparator) ReverseComparator(org.apache.commons.collections.comparators.ReverseComparator) ReverseComparator(org.apache.commons.collections.comparators.ReverseComparator) BeanComparator(org.apache.commons.beanutils.BeanComparator) NullComparator(org.apache.commons.collections.comparators.NullComparator) Comparator(java.util.Comparator)

Example 3 with NullComparator

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

Example 4 with NullComparator

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;
}
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 NullComparator

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;
}
Also used : Order(org.motechproject.mds.util.Order) NullComparator(org.apache.commons.collections.comparators.NullComparator) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) ReverseComparator(org.apache.commons.collections.comparators.ReverseComparator) CompoundComparator(org.springframework.util.comparator.CompoundComparator) NullComparator(org.apache.commons.collections.comparators.NullComparator) ReverseComparator(org.apache.commons.collections.comparators.ReverseComparator) CompoundComparator(org.springframework.util.comparator.CompoundComparator) BeanComparator(org.apache.commons.beanutils.BeanComparator) Comparator(java.util.Comparator)

Aggregations

BeanComparator (org.apache.commons.beanutils.BeanComparator)6 NullComparator (org.apache.commons.collections.comparators.NullComparator)6 ComparatorChain (org.apache.commons.collections.comparators.ComparatorChain)3 ReverseComparator (org.apache.commons.collections.comparators.ReverseComparator)3 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 SortOption (com.infiniteautomation.mango.db.query.SortOption)1 HashMap (java.util.HashMap)1 List (java.util.List)1 BroadleafCurrency (org.broadleafcommerce.common.currency.domain.BroadleafCurrency)1 Money (org.broadleafcommerce.common.money.Money)1 Offer (org.broadleafcommerce.core.offer.domain.Offer)1 FulfillmentGroupOfferPotential (org.broadleafcommerce.core.offer.service.discount.FulfillmentGroupOfferPotential)1 PromotableCandidateFulfillmentGroupOffer (org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer)1 PromotableFulfillmentGroup (org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup)1 Order (org.motechproject.mds.util.Order)1 CompoundComparator (org.springframework.util.comparator.CompoundComparator)1