Example usage for org.apache.commons.collections4.comparators FixedOrderComparator FixedOrderComparator

List of usage examples for org.apache.commons.collections4.comparators FixedOrderComparator FixedOrderComparator

Introduction

In this page you can find the example usage for org.apache.commons.collections4.comparators FixedOrderComparator FixedOrderComparator.

Prototype

public FixedOrderComparator(final List<T> items) 

Source Link

Document

Constructs a FixedOrderComparator which uses the order of the given list to compare the objects.

Usage

From source file:com.feilong.core.util.SortUtilTest.java

@Test
public void testSelectArray() {
    User zhangfei = new User("", 23);
    User guanyu = new User("", 30);
    User liubei = new User("", 25);
    List<User> list = toList(zhangfei, guanyu, liubei);

    String[] names = { "", "" };
    List<User> select = CollectionsUtil.select(list, "name", names);
    sort(select, new PropertyComparator<User>("name", new FixedOrderComparator<>(names)));
    LOGGER.debug(JsonUtil.formatWithIncludes(select, "name", "age"));

    List<User> select2 = CollectionsUtil.select(list, "name", names);
    LOGGER.debug(//from   ww w.  j  av a  2  s. com
            JsonUtil.formatWithIncludes(sortByFixedOrderPropertyValues(select2, "name", names), "name", "age"));
}

From source file:chiliad.parser.pdf.cli.ParserCli.java

public void showHelpMessage() {
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setOptionComparator(new FixedOrderComparator(options.getOptions().toArray()));
    helpFormatter.setOptPrefix(optionPrefix);
    helpFormatter.printHelp(helpMessage, options);
}

From source file:com.feilong.core.util.AggregateUtilTest.java

/**
 * TestStatisticsUtilTest.//from   w  ww .j a  va  2 s . c  o  m
 */
@Test
public void testStatisticsUtilTest() {
    String[] planets = { "Mercury", "Venus", "Earth", "Mars" };
    Comparator<String> distanceFromSun = new FixedOrderComparator<>(planets);
    Predicate<String> predicate = new ComparatorPredicate<String>("Venus", distanceFromSun, Criterion.GREATER);

    LOGGER.debug("{}", predicate.evaluate("Earth"));
}

From source file:com.feilong.core.util.comparator.BeanComparatorUtil.java

/**
 * Property comparator./*from   ww w . j a  v a 2s .c  o m*/
 *
 * @param <V>
 *            the value type
 * @param <T>
 *            the generic type
 * @param propertyName
 *            T??,Possibly indexed and/or nested name of the property to be modified,??
 *            <a href="../../bean/BeanUtil.html#propertyName">propertyName</a>,value  {@link Comparable}?.
 * @param propertyValues
 *            the property values
 * @return the comparator
 * @throws NullPointerException
 *              <code>propertyName</code> null,<code>propertyValues</code> null
 * @throws IllegalArgumentException
 *              <code>propertyName</code> blank
 * @see PropertyComparator#PropertyComparator(String, Comparator)
 * @see FixedOrderComparator#FixedOrderComparator(Object...)
 */
@SafeVarargs
public static <V, T> Comparator<T> propertyComparator(String propertyName, V... propertyValues) {
    Validate.notBlank(propertyName, "propertyName can't be blank!");
    Validate.notNull(propertyValues, "propertyValues can't be null!");
    return new PropertyComparator<>(propertyName, new FixedOrderComparator<>(propertyValues));
}

From source file:com.feilong.core.util.comparator.BeanComparatorUtil.java

/**
 * Property comparator.//from  w w w  . j a v  a2 s  .  c  om
 *
 * @param <V>
 *            the value type
 * @param <T>
 *            the generic type
 * @param propertyName
 *            T??,Possibly indexed and/or nested name of the property to be modified,??
 *            <a href="../../bean/BeanUtil.html#propertyName">propertyName</a>,value  {@link Comparable}?.
 * @param propertyValues
 *            the property values
 * @return the comparator
 * @throws NullPointerException
 *              <code>propertyName</code> null,<code>propertyValues</code> null
 * @throws IllegalArgumentException
 *              <code>propertyName</code> blank
 * @see PropertyComparator#PropertyComparator(String, Comparator)
 * @see FixedOrderComparator#FixedOrderComparator(List)
 */
public static <V, T> Comparator<T> propertyComparator(String propertyName, List<V> propertyValues) {
    Validate.notBlank(propertyName, "propertyName can't be blank!");
    Validate.notNull(propertyValues, "propertyValues can't be null!");
    return new PropertyComparator<>(propertyName, new FixedOrderComparator<>(propertyValues));
}