Newer
Older
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package edu.iastate.cs228.hw2;
public class Pair<E extends Comparable, T extends Comparable> implements Comparable<Pair<E, T>> {
private E first;
private T second;
public Pair(E first, T second){
this.first = first;
this.second = second;
}
@Override
public int compareTo(Pair<E, T> other) {
if(this.getFirst().compareTo(other.getFirst()) > 0){
return 1;
}
else if(this.getFirst().compareTo(other.getFirst()) < 0){
return -1;
}
else if(this.getFirst().compareTo(other.getFirst()) == 0 && this.getSecond().compareTo(other.getSecond()) == 0){
return 0;
}
else if(this.getFirst().compareTo(other.getFirst()) == 0 && this.getSecond().compareTo(other.getSecond()) > 0){
return 1;
}
else if(this.getFirst().compareTo(other.getFirst()) == 0 && this.getSecond().compareTo(other.getSecond()) < 0){
return -1;
}
else{
return 0;
}
}
public E getFirst(){
return first;
}
public T getSecond(){
return second;
}
}