Example #1
0
 @Override
 protected void reduce(Centroid key, Iterable<Point> values, Context context)
     throws IOException, InterruptedException {
   ArrayList<Point> points = new ArrayList<Point>();
   points.clear();
   int clusterId = key.id;
   Point newCenter = null;
   for (Point p : values) {
     Point copy = p.deepCopy();
     points.add(copy);
     if (newCenter == null) {
       newCenter = new Point(copy.deepCopy());
     } else {
       newCenter = newCenter.add(copy);
     }
   }
   Centroid center = new Centroid(clusterId, newCenter);
   for (Point p : points) {
     context.write(center, p);
   }
 }