forked from NASU41/AtCoderLibraryForJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPair.java
More file actions
28 lines (27 loc) · 1013 Bytes
/
Pair.java
File metadata and controls
28 lines (27 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Pair<S extends Comparable<S>, T extends Comparable<T>> implements Comparable<Pair<S,T>>{
S first;
T second;
public Pair(S s, T t){
first = s;
second = t;
}
public S getFirst(){return first;}
public T getSecond(){return second;}
public boolean equals(Object another){
if(this==another) return true;
if(!(another instanceof Pair)) return false;
Pair otherPair = (Pair)another;
return this.first.equals(otherPair.first) && this.second.equals(otherPair.second);
}
public int compareTo(Pair<S,T> another){
java.util.Comparator<Pair<S,T>> comp1 = java.util.Comparator.comparing(Pair::getFirst);
java.util.Comparator<Pair<S,T>> comp2 = comp1.thenComparing(Pair::getSecond);
return comp2.compare(this, another);
}
public int hashCode(){
return first.hashCode() * 10007 + second.hashCode();
}
public String toString(){
return String.format("(%s, %s)", first, second);
}
}