Example usage for org.apache.commons.collections ComparatorUtils nullLowComparator

List of usage examples for org.apache.commons.collections ComparatorUtils nullLowComparator

Introduction

In this page you can find the example usage for org.apache.commons.collections ComparatorUtils nullLowComparator.

Prototype

public static Comparator nullLowComparator(Comparator comparator) 

Source Link

Document

Gets a Comparator that controls the comparison of null values.

Usage

From source file:com.xpn.xwiki.objects.ElementComparator.java

/**
 * Compares two objects (that implement ElementInterface) by name according 
 * to the rules for the compare method.//from w  w w  .j a v a  2s .c o  m
 * 
 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
 */
public int compare(Object o1, Object o2) {
    // Get a null comparator that is backed by a static "natural" comparator
    Comparator c = ComparatorUtils.nullLowComparator(null);

    // convert o1 and o2 into the string names when not null
    Object no1 = (o1 == null) ? null : ((ElementInterface) o1).getName();
    Object no2 = (o2 == null) ? null : ((ElementInterface) o2).getName();

    // let the null comparator handle possible null values, where null < non-null string
    return c.compare(no1, no2);
}

From source file:org.opensingular.lib.wicket.util.lambda.ILambdasMixin.java

@SuppressWarnings("unchecked")
default <T, R extends Comparable<R>> Comparator<T> compareWith(IFunction<T, R> func) {
    return (T a, T b) -> ComparatorUtils.nullLowComparator(Comparator.naturalOrder()).compare(func.apply(a),
            func.apply(b));//from   w  ww  . j a  v  a2 s  . c o m
}

From source file:org.openvpms.report.jasper.IMObjectCollectionDataSource.java

/**
 * Sorts a list of IMObjects on a node in the form specified by {@link NodeResolver}.
 *
 * @param objects  the objects to sort//w w w  .j av  a2 s . c o  m
 * @param sortNode the node to sort on
 */
@SuppressWarnings("unchecked")
private void sort(List<IMObject> objects, String sortNode) {
    Comparator comparator = ComparatorUtils.naturalComparator();
    comparator = ComparatorUtils.nullLowComparator(comparator);

    Transformer transformer = new NodeTransformer(sortNode, getArchetypeService());
    TransformingComparator transComparator = new TransformingComparator(transformer, comparator);
    Collections.sort(objects, transComparator);
}

From source file:org.openvpms.web.component.im.util.IMObjectSorter.java

/**
 * Returns a new comparator to sort in ascending or descending order.
 * <p/>/*from   w w  w  . j a va2s . co  m*/
 * This comparator handles nulls.
 *
 * @param ascending if <tt>true</tt> sort in ascending order; otherwise sort in descending order
 * @return a new comparator
 */
public static Comparator getComparator(boolean ascending) {
    Comparator comparator = ComparatorUtils.naturalComparator();

    // handle nulls.
    comparator = ComparatorUtils.nullLowComparator(comparator);
    if (!ascending) {
        comparator = ComparatorUtils.reversedComparator(comparator);
    }
    return comparator;
}