@Override public int compareTo(Team that) { ArrayList<Player> thisSorted = sortHeightMembers(); ArrayList<Player> thatSorted = that.sortHeightMembers(); for (int i = 0; i < thisSorted.size() && i < thatSorted.size(); ++i) { if (thisSorted.get(i).compareTo(thatSorted.get(i)) >= 0) { return 1; } } return -1; }
public static void main(String[] args) { ArrayList<Integer> height = new ArrayList<Integer>(3); height.add(0, 1); height.add(1, 5); height.add(2, 4); Team t1 = new Team(height); height.set(0, 2); height.set(1, 3); height.set(2, 4); Team t2 = new Team(height); assert (t1.compareTo(t2) >= 0 && t2.compareTo(t1) >= 0); height.set(0, 0); height.set(1, 3); height.set(2, 2); Team t3 = new Team(height); assert (t3.compareTo(t1) < 0 && t1.compareTo(t3) >= 0 && t3.compareTo(t2) < 0 && t1.compareTo(t2) >= 0); }