Example usage for org.apache.commons.collections.comparators ComparableComparator compare

List of usage examples for org.apache.commons.collections.comparators ComparableComparator compare

Introduction

In this page you can find the example usage for org.apache.commons.collections.comparators ComparableComparator compare.

Prototype

public int compare(Object obj1, Object obj2) 

Source Link

Document

Compare the two Comparable Comparable arguments.

Usage

From source file:de.openali.odysseus.chart.framework.model.data.DataRange.java

@SafeVarargs
@Deprecated/*from  w w w  .  j a va 2 s  .  c o m*/
public static <T> DataRange<T> createFromComparable(final T... items) {
    final ComparableComparator comp = new ComparableComparator();

    T min = null;
    T max = null;

    boolean hasMinAndMax = false;
    for (final T item : items) {
        if (item != null) {
            // erster von Null verschiedener Wert wird als max und min genutzt
            if (hasMinAndMax) {
                try {
                    if (comp.compare(item, min) < 0) {
                        min = item;
                    }
                    if (comp.compare(item, max) > 0) {
                        max = item;
                    }
                } catch (final ClassCastException e) {
                    e.printStackTrace();
                }
            } else {
                min = item;
                max = item;
                hasMinAndMax = true;
            }
        }
    }

    return new DataRange<>(min, max);
}