Java 类org.apache.commons.collections4.comparators.ComparatorChain 实例源码

项目:HCFCore    文件:ComparatorUtils.java   
/**
 * Gets a comparator that compares using an array of {@link Comparator}s, applied
 * in sequence until one returns not equal or the array 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 array is null or contains a null
 * @see ComparatorChain
 */
public static <E> Comparator<E> chainedComparator(final Comparator<E>... comparators) {
    final ComparatorChain<E> chain = new ComparatorChain<E>();
    for (final Comparator<E> comparator : comparators) {
        if (comparator == null) {
            throw new NullPointerException("Comparator cannot be null");
        }
        chain.addComparator(comparator);
    }
    return chain;
}
项目:HCFCore    文件:ComparatorUtils.java   
/**
 * Gets a comparator that compares using an array of {@link Comparator}s, applied
 * in sequence until one returns not equal or the array 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 array is null or contains a null
 * @see ComparatorChain
 */
public static <E> Comparator<E> chainedComparator(final Comparator<E>... comparators) {
    final ComparatorChain<E> chain = new ComparatorChain<E>();
    for (final Comparator<E> comparator : comparators) {
        if (comparator == null) {
            throw new NullPointerException("Comparator cannot be null");
        }
        chain.addComparator(comparator);
    }
    return chain;
}