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

项目:sosiefier    文件:CollatingIteratorTest.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    comparator = new ComparableComparator<java.lang.Integer>();
    evens = new ArrayList<java.lang.Integer>();
    odds = new ArrayList<java.lang.Integer>();
    for (int i = 0 ; i < 20 ; i++) {
        if (0 == (i % 2)) {
            evens.add(i);
        } else {
            odds.add(i);
        }
    }
    fib = new ArrayList<java.lang.Integer>();
    fib.add(1);
    fib.add(1);
    fib.add(2);
    fib.add(3);
    fib.add(5);
    fib.add(8);
    fib.add(13);
    fib.add(21);
}
项目:sosiefier    文件:CollatingIteratorTest.java   
@Test(timeout = 1000)
public void testNullComparator_add975() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testNullComparator_add975");
    final List<java.lang.Integer> l1 = java.util.Arrays.asList(1, 3, 5);
    final List<java.lang.Integer> l2 = java.util.Arrays.asList(2, 4, 6);
    final CollatingIterator<java.lang.Integer> collatingIterator1 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    try {
        collatingIterator1.next();
        collatingIterator1.next();
    } catch (final NullPointerException e) {
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2991,e.getMessage(),2990,e.getMessage().startsWith("You must invoke setComparator"));
    }
    int i = 0;
    final CollatingIterator<java.lang.Integer> collatingIterator2 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    for ( ; collatingIterator2.hasNext() ; i++) {
        final Integer n = collatingIterator2.next();
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2992,((int)(n)));
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2993,(i + 1));
    }
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2994,i);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2995,((l1.size()) + (l2.size())));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:CollatingIteratorTest.java   
@Test(timeout = 1000)
public void testNullComparator_add976() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testNullComparator_add976");
    final List<java.lang.Integer> l1 = java.util.Arrays.asList(1, 3, 5);
    final List<java.lang.Integer> l2 = java.util.Arrays.asList(2, 4, 6);
    final CollatingIterator<java.lang.Integer> collatingIterator1 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    try {
        collatingIterator1.next();
    } catch (final NullPointerException e) {
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2991,e.getMessage(),2990,e.getMessage().startsWith("You must invoke setComparator"));
    }
    int i = 0;
    final CollatingIterator<java.lang.Integer> collatingIterator2 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    for ( ; collatingIterator2.hasNext() ; i++) {
        final Integer n = collatingIterator2.next();
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2992,((int)(n)));
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2993,(i + 1));
    }
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2994,i);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2995,((l1.size()) + (l2.size())));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:CollatingIteratorTest.java   
public void testNullComparator() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testNullComparator");
    final List<java.lang.Integer> l1 = java.util.Arrays.asList(0, 3, 5);
    final List<java.lang.Integer> l2 = java.util.Arrays.asList(2, 4, 6);
    final CollatingIterator<java.lang.Integer> collatingIterator1 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    try {
        collatingIterator1.next();
    } catch (final NullPointerException e) {
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2991,e.getMessage(),2990,e.getMessage().startsWith("You must invoke setComparator"));
    }
    int i = 0;
    final CollatingIterator<java.lang.Integer> collatingIterator2 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    for ( ; collatingIterator2.hasNext() ; i++) {
        final Integer n = collatingIterator2.next();
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2992,((int)(n)));
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2993,(i + 1));
    }
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2994,i);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2995,((l1.size()) + (l2.size())));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:CollatingIteratorTest.java   
public void testNullComparator_literalMutation975() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testNullComparator_literalMutation975");
    final List<java.lang.Integer> l1 = java.util.Arrays.asList(1, 4, 5);
    final List<java.lang.Integer> l2 = java.util.Arrays.asList(2, 4, 6);
    final CollatingIterator<java.lang.Integer> collatingIterator1 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    try {
        collatingIterator1.next();
    } catch (final NullPointerException e) {
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2991,e.getMessage(),2990,e.getMessage().startsWith("You must invoke setComparator"));
    }
    int i = 0;
    final CollatingIterator<java.lang.Integer> collatingIterator2 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    for ( ; collatingIterator2.hasNext() ; i++) {
        final Integer n = collatingIterator2.next();
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2992,((int)(n)));
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2993,(i + 1));
    }
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2994,i);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2995,((l1.size()) + (l2.size())));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:CollatingIteratorTest.java   
public void testNullComparator_literalMutation976() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testNullComparator_literalMutation976");
    final List<java.lang.Integer> l1 = java.util.Arrays.asList(1, 3, 6);
    final List<java.lang.Integer> l2 = java.util.Arrays.asList(2, 4, 6);
    final CollatingIterator<java.lang.Integer> collatingIterator1 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    try {
        collatingIterator1.next();
    } catch (final NullPointerException e) {
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2991,e.getMessage(),2990,e.getMessage().startsWith("You must invoke setComparator"));
    }
    int i = 0;
    final CollatingIterator<java.lang.Integer> collatingIterator2 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    for ( ; collatingIterator2.hasNext() ; i++) {
        final Integer n = collatingIterator2.next();
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2992,((int)(n)));
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2993,(i + 1));
    }
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2994,i);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2995,((l1.size()) + (l2.size())));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:CollatingIteratorTest.java   
public void testNullComparator_literalMutation977() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testNullComparator_literalMutation977");
    final List<java.lang.Integer> l1 = java.util.Arrays.asList(1, 3, 5);
    final List<java.lang.Integer> l2 = java.util.Arrays.asList(1, 4, 6);
    final CollatingIterator<java.lang.Integer> collatingIterator1 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    try {
        collatingIterator1.next();
    } catch (final NullPointerException e) {
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2991,e.getMessage(),2990,e.getMessage().startsWith("You must invoke setComparator"));
    }
    int i = 0;
    final CollatingIterator<java.lang.Integer> collatingIterator2 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    for ( ; collatingIterator2.hasNext() ; i++) {
        final Integer n = collatingIterator2.next();
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2992,((int)(n)));
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2993,(i + 1));
    }
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2994,i);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2995,((l1.size()) + (l2.size())));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:CollatingIteratorTest.java   
public void testNullComparator_literalMutation978() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testNullComparator_literalMutation978");
    final List<java.lang.Integer> l1 = java.util.Arrays.asList(1, 3, 5);
    final List<java.lang.Integer> l2 = java.util.Arrays.asList(2, 5, 6);
    final CollatingIterator<java.lang.Integer> collatingIterator1 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    try {
        collatingIterator1.next();
    } catch (final NullPointerException e) {
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2991,e.getMessage(),2990,e.getMessage().startsWith("You must invoke setComparator"));
    }
    int i = 0;
    final CollatingIterator<java.lang.Integer> collatingIterator2 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    for ( ; collatingIterator2.hasNext() ; i++) {
        final Integer n = collatingIterator2.next();
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2992,((int)(n)));
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2993,(i + 1));
    }
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2994,i);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2995,((l1.size()) + (l2.size())));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:CollatingIteratorTest.java   
public void testNullComparator_literalMutation979() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testNullComparator_literalMutation979");
    final List<java.lang.Integer> l1 = java.util.Arrays.asList(1, 3, 5);
    final List<java.lang.Integer> l2 = java.util.Arrays.asList(2, 4, 7);
    final CollatingIterator<java.lang.Integer> collatingIterator1 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    try {
        collatingIterator1.next();
    } catch (final NullPointerException e) {
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2991,e.getMessage(),2990,e.getMessage().startsWith("You must invoke setComparator"));
    }
    int i = 0;
    final CollatingIterator<java.lang.Integer> collatingIterator2 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    for ( ; collatingIterator2.hasNext() ; i++) {
        final Integer n = collatingIterator2.next();
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2992,((int)(n)));
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2993,(i + 1));
    }
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2994,i);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2995,((l1.size()) + (l2.size())));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:sosiefier    文件:CollatingIteratorTest.java   
public void testNullComparator_literalMutation981() {
    fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testNullComparator_literalMutation981");
    final List<java.lang.Integer> l1 = java.util.Arrays.asList(1, 3, 5);
    final List<java.lang.Integer> l2 = java.util.Arrays.asList(2, 4, 6);
    final CollatingIterator<java.lang.Integer> collatingIterator1 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    try {
        collatingIterator1.next();
    } catch (final NullPointerException e) {
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2991,e.getMessage(),2990,e.getMessage().startsWith("You must invoke setComparator"));
    }
    int i = 1;
    final CollatingIterator<java.lang.Integer> collatingIterator2 = new CollatingIterator<java.lang.Integer>(null , l1.iterator() , l2.iterator());
    collatingIterator2.setComparator(new ComparableComparator<java.lang.Integer>());
    for ( ; collatingIterator2.hasNext() ; i++) {
        final Integer n = collatingIterator2.next();
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2992,((int)(n)));
        fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2993,(i + 1));
    }
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2994,i);
    fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),2995,((l1.size()) + (l2.size())));
    fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread());
}
项目:dhus-core    文件:SortedMapTest.java   
/** Constructor: If map param is null, must throw an IllegalArgumentException. */
@Test(expectedExceptions=NullPointerException.class)
@SuppressWarnings("ResultOfObjectAllocationIgnored")
public void nullMapTest()
{
   new SortedMap(null, new ComparableComparator<>());
}
项目:DataHubSystem    文件:SortedMapTest.java   
/** Constructor: If map param is null, must throw an IllegalArgumentException. */
@Test(expectedExceptions=NullPointerException.class)
@SuppressWarnings("ResultOfObjectAllocationIgnored")
public void nullMapTest()
{
   new SortedMap(null, new ComparableComparator<>());
}
项目:feilong-core    文件:BeanComparatorUtil.java   
/**
 * 按照不同指定属性 <code>propertyNameAndOrders</code> 排序的 {@link Comparator}.
 *
 * @param <T>
 *            the generic type
 * @param propertyNameAndOrders
 *            属性名称和排序因子,
 * 
 *            <p>
 *            格式可以是纯的属性名称, 比如 "name"; 也可以是属性名称+排序因子(以空格分隔),比如 "name desc"
 *            </p>
 * 
 *            <h3>说明:</h3>
 *            <blockquote>
 * 
 *            <dl>
 *            <dt>关于属性名称</dt>
 *            <dd>
 *            泛型T对象指定的属性名称,Possibly indexed and/or nested name of the property to be
 *            modified,参见<a href="../../bean/BeanUtil.html#propertyName">propertyName</a>,<br>
 *            该属性对应的value 必须实现 {@link Comparable}接口.
 *            </dd>
 * 
 *            <dt>关于排序因子</dt>
 *            <dd>
 *            可以没有排序因子<br>
 *            如果有,值可以是asc(顺序),desc(倒序)两种;<br>
 *            如果没有,默认按照asc(顺序)排序;<br>
 *            此外,asc/desc忽略大小写
 *            </dd>
 * 
 *            </dl>
 * 
 *            </blockquote>
 * @return 如果propertyNameAndOrders是单值,那么直接调用 {@link #propertyComparator(String)} 返回
 * @throws NullPointerException
 *             如果 <code>propertyNameAndOrders</code> 是null,<br>
 *             或者有元素是 null;
 * @throws IllegalArgumentException
 *             如果 <code>propertyNameAndOrders</code> 是empty,<br>
 *             或者有元素是 blank
 * @see org.apache.commons.collections4.ComparatorUtils#chainedComparator(java.util.Collection)
 * @since 1.10.2 support propertyNameAndOrder
 */
