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

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

Introduction

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

Prototype

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

Source Link

Document

Null safe comparison of Comparables.

Usage

From source file:net.sf.appstatus.core.check.impl.StatusResultImpl.java

public int compareTo(ICheckResult otherResult) {
    int groupCompare = ObjectUtils.compare(group, otherResult.getGroup());
    if (groupCompare != 0) {
        return groupCompare;
    }//ww w .  ja v  a 2 s.  co  m

    return ObjectUtils.compare(probeName, otherResult.getProbeName());
}

From source file:joachimeichborn.geotag.ui.tablecomparators.PositionViewerComparator.java

@Override
public int compare(final Viewer aViewer, final Object aObj1, final Object aObj2) {
    final PositionData p1 = (PositionData) aObj1;
    final PositionData p2 = (PositionData) aObj2;
    int rc = 0;//from ww w  .  j  a v a 2 s . c o m
    switch (column) {
    case PositionsViewerLabelProvider.NAME_COLUMN:
        rc = p1.getName().compareTo(p2.getName());
        break;
    case PositionsViewerLabelProvider.COORDINATES_COLUMN:
        ObjectUtils.compare(p1.getCoordinates(), p2.getCoordinates());
        break;
    case PositionsViewerLabelProvider.TIMESTAMP_COLUMN:
        rc = p1.getTimeStamp().compareTo(p2.getTimeStamp());
        break;
    case PositionsViewerLabelProvider.ACCURACY_COLUMN:
        rc = Float.compare(p1.getAccuracy(), p2.getAccuracy());
        break;
    default:
        rc = 0;
    }

    if (!direction) {
        rc = -rc;
    }

    return rc;
}

From source file:joachimeichborn.geotag.ui.tablecomparators.PictureViewerComparator.java

@Override
public int compare(final Viewer aViewer, final Object aObj1, final Object aObj2) {
    final Picture p1 = (Picture) aObj1;
    final Picture p2 = (Picture) aObj2;
    int rc = 0;//from   w ww  . j a v a  2 s  .  co m
    switch (column) {
    case PictureViewerLabelProvider.NAME_COLUMN:
        rc = p1.getFile().getFileName().toString().compareTo(p2.getFile().getFileName().toString());
        break;
    case PictureViewerLabelProvider.TIME_COLUMN:
        rc = p1.getTime().compareTo(p2.getTime());
        break;
    case PictureViewerLabelProvider.COORDINATES_COLUMN:
        ObjectUtils.compare(p1.getCoordinates(), p2.getCoordinates());
        break;
    case PictureViewerLabelProvider.LOCATION_COLUMN:
        rc = p1.getGeocoding().getLocationName().compareTo(p2.getGeocoding().getLocationName());
        break;
    case PictureViewerLabelProvider.CITY_COLUMN:
        rc = p1.getGeocoding().getCity().compareTo(p2.getGeocoding().getCity());
        break;
    case PictureViewerLabelProvider.SUBLOCATION_COLUMN:
        rc = p1.getGeocoding().getSublocation().compareTo(p2.getGeocoding().getSublocation());
        break;
    case PictureViewerLabelProvider.PROVINCE_STATE_COLUMN:
        rc = p1.getGeocoding().getProvinceState().compareTo(p2.getGeocoding().getProvinceState());
        break;
    case PictureViewerLabelProvider.COUNTRY_CODE_COLUMN:
        rc = p1.getGeocoding().getCountryCode().compareTo(p2.getGeocoding().getCountryCode());
        break;
    case PictureViewerLabelProvider.COUNTRY_NAME_COLUMN:
        rc = p1.getGeocoding().getCountryName().compareTo(p2.getGeocoding().getCountryName());
        break;
    default:
        rc = 0;
    }

    if (!direction) {
        rc = -rc;
    }

    return rc;
}

From source file:com.chessix.vas.service.ValidationService.java

/**
 * Validate given clas, if all accounts have the same value in the different
 * layers.//from w w  w.j a v  a  2 s. c  om
 */
