/* WARNING: This method should modify the TaxonSet and TaxonLink objects too, but doesn't.
* At the time it was written, there were no such objects. 20090409 MJD
*/
public void doMergeTaxonClass(Set<Taxon> taxonClass) {
Iterator<Taxon> it = taxonClass.iterator();
Taxon canonicalTaxon = it.next();
// Find the taxon in the set with the lowest ID number
while (it.hasNext()) {
Taxon t = it.next();
if (t.getId() < canonicalTaxon.getId()) canonicalTaxon = t;
}
{
StringBuilder s = new StringBuilder ("Merging taxon class : ");
for (Taxon t : taxonClass) s.append(t.getId()).append(" ");
s.append("\n");
warn(s.toString());
}
warn(" Canonical taxon for this set is T" + canonicalTaxon.getId());
// Map all the other taxa to the canonical one
for (Taxon t : taxonClass) {
if (t.equals(canonicalTaxon)) continue;
for (TaxonVariant tv : getTaxonHome().findVariantsByTaxon(t)) {
tv.setTaxon(canonicalTaxon);
getTaxonHome().merge(tv);
}
getCurrentSession().flush();