public static <T> Comparator<T> chainedComparator(String...propertyNameAndOrders){
    Validate.notEmpty(propertyNameAndOrders, "propertyNameAndOrders can't be null/empty!");

    //如果propertyNameAndOrders是单值,那么直接调用 com.feilong.core.util.comparator.BeanComparatorUtil.propertyComparator(String) 返回
    if (1 == propertyNameAndOrders.length){
        return propertyComparator(propertyNameAndOrders[0]);
    }

    //---------------------------------------------------------------

    List<Comparator<T>> comparators = newArrayList();
    for (String propertyNameAndOrder : propertyNameAndOrders){
        Validate.notBlank(propertyNameAndOrder, "propertyNameAndOrder can't be blank!");

        String[] propertyNameAndOrderArray = SortHelper.parsePropertyNameAndOrder(propertyNameAndOrder);

        //注意:此处不要使用 propertyComparator(propertyName)

        //因为,PropertyComparator 如果属性值相同,会使用其他规则继续比较(为了TreeMap/treeSet), 
        //也就是说,通常而言一次就比较出顺序,后续的propertyNameAndOrders 就没作用了

        Comparator instance = ComparatorUtils.nullHighComparator(ComparableComparator.comparableComparator()); //null排在最后面  

        BeanComparator<T> beanComparator = new BeanComparator<>(propertyNameAndOrderArray[0], instance);
        comparators.add(isAsc(propertyNameAndOrderArray) ? beanComparator : reversedComparator(beanComparator));
    }
    return ComparatorUtils.chainedComparator(comparators);
}