public boolean validate(final String clasId) {
    int page = 0;
    boolean result = true;
    Page<Account> accounts;
    do {
        log.debug("validate({}) : page: {}", clasId, page);
        accounts = dbService.findAccountsByClas(clasId, new PageRequest(page, PAGE_SIZE));
        for (final Account account : accounts) {
            final Integer speed = balance(clasId, account.getExternalId());
            final boolean compare = ObjectUtils.compare(speed, account.getBalance()) == 0;
            if (!compare) {
                log.warn("account {}/{} is out of sync. speed/batch = {}/{}", clasId, account.getExternalId(),
                        speed, account.getBalance());
            }
            result = result && compare;
        }
        page += 1;
    } while (result && accounts.hasNext());
    return result;
}

From source file:gov.va.isaac.search.CompositeSearchResultComparator.java

/**
 * Note, the primary getBestScore() sort is in reverse, so it goes highest to lowest
 *
 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
 *///ww  w  .j  a  v a2  s .c  om
@Override
public int compare(CompositeSearchResult o1, CompositeSearchResult o2) {
    if (o1.getBestScore() < o2.getBestScore()) {
        return 1;
    } else if (o1.getBestScore() > o2.getBestScore()) {
        return -1;
    }

    if (o1.getContainingConcept() == null || o2.getContainingConcept() == null) {
        if (o1.getContainingConcept() == null && o2.getContainingConcept() != null) {
            return 1;
        } else if (o1.getContainingConcept() != null && o2.getContainingConcept() == null) {
            return -1;
        } else {
            return 0;
        }
    }
    // else same score
    String o1FSN = null;
    try {
        o1FSN = o1.getContainingConcept().getFullySpecifiedDescription().getText().trim();
    } catch (Exception e) {
        LOG.warn("Failed calling getFullySpecifiedDescription() (" + e.getClass().getName() + " \""
                + e.getLocalizedMessage() + "\") on concept " + o1, e);
    }
    String o2FSN = null;
    try {
        o2FSN = o2.getContainingConcept().getFullySpecifiedDescription().getText().trim();
    } catch (Exception e) {
        LOG.warn("Failed calling getFullySpecifiedDescription() (" + e.getClass().getName() + " \""
                + e.getLocalizedMessage() + "\") on concept " + o2, e);
    }

    int fsnComparison = ObjectUtils.compare(o1FSN, o2FSN);
    if (fsnComparison != 0) {
        return fsnComparison;
    }

    // else same score and FSN
    String o1PreferredDescription = null;
    try {
        o1PreferredDescription = o1.getContainingConcept().getPreferredDescription().getText().trim();
    } catch (Exception e) {
        LOG.debug("Failed calling getPreferredDescription() (" + e.getClass().getName() + " \""
                + e.getLocalizedMessage() + "\") on concept " + o1, e);
    }

    String o2PreferredDescription = null;
    try {
        o2PreferredDescription = o2.getContainingConcept().getPreferredDescription().getText().trim();
    } catch (Exception e) {
        LOG.debug("Failed calling getPreferredDescription() (" + e.getClass().getName() + " \""
                + e.getLocalizedMessage() + "\") on concept " + o2, e);
    }

    int prefDescComparison = ObjectUtils.compare(o1PreferredDescription, o2PreferredDescription);
    if (prefDescComparison != 0) {
        return prefDescComparison;
    }

    // else same score and FSN and preferred description - sort on type
    String comp1String = o1.getMatchingComponents().iterator().next().toUserString();
    String comp2String = o2.getMatchingComponents().iterator().next().toUserString();

    return ObjectUtils.compare(comp1String, comp2String);
}

From source file:com.discovery.darchrow.util.comparator.PropertyComparator.java

/**
 * Compare./*from   w  w  w.jav a2s  . c  o m*/
 *
 * @param t1
 *            the t1
 * @param t2
 *            the t2
 * @return the int
 * @see org.apache.commons.lang3.ObjectUtils#compare(Comparable, Comparable)
 * @see org.apache.commons.lang3.ObjectUtils#compare(Comparable, Comparable, boolean)
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public int compare(T t1, T t2) {
    if (t1 == t2) {
        return 0;
    } else if (null == t1) {
        return 1;
    } else if (null == t2) {
        return -1;
    }

    Comparable propertyValue1 = PropertyUtil.getProperty(t1, propertyName);
    Comparable propertyValue2 = PropertyUtil.getProperty(t2, propertyName);

    int compareTo = ObjectUtils.compare(propertyValue1, propertyValue2);

    if (0 == compareTo) {
        //??TreeSet / TreeMap ?sort??
        compareTo = ObjectUtils.compare(t1.hashCode(), t2.hashCode());
    }

    //NullPointException
    //propertyValue1.compareTo(propertyValue2);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("propertyName:[{}],propertyValue1:[{}],propertyValue2:[{}],compareTo:[{}]", propertyName,
                propertyValue1, propertyValue2, compareTo);
    }
    return compareTo;
}

