static class MaxTemperatureMapper extends Mapper { private static final int MISSING = 9999; public void map(LongWritable key, Text value, Context conext) throws IOException, InterruptedException { String line = value.toString(); String year = line.substring(5, 9); int airTemperature = Integer.parseInt(line.substring(15, 19));
if(airTemperature != MISSING) { conext.write(new Text(year), new IntWritable(airTemperature)); } } } static class MaxTemperatureReducer extends Reducer { public void reduce(Text key, Iterable values,Context context) throws IOException, InterruptedException { int maxValue = Integer.MIN_VALUE; for(IntWritable value : values) { maxValue = Math.max(maxValue, value.get()); } context.write(key, new IntWritable(maxValue)); } }
public static void main(String[] args) { // TODO Auto-generated method stub if(args.length != 2) { System.err.println("Usage: MaxTemperature