本文整理汇总了Java中org.apache.commons.collections4.comparators.ComparatorChain类的典型用法代码示例。如果您正苦于以下问题:Java ComparatorChain类的具体用法?Java ComparatorChain怎么用?Java ComparatorChain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ComparatorChain类属于org.apache.commons.collections4.comparators包,在下文中一共展示了ComparatorChain类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: chainedComparator
import org.apache.commons.collections4.comparators.ComparatorChain; //导入依赖的package包/类
/**
* 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;
}