private Collection<AssociationRoleIF> getTopicRoles(TopicIF topic, TopicIF roleType, TopicIF associationType) { if (roleType == null) { return topic.getRoles(); } else { if (associationType == null) { return topic.getRolesByType(roleType); } else { return topic.getRolesByType(roleType, associationType); } } }
@Override public Set<Role> getRolesPlayed() { return topicMap.wrapSet(wrapped.getRoles()); }
private static void copyAssociations(TopicIF target, TopicIF source) { Set<AssociationIF> uniqueAssocs = new HashSet<AssociationIF>(); Iterator<AssociationRoleIF> roleIterator = source.getRoles().iterator(); while (roleIterator.hasNext()) { AssociationRoleIF o = roleIterator.next(); uniqueAssocs.add(o.getAssociation()); } Iterator<AssociationIF> associationIterator = uniqueAssocs.iterator(); while (associationIterator.hasNext()) { AssociationIF o = associationIterator.next(); copyAssociation(target, o, source); } }
public static List<AssociationRoleIF> findRoles(TopicIF aType, TopicIF rType, TopicIF player) { List<AssociationRoleIF> result = new ArrayList<AssociationRoleIF>(); Iterator<AssociationRoleIF> it = player.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF role = it.next(); AssociationIF association = role.getAssociation(); if (Objects.equals(role.getType(), rType) && Objects.equals(association.getType(), aType)) result.add(role); } return result; }
public static AssociationIF findUnaryAssociation( TopicMap tm, TopicIF aType, TopicIF player, TopicIF rType) { Iterator<AssociationRoleIF> iter = player.getRoles().iterator(); while (iter.hasNext()) { AssociationRoleIF role = iter.next(); AssociationIF assoc = role.getAssociation(); if (Objects.equals(role.getType(), rType) && Objects.equals(assoc.getType(), aType)) return assoc; } return null; }
public static List<AssociationRoleIF> findRoles(TopicIF aType, TopicIF rType, TopicIF player) { List<AssociationRoleIF> result = new ArrayList<AssociationRoleIF>(); Iterator<AssociationRoleIF> it = player.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF role = it.next(); AssociationIF association = role.getAssociation(); if (ObjectUtils.equals(role.getType(), rType) && ObjectUtils.equals(association.getType(), aType)) result.add(role); } return result; }
public static AssociationIF findUnaryAssociation( TopicMap tm, TopicIF aType, TopicIF player, TopicIF rType) { Iterator<AssociationRoleIF> iter = player.getRoles().iterator(); while (iter.hasNext()) { AssociationRoleIF role = iter.next(); AssociationIF assoc = role.getAssociation(); if (ObjectUtils.equals(role.getType(), rType) && ObjectUtils.equals(assoc.getType(), aType)) return assoc; } return null; }
public static List<AssociationRoleIF> findRoles(TopicIF aType, TopicIF rType, TopicIF player, Collection<TopicIF> scope) { List<AssociationRoleIF> result = new ArrayList<AssociationRoleIF>(); Iterator<AssociationRoleIF> it = player.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF role = it.next(); AssociationIF association = role.getAssociation(); if (ObjectUtils.equals(role.getType(), rType) && ObjectUtils.equals(association.getType(), aType) && CollectionUtils.equalsUnorderedSet(association.getScope(), scope)) result.add(role); } return result; }
public void testBothBoundTrue() throws InvalidQueryException, IOException { load("bb-test.ltm"); List matches = new ArrayList(); TopicIF teacher = getTopicById("larer"); AssociationRoleIF role = (AssociationRoleIF) teacher.getRoles().iterator().next(); matches.add(new HashMap()); verifyQuery(matches, "role-player(@" + role.getObjectId() + ", larer)?"); }
public void testBothBoundFalse() throws InvalidQueryException, IOException { load("bb-test.ltm"); List matches = new ArrayList(); TopicIF teacher = getTopicById("larer"); AssociationRoleIF role = (AssociationRoleIF) teacher.getRoles().iterator().next(); verifyQuery(matches, "role-player(@" + role.getObjectId() + ", gdm)?"); }
public void testAssociation() { LocatorIF loc = base.resolveAbsolute("#topic-1"); TopicIF topic = (TopicIF)tm.getObjectByItemIdentifier(loc); AssociationRoleIF assocrl = (AssociationRoleIF)topic.getRoles().iterator().next(); AssociationIF association = assocrl.getAssociation(); tmobjectTest(association, true, true); }
public void testLiteralType() throws InvalidQueryException, IOException { load("bug662.xtm"); TopicIF topic = getTopicById("history"); AssociationRoleIF role = (AssociationRoleIF) topic.getRoles().iterator().next(); String rid = role.getObjectId(); findNothing(OPT_TYPECHECK_OFF + "example-of(@" + rid + " : illustrated, $E : example)?"); }
public void testBothBoundTrue() throws InvalidQueryException, IOException { load("bb-test.ltm"); List matches = new ArrayList(); TopicIF teacher = getTopicById("larer"); AssociationRoleIF role = (AssociationRoleIF) teacher.getRoles().iterator().next(); AssociationIF assoc = role.getAssociation(); matches.add(new HashMap()); verifyQuery(matches, "association-role(@" + assoc.getObjectId() + ", @" + role.getObjectId() + ")?"); closeStore(); }
public void testBothBoundFalse() throws InvalidQueryException, IOException { load("bb-test.ltm"); List matches = new ArrayList(); TopicIF teacher = getTopicById("gdm"); Iterator it = teacher.getRoles().iterator(); AssociationRoleIF role = (AssociationRoleIF) it.next(); AssociationRoleIF role2 = (AssociationRoleIF) it.next(); AssociationIF assoc = role2.getAssociation(); verifyQuery(matches, "association-role(@" + assoc.getObjectId() + ", @" + role.getObjectId() + ")?"); closeStore(); }
@Override public void run(MasterTest mt) { AssociationRoleIF r = (AssociationRoleIF)topicmap.getObjectById(mt.objectId); TopicIF player = (TopicIF)topicmap.getObjectById(mt.value); assertTrue("Role player is not set" + player, player.equals(r.getPlayer())); assertTrue("Player role is not set", player.getRoles().contains(r)); } });
private void verifySingleTopicName(TopicIF topic, String name) { Assert.assertTrue("topic has spurious children", topic.getTypes().size() == 0 && topic.getRoles().size() == 0 && topic.getOccurrences().size() == 0); Assert.assertTrue("topic has wrong number of base names", topic.getTopicNames() .size() == 1); TopicNameIF basename = (TopicNameIF) topic.getTopicNames().iterator() .next(); Assert.assertTrue("wrong basename value: '" + basename.getValue() + "'", basename .getValue().equals(name)); Assert.assertTrue("basename has spurious children", basename.getVariants().size() == 0); Assert.assertTrue("basename has spurious themes", basename.getScope().size() == 0); }
public void testSpecificRole() throws InvalidQueryException, IOException { load("bb-test.ltm"); List matches = new ArrayList(); TopicIF teacher = getTopicById("larer"); AssociationRoleIF role = (AssociationRoleIF) teacher.getRoles().iterator().next(); AssociationIF assoc = role.getAssociation(); addMatch(matches, "ASSOC", assoc); verifyQuery(matches, "association-role($ASSOC, @" + role.getObjectId() + ")?"); closeStore(); }
@Override public void run(MasterTest mt) { AssociationRoleIF r = (AssociationRoleIF)topicmap.getObjectById(mt.objectId); TopicIF player = (TopicIF)topicmap.getObjectById(mt.value); assertTrue("Role player is set", r.getPlayer().getSubjectIdentifiers().contains(URILocator.create("player:cleared"))); assertTrue("Player roles is set", player.getRoles().isEmpty()); } });
public void testMergeDuplicateAssociations() throws IOException { TopicMapIF tm = ImportExportUtils.getReader(TestFileUtils.getTestInputFile("various", "merge-duplicate-assoc.ltm")).read(); LocatorIF base = tm.getStore().getBaseAddress(); TopicIF puccini1 = (TopicIF) tm.getObjectByItemIdentifier(base.resolveAbsolute("#puccini1")); TopicIF puccini2 = (TopicIF) tm.getObjectByItemIdentifier(base.resolveAbsolute("#puccini2")); MergeUtils.mergeInto(puccini1, puccini2); // the new puccini should have only a single place of birth; in // fact, only a single association assertTrue("Merge did not remove duplicate associations", puccini1.getRoles().size() == 1); }
public void testTopicRemovalPolicyRole() { TopicIF topic = builder.makeTopic(); TopicIF other = builder.makeTopic(); AssociationIF assoc = builder.makeAssociation(builder.makeTopic()); AssociationRoleIF role1 = builder.makeAssociationRole(assoc, builder.makeTopic(), topic); AssociationRoleIF role2 = builder.makeAssociationRole(assoc, builder.makeTopic(), other); topic.remove(); assertTrue("association not deleted", assoc.getTopicMap() == null); assertTrue("role1 not deleted", role1.getTopicMap() == null); assertTrue("role2 not deleted", role2.getTopicMap() == null); assertTrue("remaining topic has roles left", other.getRoles().size() == 0); }