List of usage examples for java.lang Comparable compareTo
public int compareTo(T o);
From source file:org.lpe.common.util.LpeNumericUtils.java
/** * Returns the maximum of the given values. * //w w w .j a v a2 s .c o m * @param values * a collection of values * @param <T> * type of values * @return the maximum */ public static <T extends Number> T max(Collection<T> values) { T max = null; for (T value : values) { if (max == null) { max = value; continue; } @SuppressWarnings("unchecked") Comparable<T> comparable = (Comparable<T>) value; if (comparable.compareTo(max) > 0) { max = value; } } return max; }
From source file:org.lpe.common.util.LpeNumericUtils.java
/** * Returns the minimum of the given values. * /*from w w w . j a v a 2s .c o m*/ * @param values * a collection of values * @param <T> * type of values * @return the minimum */ public static <T extends Number> T min(Collection<T> values) { T min = null; for (T value : values) { if (min == null) { min = value; continue; } @SuppressWarnings("unchecked") Comparable<T> comparable = (Comparable<T>) value; if (comparable.compareTo(min) < 0) { min = value; } } return min; }
From source file:com.espertech.esper.support.util.ArrayAssertionUtil.java
public static EventBean[] sort(EventBean[] oldevents, final String property) { List<EventBean> list = Arrays.asList(oldevents); Collections.sort(list, new Comparator<EventBean>() { public int compare(EventBean o1, EventBean o2) { Comparable val1 = (Comparable) o1.get(property); Comparable val2 = (Comparable) o2.get(property); return val1.compareTo(val2); }/*from w w w.ja va 2 s. c o m*/ }); return list.toArray(new EventBean[list.size()]); }
From source file:uk.gov.gchq.gaffer.function.aggregate.ComparableMax.java
@Override protected void _aggregate(final Comparable input) { if (aggregate == null || input.compareTo(aggregate) > 0) { aggregate = input;//from w ww . ja v a2s.c om } }
From source file:uk.gov.gchq.gaffer.function.aggregate.ComparableMin.java
@Override protected void _aggregate(final Comparable input) { if (aggregate == null || input.compareTo(aggregate) < 0) { aggregate = input;// w w w . j ava 2 s . co m } }
From source file:com.codecrate.shard.util.ComparableComparator.java
public int compare(Object object1, Object object2) { if (!(object1 instanceof Comparable)) { LOG.warn("Object is not comparable: " + object1.getClass()); return 0; }/*from ww w . j a va 2 s . co m*/ Comparable compare1 = (Comparable) object1; Comparable compare2 = (Comparable) object2; return compare1.compareTo(compare2); }
From source file:com.ocs.dynamo.filter.Between.java
@SuppressWarnings("unchecked") @Override/*from w ww . j a v a 2 s. com*/ public boolean evaluate(Object that) { Object value = getProperty(that, getPropertyId()); if (value instanceof Comparable) { Comparable<Object> comp = (Comparable<Object>) value; return comp.compareTo(getStartValue()) >= 0 && comp.compareTo(getEndValue()) <= 0; } return false; }
From source file:com.linkedin.cubert.memory.ObjectArrayList.java
@Override public int compareIndices(int i1, int i2) { Comparable o1 = (Comparable) get(i1); Comparable o2 = (Comparable) get(i2); return o1.compareTo(o2); }
From source file:org.apache.sqoop.validation.AbsoluteValidationThreshold.java
@Override @SuppressWarnings("unchecked") public boolean compare(Comparable left, Comparable right) { LOG.debug("Absolute Validation threshold comparing " + left + " with " + right); return (Math.abs(left.compareTo(right)) == 0); }
From source file:org.sventon.model.DirEntryComparator.java
private <T> int nullSafeCompare(final Comparable<T> o1, final T o2) { if (o1 != null && o2 != null) { return o1.compareTo(o2); } else if (o1 == null && o2 == null) { return 0; } else {//w w w .j a v a 2 s.com return o1 == null ? -1 : 1; } }