}
@Override
protected void map(Text key, CanopyWritable value, Context context) throws IOException, InterruptedException {
Cluster cluster = value.get();
int[] point = cluster.getCenter();
boolean stronglyBound = false;
for (Cluster canopy : canopies) {
double dist = measure.distance(canopy.getCenter(), point);
if (dist < t1) {
KEY.set(Arrays.toString(canopy.getCenter()));
Cluster newCluster;
if (dist < t2) {
newCluster = new Canopy(canopy.getId(), point, value.get().getNum());
LOGGER.debug("Adding (T2) {} to Cluster {}", Arrays.toString(point),
Arrays.toString(canopy.getCenter()));
} else {
newCluster = new Canopy(canopy.getId(), point, 0L);
LOGGER.debug("Adding (T1) {} to Cluster {}", Arrays.toString(point),
Arrays.toString(canopy.getCenter()));
}
context.write(KEY, new CanopyWritable(newCluster));
}
stronglyBound = stronglyBound || dist < t2;
}
if (!stronglyBound) {
nextCanopyId++;
Cluster canopy = new Canopy(nextCanopyId, point, value.get().getNum());
canopies.add(canopy);
LOGGER.debug("Creating a new Cluster {}", canopy.asFormattedString());
KEY.set(Arrays.toString(canopy.getCenter()));
context.write(KEY, value);
}
}