-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPair.java
More file actions
52 lines (37 loc) · 1.04 KB
/
Copy pathPair.java
File metadata and controls
52 lines (37 loc) · 1.04 KB
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
44
45
46
47
48
49
50
51
52
public class Pair {
String word;
String type;
public Pair(String word, String type) {
this.word = word.toLowerCase();
this.type = type.toLowerCase();
}
public String getWord() {
return this.word;
}
public String getType() {
return this.type;
}
public int compareTo(Pair k) {
//int result = str1.compareTo( str2 );
int tWord = this.word.compareTo(k.getWord());
int tType = this.type.compareTo(k.getType());
int cWord = k.getWord().compareTo(this.word);
int cType = k.getType().compareTo(this.type);
if(tWord == cWord && tType == cType) {
return 0;
}else if(tWord<cWord) {
return -1;
}else if(tWord == cWord && tType < cType){
return -1;
}else {
return 1;
}
}
public static void main(String args[]) {
Pair test = new Pair("computer","text");
Pair test2 = new Pair("computer", "image");
Pair test3 = new Pair("flower", "image");
System.out.println(test.compareTo(test2));
System.out.println(test2.compareTo(test3));
}
}