/** * @since 4.0 */ public <E> List<E> orderedList(Collection<E> objects) { List<E> newList = new ArrayList<>(objects); orderList(newList); return newList; }
/** * Orders a given list of objects, using a List of Orderings applied * according the default iteration order of the Orderings list. I.e. each * Ordering with lower index is more significant than any other Ordering * with higher index. * * @param objects elements to sort * @param orderings list of Orderings to be applied * @return new List with ordered elements * * @since 4.0 */ public static <E> List<E> orderedList(final Collection<E> objects, List<? extends Ordering> orderings) { List<E> newList = new ArrayList<>(objects); orderList(newList, orderings); return newList; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private List<?> toList(Object object) { if (object == null) { throw new IllegalStateException("Unexpected null list"); } if (!(object instanceof List)) { throw new IllegalStateException( "Unexpected object type. Should be a List, got: " + object.getClass().getName()); } List<?> list = (List) object; // sort list before encoding, but do not filter it - we can filter during encoding if (!orderings.isEmpty() && list.size() > 1) { // don't mess up underlying relationship, sort a copy... list = new ArrayList<>(list); Ordering.orderList(list, orderings); } return list; }
o.orderList(list);