if (clusteringByThreshold && (top.getSimilarity() < clusteringThreshold)) {
done = true;
break;
}
FastIDSet cluster1 = top.getCluster1();
FastIDSet cluster2 = top.getCluster2();
// Pull out current two clusters from clusters
Iterator<FastIDSet> clusterIterator = clusters.iterator();
boolean removed1 = false;
boolean removed2 = false;
while (clusterIterator.hasNext() && !(removed1 && removed2)) {
FastIDSet current = clusterIterator.next();
// Yes, use == here
if (!removed1 && (cluster1 == current)) {
clusterIterator.remove();
removed1 = true;
} else if (!removed2 && (cluster2 == current)) {
clusterIterator.remove();
removed2 = true;
}
}
// The only catch is if a cluster showed it twice in the list of best cluster pairs;
// have to remove the others. Pull out anything referencing these clusters from queue
for (Iterator<ClusterClusterPair> queueIterator = queue.iterator(); queueIterator.hasNext();) {
ClusterClusterPair pair = queueIterator.next();
FastIDSet pair1 = pair.getCluster1();
FastIDSet pair2 = pair.getCluster2();
if ((pair1 == cluster1) || (pair1 == cluster2) || (pair2 == cluster1) || (pair2 == cluster2)) {
queueIterator.remove();
}
}
// Make new merged cluster
FastIDSet merged = new FastIDSet(cluster1.size() + cluster2.size());
merged.addAll(cluster1);
merged.addAll(cluster2);
// Compare against other clusters; update queue if needed
// That new pair we're just adding might be pretty close to something else, so
// catch that case here and put it back into our queue
for (FastIDSet cluster : clusters) {