@Test public void testAssociationReifiers() { TopicIF type = builder.makeTopic(); TopicIF role1 = builder.makeTopic(); TopicIF role2 = builder.makeTopic(); TopicIF player1 = builder.makeTopic(); TopicIF player2 = builder.makeTopic(); AssociationIF assoc = builder.makeAssociation(type); AssociationRoleIF role = builder.makeAssociationRole(assoc, role1, player1); role = builder.makeAssociationRole(assoc, role2, player2); TopicIF r1 = builder.makeTopic(); assoc.setReifier(r1); builder.makeTopicName(r1, "r1"); assoc = builder.makeAssociation(type); role = builder.makeAssociationRole(assoc, role1, player1); role = builder.makeAssociationRole(assoc, role2, player2); TopicIF r2 = builder.makeTopic(); assoc.setReifier(r2); builder.makeTopicName(r2, "r2"); DuplicateSuppressionUtils.removeDuplicates(topicmap); Assert.assertTrue("duplicate association was not removed", topicmap.getAssociations().size() == 1); assoc = (AssociationIF) topicmap.getAssociations().iterator().next(); Assert.assertTrue("reifier was lost", assoc.getReifier() != null); Assert.assertTrue("reifiers were not merged", assoc.getReifier().getTopicNames().size() == 2); }
public static void removeDuplicates(TopicMapIF topicmap) { 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()); } } 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); } assocs = cindex.getAssociations(null); if (!assocs.isEmpty()) removeDuplicateAssociations(assocs); }
DuplicateSuppressionUtils { public static void removeDuplicates(TopicMapIF topicmap) { 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()); } } 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); } assocs = cindex.getAssociations(null); if (!assocs.isEmpty()) removeDuplicateAssociations(assocs); } }
DuplicateSuppressionUtils { public static void removeDuplicates(TopicMapIF topicmap) { 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()); } } 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); } assocs = cindex.getAssociations(null); if (!assocs.isEmpty()) removeDuplicateAssociations(assocs); }  }
DuplicateSuppressionUtils { public static void removeDuplicates(TopicMapIF topicmap) { 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()); } } 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); } assocs = cindex.getAssociations(null); if (!assocs.isEmpty()) removeDuplicateAssociations(assocs); }  static void removeDuplicates(TopicMapIF topicmap); static void removeDuplicates(TopicIF topic); static void removeDuplicateTopicNames(Collection<TopicNameIF> basenames); static void removeDuplicateOccurrences(Collection<OccurrenceIF> occurs); static void removeDuplicateAssociations(Collection<AssociationIF> assocs); static void removeDuplicates(TopicNameIF basename); static void removeDuplicates(AssociationIF assoc); static Map<AssociationIF, Set<AssociationIF>> removeDuplicateAssociations(TopicIF topic); }
DuplicateSuppressionUtils { public static void removeDuplicates(TopicMapIF topicmap) { 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()); } } 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); } assocs = cindex.getAssociations(null); if (!assocs.isEmpty()) removeDuplicateAssociations(assocs); }  static void removeDuplicates(TopicMapIF topicmap); static void removeDuplicates(TopicIF topic); static void removeDuplicateTopicNames(Collection<TopicNameIF> basenames); static void removeDuplicateOccurrences(Collection<OccurrenceIF> occurs); static void removeDuplicateAssociations(Collection<AssociationIF> assocs); static void removeDuplicates(TopicNameIF basename); static void removeDuplicates(AssociationIF assoc); static Map<AssociationIF, Set<AssociationIF>> removeDuplicateAssociations(TopicIF topic);  }