本文整理汇总了Java中org.apache.commons.collections.ComparatorUtils.chainedComparator方法的典型用法代码示例。如果您正苦于以下问题:Java ComparatorUtils.chainedComparator方法的具体用法?Java ComparatorUtils.chainedComparator怎么用?Java ComparatorUtils.chainedComparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.collections.ComparatorUtils
的用法示例。
在下文中一共展示了ComparatorUtils.chainedComparator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: attachRoutesForClass
import org.apache.commons.collections.ComparatorUtils; //导入方法依赖的package包/类
private void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) {
TreeSet<String> pathsOrderedByLength = new TreeSet<String>(ComparatorUtils.chainedComparator(new Comparator<String>() {
private IntComparator _intComparator = IntComparators.NATURAL_COMPARATOR;
@Override
public int compare(String o1, String o2) {
return _intComparator.compare(o1.length(), o2.length());
}
}, ComparatorUtils.NATURAL_COMPARATOR));
for (Method method : clazz.getDeclaredMethods()) {
Annotation annotationInstance = method.getAnnotation(Paths.class);
if (annotationInstance != null) {
pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value()));
}
}
for (String routePath : pathsOrderedByLength) {
LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName());
router.attach(routePath, new AddHeaderFilter(getContext(), createFinder(clazz)));
}
}
示例2: getComparator
import org.apache.commons.collections.ComparatorUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // unchecked cast
private Comparator<?> getComparator(ExtendedProperties properties, String keyPreffix) {
String key = keyPreffix + ".comparator";
String[] classNames = properties.getStringArray(key);
List<Comparator<?>> comparators = new ArrayList<>();
Comparator<?> c;
for (String name : classNames) {
c = getComparator(name);
if (c != null) {
comparators.add(c);
}
}
return comparators.isEmpty() ? null : (Comparator<?>) ComparatorUtils.chainedComparator(comparators); // unchecked cast
}
示例3: sort
import org.apache.commons.collections.ComparatorUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // unchecked cast
public static <T> Collection<T> sort(Collection<T> collection, Comparator<T>... comparators) {
if (collection instanceof List && !collection.isEmpty() && comparators != null) {
List<T> list = (List<T>) collection;
Comparator<T> comparator = (Comparator<T>) ComparatorUtils.chainedComparator(comparators); // unchecked cast
Collections.sort(list, comparator);
}
return collection;
}
示例4: testSortingByMultipleColumn
import org.apache.commons.collections.ComparatorUtils; //导入方法依赖的package包/类
@Test
public void testSortingByMultipleColumn() {
Comparator<User> byAge = new ArgumentComparator<User, Integer>(on(User.class).getAge());
Comparator<User> byRegistYmdt = new ArgumentComparator<User, Date>(on(User.class).getRegistYmdt());
@SuppressWarnings("unchecked") Comparator<User> orderBy = ComparatorUtils.chainedComparator(byAge, byRegistYmdt);
List<User> sortedList = sort(userList, on(User.class), orderBy);
println("Test sorting:", sortedList);
}
示例5: compareTo
import org.apache.commons.collections.ComparatorUtils; //导入方法依赖的package包/类
/**
* compare to ReleaseChannelMap
* @param o the other object
* @return the compare return
*/
public int compareTo(ReleaseChannelMap o) {
List<Comparator> compar = new ArrayList<Comparator>();
compar.add(new DynamicComparator("channel", true));
compar.add(new DynamicComparator("channelArch", true));
compar.add(new DynamicComparator("product", true));
compar.add(new DynamicComparator("version", true));
compar.add(new DynamicComparator("release", true));
Comparator com = ComparatorUtils.chainedComparator(
(Comparator[]) compar.toArray());
return com.compare(this, o);
}