/** * Clones this object. * * @return clone of this object */ public PairOfLongs clone() { return new PairOfLongs(this.leftElement, this.rightElement); }
public static PairOfLongs of(long left, long right) { return new PairOfLongs(left, right); }
@Override public void map(Text key, Text value, Context context) throws IOException, InterruptedException { context.write(key, new PairOfLongs(Long.parseLong(value.toString()), 1L)); } }
@Override public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { Iterator<IntWritable> iter = values.iterator(); long sum = 0L; long cnt = 0L; while (iter.hasNext()) { sum += iter.next().get(); cnt++; } context.write(key, new PairOfLongs(sum, cnt)); } }
@Override public void reduce(Text key, Iterable<PairOfLongs> values, Context context) throws IOException, InterruptedException { Iterator<PairOfLongs> iter = values.iterator(); long sum = 0L; long cnt = 0L; while (iter.hasNext()) { PairOfLongs pair = iter.next(); sum += pair.getLeftElement(); cnt += pair.getRightElement(); } context.write(key, new PairOfLongs(sum, cnt)); } }
@Override public void reduce(Text key, Iterable<PairOfLongs> values, Context context) throws IOException, InterruptedException { Iterator<PairOfLongs> iter = values.iterator(); long sum = 0L; long cnt = 0L; while (iter.hasNext()) { PairOfLongs pair = iter.next(); sum += pair.getLeftElement(); cnt += pair.getRightElement(); } context.write(key, new PairOfLongs(sum, cnt)); } }
@Override public void cleanup(Context context) throws IOException, InterruptedException { for (String key : sums.keySet()) { context.write(new Text(key), new PairOfLongs(sums.get(key), counts.get(key))); } } }