use of org.apache.commons.beanutils.BeanComparator in project entando-core by entando.
the class AbstractContentAction method getGroups.
/**
* Restituisce la lista ordinata dei gruppi presenti nel sistema.
* @return La lista dei gruppi presenti nel sistema.
*/
public List<Group> getGroups() {
List<Group> groups = this.getGroupManager().getGroups();
BeanComparator c = new BeanComparator("description");
Collections.sort(groups, c);
return groups;
}
use of org.apache.commons.beanutils.BeanComparator 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.beanutils.BeanComparator in project BroadleafCommerce by BroadleafCommerce.
the class RatingServiceImpl method readReviews.
@Override
@SuppressWarnings("unchecked")
public List<ReviewDetail> readReviews(String itemId, RatingType type, int start, int finish, RatingSortType sortBy) {
RatingSummary summary = this.readRatingSummary(itemId, type);
if (summary != null) {
List<ReviewDetail> reviews = summary.getReviews();
List<ReviewDetail> reviewsToReturn = new ArrayList<ReviewDetail>();
int i = 0;
for (ReviewDetail review : reviews) {
if (i > finish) {
break;
}
if (i >= start) {
reviewsToReturn.add(review);
}
i++;
}
String sortByBeanProperty = "reviewSubmittedDate";
if (sortBy == RatingSortType.MOST_HELPFUL) {
sortByBeanProperty = "helpfulCount";
}
Collections.sort(reviewsToReturn, new BeanComparator(sortByBeanProperty));
return reviewsToReturn;
} else {
return new ArrayList<ReviewDetail>();
}
}
use of org.apache.commons.beanutils.BeanComparator in project BroadleafCommerce by BroadleafCommerce.
the class PageServiceImpl method buildPageDTOListUsingCache.
@SuppressWarnings("unchecked")
protected List<PageDTO> buildPageDTOListUsingCache(List<Page> pageList, String identifier, Locale locale, boolean secure) {
List<PageDTO> dtoList = getCachedPageDTOList(pageList, identifier, locale, secure);
if (dtoList == null || dtoList.isEmpty()) {
addPageListToPageDTOList(pageList, secure, dtoList);
if (dtoList != null && !dtoList.isEmpty()) {
Collections.sort(dtoList, new BeanComparator("priority"));
addPageListToCache(dtoList, identifier, locale, secure);
}
}
return dtoList;
}
use of org.apache.commons.beanutils.BeanComparator in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOfferUtility method determineOfferUnitValue.
@SuppressWarnings("unchecked")
public static BigDecimal determineOfferUnitValue(Offer offer, PromotableCandidateItemOffer promotableCandidateItemOffer) {
if (offer instanceof AdvancedOffer) {
AdvancedOffer advancedOffer = (AdvancedOffer) offer;
if (advancedOffer.isTieredOffer()) {
int quantity = promotableCandidateItemOffer.calculateTargetQuantityForTieredOffer();
List<OfferTier> offerTiers = advancedOffer.getOfferTiers();
Collections.sort(offerTiers, new BeanComparator("minQuantity"));
OfferTier maxTier = null;
// assuming that promotableOffer.getOffer()).getOfferTiers() is sorted already
for (OfferTier currentTier : offerTiers) {
if (quantity >= currentTier.getMinQuantity()) {
maxTier = currentTier;
} else {
break;
}
}
if (maxTier != null) {
return maxTier.getAmount();
}
if (OfferDiscountType.FIX_PRICE.equals(offer.getDiscountType())) {
// so the offer will not get selected.
return BigDecimal.valueOf(Integer.MAX_VALUE);
} else {
return BigDecimal.ZERO;
}
}
}
return offer.getValue();
}
Aggregations