-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxLengthWordMapper.Java
42 lines (33 loc) · 991 Bytes
/
MaxLengthWordMapper.Java
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
package june_6_2013;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class MaxLengthWordMapper extends
Mapper<LongWritable, Text, Text, IntWritable> {
private int max_length=0;
private String max_length_word;
private int curr_length=0;
private String curr_length_word;
StringTokenizer st;
public void map(LongWritable key,Text value,Context context)
{
st=new StringTokenizer(value.toString());
while(st.hasMoreTokens())
{
curr_length_word=st.nextToken();
curr_length=curr_length_word.length();
if(max_length<curr_length)
{
max_length=curr_length;
max_length_word=curr_length_word;
}
}
}
protected void cleanup(Context context)
throws IOException, InterruptedException {
context.write(new Text(max_length_word),new IntWritable(max_length));
}
}