Skip to content

Commit d5af2ab

Browse files
committed
fix Pair::compareTo
1 parent 46d6287 commit d5af2ab

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Pair/Pair.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public boolean equals(Object another){
1313
return this.first.equals(otherPair.first) && this.second.equals(otherPair.second);
1414
}
1515
public int compareTo(Pair<S,T> another){
16-
if(this.second.compareTo(another.second) == 0) return this.first.compareTo(another.first);
17-
else return this.second.compareTo(another.second);
16+
Comparator<Pair<S,T>> comp1 = Comparator.comparing(Pair::getFirst);
17+
Comparator<Pair<S,T>> comp2 = comp1.thenComparing(Pair::getSecond);
18+
return comp2.compare(this, another);
1819
}
1920
public int hashCode(){
2021
return first.hashCode() * 10007 + second.hashCode();

0 commit comments

Comments
 (0)