/** * The resulting sort-order is: 1. descending weight, 2. ascending key * (i.e. string representation of this sorted set). * * @param o the other key to compare * @return the result of the comparison */ public int compareTo(Key o) { WeightedKey other = (WeightedKey) o; // compare weights if (weight > other.weight) { return -1; } else if (weight < other.weight) { return 1; } // compare arrays of names int len1 = names.length; int len2 = other.names.length; int len = Math.min(len1, len2); for (int i = 0; i < len; i++) { Name name1 = names[i]; Name name2 = other.names[i]; int result = name1.compareTo(name2); if (result != 0) { return result; } } return len1 - len2; }
/** * The resulting sort-order is: 1. descending weight, 2. ascending key * (i.e. string representation of this sorted set). * * @param o the other key to compare * @return the result of the comparison */ public int compareTo(Key o) { WeightedKey other = (WeightedKey) o; // compare weights if (weight > other.weight) { return -1; } else if (weight < other.weight) { return 1; } // compare arrays of names int len1 = names.length; int len2 = other.names.length; int len = Math.min(len1, len2); for (int i = 0; i < len; i++) { Name name1 = names[i]; Name name2 = other.names[i]; int result = name1.compareTo(name2); if (result != 0) { return result; } } return len1 - len2; }