@SuppressWarnings("unchecked") public Collection<?> sortItems(Collection<?> items, Limit limit) { ComparatorChain chain = new ComparatorChain(); SortSet sortSet = limit.getSortSet(); for (Sort sort : sortSet.getSorts()) { if (sort.getOrder() == Order.ASC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator())); } else if (sort.getOrder() == Order.DESC) { chain.addComparator(new BeanComparator(sort.getProperty(), new NullComparator()), true); } } if (chain.size() > 0) { Collections.sort((List<?>) items, chain); } return items; }