use of org.apache.commons.collections.comparators.ReverseComparator 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.ReverseComparator in project mondrian by pentaho.
the class PartialSortTest method doStablePartialSort.
// just glue
private Item[] doStablePartialSort(Item[] vec, boolean desc, int limit) {
Comparator<Item> comp = Item.byKey;
if (desc) {
// noinspection unchecked
comp = new ReverseComparator(comp);
}
List<Item> sorted = FunUtil.stablePartialSort(Arrays.asList(vec), comp, limit);
return sorted.toArray(new Item[sorted.size()]);
}
use of org.apache.commons.collections.comparators.ReverseComparator 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;
}
use of org.apache.commons.collections.comparators.ReverseComparator in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupOfferProcessorImpl method applyAllFulfillmentGroupOffers.
@Override
@SuppressWarnings("unchecked")
public boolean applyAllFulfillmentGroupOffers(List<PromotableCandidateFulfillmentGroupOffer> qualifiedFGOffers, PromotableOrder order) {
Map<FulfillmentGroupOfferPotential, List<PromotableCandidateFulfillmentGroupOffer>> offerMap = new HashMap<FulfillmentGroupOfferPotential, List<PromotableCandidateFulfillmentGroupOffer>>();
for (PromotableCandidateFulfillmentGroupOffer candidate : qualifiedFGOffers) {
FulfillmentGroupOfferPotential potential = new FulfillmentGroupOfferPotential();
potential.setOffer(candidate.getOffer());
if (offerMap.get(potential) == null) {
offerMap.put(potential, new ArrayList<PromotableCandidateFulfillmentGroupOffer>());
}
offerMap.get(potential).add(candidate);
}
List<FulfillmentGroupOfferPotential> potentials = new ArrayList<FulfillmentGroupOfferPotential>();
for (FulfillmentGroupOfferPotential potential : offerMap.keySet()) {
List<PromotableCandidateFulfillmentGroupOffer> fgOffers = offerMap.get(potential);
Collections.sort(fgOffers, new ReverseComparator(new BeanComparator("discountedAmount", new NullComparator())));
Collections.sort(fgOffers, new BeanComparator("priority", new NullComparator()));
if (potential.getOffer().isLimitedUsePerOrder() && fgOffers.size() > potential.getOffer().getMaxUsesPerOrder()) {
for (int j = potential.getOffer().getMaxUsesPerOrder(); j < fgOffers.size(); j++) {
fgOffers.remove(j);
}
}
filterOffersByQualifyingAndSubtotalRequirements(order, fgOffers);
for (PromotableCandidateFulfillmentGroupOffer candidate : fgOffers) {
if (potential.getTotalSavings().getAmount().equals(BankersRounding.zeroAmount())) {
BroadleafCurrency currency = order.getOrderCurrency();
if (currency != null) {
potential.setTotalSavings(new Money(BigDecimal.ZERO, currency.getCurrencyCode()));
} else {
potential.setTotalSavings(new Money(BigDecimal.ZERO));
}
}
Money priceBeforeAdjustments = candidate.getFulfillmentGroup().calculatePriceWithoutAdjustments();
Money discountedPrice = candidate.getDiscountedPrice();
potential.setTotalSavings(potential.getTotalSavings().add(priceBeforeAdjustments.subtract(discountedPrice)));
potential.setPriority(candidate.getOffer().getPriority());
}
potentials.add(potential);
}
// Sort fg potentials by priority and discount
Collections.sort(potentials, new BeanComparator("totalSavings", Collections.reverseOrder()));
Collections.sort(potentials, new BeanComparator("priority"));
potentials = removeTrailingNotCombinableFulfillmentGroupOffers(potentials);
boolean fgOfferApplied = false;
for (FulfillmentGroupOfferPotential potential : potentials) {
Offer offer = potential.getOffer();
boolean alreadyContainsTotalitarianOffer = order.isTotalitarianOfferApplied();
List<PromotableCandidateFulfillmentGroupOffer> candidates = offerMap.get(potential);
for (PromotableCandidateFulfillmentGroupOffer candidate : candidates) {
applyFulfillmentGroupOffer(candidate.getFulfillmentGroup(), candidate);
fgOfferApplied = true;
}
for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
fg.chooseSaleOrRetailAdjustments();
}
if ((offer.isTotalitarianOffer() != null && offer.isTotalitarianOffer()) || alreadyContainsTotalitarianOffer) {
fgOfferApplied = compareAndAdjustFulfillmentGroupOffers(order, fgOfferApplied);
if (fgOfferApplied) {
break;
}
} else if (!offer.isCombinableWithOtherOffers()) {
break;
}
}
return fgOfferApplied;
}
Aggregations