From source file:com.sunchenbin.store.feilong.core.util.comparator.PropertyComparator.java

/**
 * Inner compare./*from w  w w  . j  a  va2s . co  m*/
 *
 * @param t1
 *            the t1
 * @param t2
 *            the t2
 * @return the int
 * @since 1.4.0
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private int innerCompare(T t1, T t2) {
    if (t1 == t2) {
        return 0;
    } else if (null == t1) {
        return 1;
    } else if (null == t2) {
        return -1;
    }

    Comparable propertyValue1 = PropertyUtil.getProperty(t1, propertyName);
    Comparable propertyValue2 = PropertyUtil.getProperty(t2, propertyName);

    int compareTo = ObjectUtils.compare(propertyValue1, propertyValue2);

    if (0 == compareTo) {
        //??TreeSet / TreeMap ?sort??
        compareTo = ObjectUtils.compare(t1.hashCode(), t2.hashCode());
    }

    //NullPointException if propertyValue1.compareTo(propertyValue2);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("propertyName:[{}],propertyValue1:[{}],propertyValue2:[{}],compareTo:[{}]", propertyName,
                propertyValue1, propertyValue2, compareTo);
    }
    return compareTo;
}

From source file:gov.nih.nci.firebird.web.action.AbstractProtocolRegistrationAction.java

private boolean checkProtocolDatesNotEqual() {
    Protocol protocol = getRegistration().getProtocol();
    return ObjectUtils.compare(protocol.getLastUpdate(), getOriginalUpdateDate()) != 0;
}

From source file:de.digiway.rapidbreeze.server.infrastructure.objectstorage.ObjectStorage.java

/**
 * Loads all instances which apply to the given filter.
 *
 * @param <T>/*from w w w  .  ja va  2s  .c  o  m*/
 * @param filter
 * @return
 */
public <T> List<T> load(final ObjectStorageFilter filter) {
    List<T> list = load(filter.getClazz());

    // Apply order by filter criteria:
    if (filter.getOrderByProperty() != null) {
        Collections.sort(list, new Comparator<T>() {
            @Override
            public int compare(T o1, T o2) {
                Comparable value1 = ObjectStorageHelper.getProperty(o1, filter.getOrderByProperty());
                Comparable value2 = ObjectStorageHelper.getProperty(o2, filter.getOrderByProperty());
                return ObjectUtils.compare(value1, value2);
            }
        });
        if (!filter.isOrderByAscending()) {
            Collections.reverse(list);
        }
    }

    return list;
}

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

/**
 *  propertyValue1?propertyValue2,? t1/t2 .
 * /* ww  w  .  j av a 2s .  c  o  m*/
 * <p>
 * ??? property, ??,  TreeSet / TreeMap ?sort??
 * </p>
 *
 * @param t1
 *            the t1
 * @param t2
 *            the t2
 * @param propertyValue1
 *            the property value1
 * @param propertyValue2
 *            the property value2
 * @return the int
 * @see org.apache.commons.collections4.comparators.ComparableComparator
 * @since 1.5.4
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private int compare(T t1, T t2, Comparable propertyValue1, Comparable propertyValue2) {
    //NullPointException if propertyValue1.compareTo(propertyValue2);
    int compareTo = ObjectUtils.compare(propertyValue1, propertyValue2);

    if (0 == compareTo) {
        //??TreeSet / TreeMap ?sort??
        int hashCode1 = t1.hashCode();
        int hashCode2 = t2.hashCode();
        compareTo = ObjectUtils.compare(hashCode1, hashCode2);

        String pattern = "propertyName:[{}],same propertyValue:[{}],hashCode1:[{}],hashCode2:[{}],result:[{}]";
        LOGGER.trace(pattern, propertyName, propertyValue1, hashCode1, hashCode2, compareTo);
        return compareTo;
    }

    String pattern = "propertyName:[{}],propertyValue1:[{}],propertyValue2:[{}],result:[{}]";
    LOGGER.trace(pattern, propertyName, propertyValue1, propertyValue2, compareTo);
    return compareTo;
}