/** * Compare the min and max of two values * * @param <E> * a class that implements {@link Comparable} interface * @param e1 * * @param e2 * @return MinMax */ static public <E extends Comparable<E>> MinMax<E> minmax(E e1, E e2) { int cmpResult = e1.compareTo(e2); if (cmpResult <= 0) // e1 is less than or equal to e2 return new MinMax<E>(e1, e2); else return new MinMax<E>(e2, e1); }
public E min() { return getFirst(); }
public E max() { return getSecond(); }
/** * compare * * @param other * @return */ public int compareTo(ECN other) { MinMax<Integer> minmax = Algorithm.minmax(this.size(), other.size()); for (int i = 0; i < minmax.min(); ++i) { int cmp = val.get(i) - other.get(i); if (cmp != 0) return cmp; } ECN largerECN = this.size() > other.size() ? this : other; for (int i = minmax.min(); i < minmax.max(); ++i) { int cmp = largerECN.get(i); if (cmp != 0) return cmp; } return 0; }
static public <E extends Comparable<E>> E min(E e1, E e2) { return minmax(e1, e2).min(); }
static public <E extends Comparable<E>> E max(E e1, E e2) { return minmax(e1, e2).min(); }