-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordCountKeyComparator.java
More file actions
46 lines (38 loc) · 1.25 KB
/
WordCountKeyComparator.java
File metadata and controls
46 lines (38 loc) · 1.25 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
package wordcount;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;
public class WordCountKeyComparator extends WritableComparator {
public WordCountKeyComparator() {
super(Text.class, true);
}
public int compare(WritableComparable o1, WritableComparable o2) {
Text key1 = (Text) o1;
Text key2 = (Text) o2;
String text1 = key1.toString();
String text2 = key2.toString();
int flag = text1.compareTo(text2);
if(flag>0){//text1>text2
int check = text1.toLowerCase().compareTo(text2.toLowerCase());
if(check>0){
return 1;
}else if(check==0){
return 1;
}else if(check<0){
return -1;
}
}else if(flag==0){//text1=text2
return 0;
}else if(flag<0){//text1<text2
int check = text1.toLowerCase().compareTo(text2.toLowerCase());
if(check>0){
return 1;
}else if(check==0){
return -1;
}else if(check<0){
return -1;
}
}
return 0;
}
}