class DuplicateSuppressionUtils {

  public static void removeDuplicates(TopicMapIF topicmap) {

    // remove duplicate topic characteristics
    int batchSize = 50;
    Iterator<TopicIF> it = topicmap.getTopics().iterator();
    while (it.hasNext()) {
      List<TopicIF> batch = CollectionUtils.nextBatch(it, batchSize);
      prefetchTopics(topicmap, batch);
      Iterator<TopicIF> iter = batch.iterator();
      while (iter.hasNext()) {
        removeDuplicates(iter.next());
      }
    }
    
    // remove duplicate associations (do one association type at a time)
    ClassInstanceIndexIF cindex = (ClassInstanceIndexIF)topicmap.getIndex("net.ontopia.topicmaps.core.index.ClassInstanceIndexIF");
    Collection<AssociationIF> assocs;
    Iterator<TopicIF> atypes = new ArrayList<TopicIF>(cindex.getAssociationTypes()).iterator();
    while (atypes.hasNext()) {
      TopicIF atype = atypes.next();
      assocs = cindex.getAssociations(atype);
      if (!assocs.isEmpty())
        removeDuplicateAssociations(assocs);
    }
    // remove duplicate untyped associations
    assocs = cindex.getAssociations(null);
    if (!assocs.isEmpty())
      removeDuplicateAssociations(assocs);
  }

}