/** * Gets a comparator that compares using a collection of {@link Comparator}s, * applied in (default iterator) sequence until one returns not equal or the * collection is exhausted. * * @param <E> the object type to compare * @param comparators the comparators to use, not null or empty or containing nulls * @return a {@link ComparatorChain} formed from the input comparators * @throws NullPointerException if comparators collection is null or contains a null * @throws ClassCastException if the comparators collection contains the wrong object type * @see ComparatorChain */ @SuppressWarnings("unchecked") public static <E> Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators) { return chainedComparator( (Comparator<E>[]) comparators.toArray(new Comparator[comparators.size()]) ); }