Example usage for org.apache.commons.lang ObjectUtils compare

List of usage examples for org.apache.commons.lang ObjectUtils compare

Introduction

In this page you can find the example usage for org.apache.commons.lang ObjectUtils compare.

Prototype

public static <T extends Comparable<? super T>> int compare(T c1, T c2, boolean nullGreater) 

Source Link

Document

Null safe comparison of Comparables.

Usage

From source file:ch.ledcom.log4jtools.utils.FilenameComparator.java

@Override
public final int compare(File f1, File f2) {
    DateTime d1 = ParseUtils.extractDateFromName(f1);
    Integer s1 = ParseUtils.extractSequenceFromName(f1);
    DateTime d2 = ParseUtils.extractDateFromName(f2);
    Integer s2 = ParseUtils.extractSequenceFromName(f2);

    if (ObjectUtils.compare(d1, d2, true) == 0) {
        return ObjectUtils.compare(s1, s2, true);
    }//from   ww w .  j  a va2 s  .  c om
    return ObjectUtils.compare(d1, d2, true);
}

From source file:com.evolveum.midpoint.web.component.util.ListDataProvider2.java

@SuppressWarnings("unchecked")
protected <V extends Comparable<V>> void sort(List<T> list) {
    Collections.sort(list, new Comparator<T>() {
        @Override/*from   w w w  . j  av  a2 s  . c om*/
        public int compare(T o1, T o2) {
            SortParam<String> sortParam = getSort();
            String propertyName = sortParam.getProperty();
            V prop1, prop2;
            try {
                prop1 = (V) PropertyUtils.getProperty(o1, propertyName);
                prop2 = (V) PropertyUtils.getProperty(o2, propertyName);
            } catch (RuntimeException | IllegalAccessException | InvocationTargetException
                    | NoSuchMethodException e) {
                throw new SystemException("Couldn't sort the object list: " + e.getMessage(), e);
            }
            int comparison = ObjectUtils.compare(prop1, prop2, true);
            return sortParam.isAscending() ? comparison : -comparison;
        }
    });
}

From source file:com.evolveum.midpoint.web.component.util.AssignmentListDataProvider.java

@SuppressWarnings("unchecked")
protected <V extends Comparable<V>> void sort(List<ContainerValueWrapper<AssignmentType>> list) {
    Collections.sort(list, new Comparator<ContainerValueWrapper<AssignmentType>>() {
        @Override/*from w  ww.ja  v a2  s.c  om*/
        public int compare(ContainerValueWrapper<AssignmentType> o1, ContainerValueWrapper<AssignmentType> o2) {
            SortParam<String> sortParam = getSort();
            String propertyName = sortParam.getProperty();
            V prop1, prop2;
            try {
                prop1 = (V) PropertyUtils.getProperty(o1.getContainerValue().asContainerable(), propertyName);
                prop2 = (V) PropertyUtils.getProperty(o2.getContainerValue().asContainerable(), propertyName);
            } catch (RuntimeException | IllegalAccessException | InvocationTargetException
                    | NoSuchMethodException e) {
                throw new SystemException("Couldn't sort the object list: " + e.getMessage(), e);
            }
            int comparison = ObjectUtils.compare(prop1, prop2, true);
            return sortParam.isAscending() ? comparison : -comparison;
        }
    });
}