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; }
@Override public int compare(Object o1, Object o2) { AssociationRoleIF role1 = (AssociationRoleIF) o1; AssociationRoleIF role2 = (AssociationRoleIF) o2; int cmp = compareTopic(role1.getPlayer(), role2.getPlayer()); if (cmp == 0) cmp = compareTopic(role1.getType(), role2.getType()); // No need to compare the parent assocaitions since this comparator only // compares roles within one assocaition. return cmp; } }
public void changeRank(TopicIF realTopic, boolean up) { TopicIF topic = tmConfig.getConfigTopic(realTopic); // Get the relevant roles played by 'topic' and 'swappedTopic', i.e. the // topic is should be swapped with. AssociationRoleIF outerRole = getRankRole(topic, !up); AssociationRoleIF innerRole = getRankRole(topic, up); AssociationIF association = getRankAssociation(innerRole); AssociationRoleIF newInnerRole = getRankRole(association, up); TopicIF swappedTopic = newInnerRole.getPlayer(); AssociationRoleIF newOuterRole = getRankRole(swappedTopic, up); // Replace 'topic's position by 'swappedTopic'. outerRole.setPlayer(swappedTopic); innerRole.setPlayer(swappedTopic); // Replace 'swappedTopic's position by 'topic'. newOuterRole.setPlayer(topic); newInnerRole.setPlayer(topic); }
public static String toString(String impl, AssociationRoleIF role) { String id = UNASSIGNED; try { if (role.getTopicMap() != null) id = role.getObjectId(); return "[" + impl + ", " + id + ", type: " + role.getType() + "]"; } catch (Throwable t) { return "[" + impl + ", " + role.getObjectId() + "!]"; } }
@Override public int compare(Object o1, Object o2) { AssociationRoleIF role1 = (AssociationRoleIF) o1; AssociationRoleIF role2 = (AssociationRoleIF) o2; int cmp = compareTopic(role1.getPlayer(), role2.getPlayer()); if (cmp == 0) cmp = compareTopic(role1.getType(), role2.getType()); if (cmp == 0) cmp = compareAssociation(role1.getAssociation(), role2.getAssociation()); return cmp; } }
AssociationIF assoc = ar.getAssociation(); log.trace(" =P " + topic + " " + assoc); AssociationRoleIF or = extractRoleOfType(oroles, rtypes[i]); if (or != null) { if (ObjectUtils.different(or.getPlayer(), players[i])) or.setPlayer(players[i]); log.trace(" =R " + players[i] + " :" + rtypes[i]); } else { for (int i=0; i < oroles.size(); i++) { AssociationRoleIF or = (AssociationRoleIF)oroles.get(i); log.trace(" -R " + or.getPlayer() + " :" + or.getType()); TopicIF player = or.getPlayer(); or.remove(); if (player != null) ctx.characteristicsChanged(player);
AssociationIF as = ar.getAssociation(); AssociationRoleIF or = null; Iterator<AssociationRoleIF> iter = as.getRoles().iterator(); TopicIF springfield = or.getPlayer(); or.setPlayer(or.getType()); topicmap.getStore().commit(); assertTrue("bart was not registered as modified", listener.snapshots.contains(bart.getObjectId())); ar.addItemIdentifier(URILocator.create("x:source-locator")); afterTest(); ar.removeItemIdentifier(URILocator.create("x:source-locator")); afterTest(); ar.setType(other); afterTest(); xr.remove(); afterTest(); xr.getAssociation().remove(); afterTest();
/** * INTERNAL: Grabs the topic playing the role in the given association role * * @param object the given object; AssociationRoleIF * @return object which is the role player; an object implementing TopicIF */ @Override public TopicIF grab(AssociationRoleIF object) { return object.getPlayer(); }
@Override public Collection<AssociationIF> getAssociations() { Set<AssociationIF> assocs = new HashSet<AssociationIF>(); for (AssociationRoleIF role : roles) { assocs.add(role.getAssociation()); } return Collections.unmodifiableSet(assocs); }
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(); }
private static void copyReferencedTopics(TopicMapIF tm, TopicIF source) { Iterator<AssociationRoleIF> it = source.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF role = it.next(); AssociationIF assoc = role.getAssociation(); Iterator<AssociationRoleIF> it2 = assoc.getRoles().iterator(); while (it2.hasNext()) { AssociationRoleIF other = it2.next(); TopicIF refd = other.getPlayer(); if (refd != source) copyTopic(tm, refd); } } }
@Test public void testAssociationRole() throws Exception { AssociationIF assoc = tm1.getBuilder().makeAssociation(tm1.getBuilder().makeTopic()); AssociationRoleIF role = tm1.getBuilder().makeAssociationRole(assoc, foo1, foo1); role.setReifier(foo1); concurrentCommit(); // verify no inconsistenties were created check(tm1, role.getType(), "Association role", "type"); check(tm1, role.getPlayer(), "Association role", "player"); check(tm1, role.getReifier(), "Association role", "reifier"); }
@Override public void run(MasterTest mt) { AssociationRoleIF r = (AssociationRoleIF)topicmap.getObjectById(mt.objectId); assertTrue("Added role not found", r != null); if (testInitialProperties) { assertTrue("Source locators is set", r.getItemIdentifiers().isEmpty()); assertTrue("Type is set", r.getType() == null); assertTrue("Player is set", r.getPlayer() == null); } } });
private static AssociationRoleIF extractRoleOfType(List<AssociationRoleIF> roles, TopicIF rtype) { int length = roles.size(); for (int i=0; i < length; i++) { AssociationRoleIF r = roles.get(i); if (Objects.equals(rtype, r.getType())) { roles.remove(i); return r; } } return null; }
@Override public void run() { AssociationRoleIF r = getAssociationRole(); TopicIF oldPlayer = r.getPlayer(); TopicIF player = builder.makeTopic(); // create player player.addSubjectIdentifier(URILocator.create("player:cleared")); r.setPlayer(player); this.objectId = r.getObjectId(); this.value = oldPlayer.getObjectId(); } });
r1E.getAssociation().setType(at2E); r1E.setType(rt3E); assertTrue("p1E.rolesByType(rt1,at1).size is not 0.", p1E.getRolesByType(rt1E, at1E).size() == 0); assertTrue("p1E.rolesByType(rt1,at2).size is not 0.", p1E.getRolesByType(rt1E, at2E).size() == 0); r1B.getAssociation().setType(at1B); assertTrue("p1B.rolesByType(rt3,at1).size is not 1.", p1B.getRolesByType(rt3B,at1B).size() == 1); assertTrue("p1B.rolesByType(rt3,at2).size is not 0.", p1B.getRolesByType(rt3B,at2B).size() == 0); assertTrue("p1B.rolesByType(rt1,at2).size is not 0.", p1B.getRolesByType(rt1B,at2B).size() == 0); r1B.setType(rt1B); assertTrue("p1B.rolesByType(rt3,at1).size is not 0.", p1B.getRolesByType(rt3B,at1B).size() == 0); assertTrue("p1B.rolesByType(rt3,at2).size is not 0.", p1B.getRolesByType(rt3B,at2B).size() == 0); AssociationIF aB = r1B.getAssociation(); r1B.remove(); assertTrue("p1B.rolesByType(rt3,at1).size is not 0.", p1B.getRolesByType(rt3B,at1B).size() == 0); assertTrue("p1B.rolesByType(rt3,at2).size is not 0.", p1B.getRolesByType(rt3B,at2B).size() == 0);
@Override public AssociationRoleIF makeAssociationRole(AssociationIF assoc, TopicIF role_type, TopicIF player) { if (assoc == null) throw new NullPointerException(MSG_ASSOCATION_NOT_NULL); if (role_type == null) throw new NullPointerException(MSG_ASSOCIATION_ROLE_TYPE_NOT_NULL); if (player == null) throw new NullPointerException(MSG_ASSOCIATION_ROLE_PLAYER_NOT_NULL); CrossTopicMapException.check(assoc, this.tm); CrossTopicMapException.check(role_type, this.tm); CrossTopicMapException.check(player, this.tm); AssociationRoleIF assocrl = new AssociationRole(tm); ((Association)assoc).addRole(assocrl); assocrl.setType(role_type); assocrl.setPlayer(player); return assocrl; }
public void perform(ActionParametersIF params, ActionResponseIF response) { AssociationRoleIF role = (AssociationRoleIF) params.get(0); //! TopicIF player = (TopicIF) params.get(1); role.setPlayer(null); // don't really need the topic, actually }
/** * PUBLIC: Merges the source role into the target role. The two * roles must be in the same topic map, but need not have the same * parent association. If the associations are not the same, they * are merged, provided that they are equal; if they are not equal, * a ConstraintViolationException is thrown. It is assumed (but not * verified) that the two roles are actually equal. * @since 5.1.0 */ public static void mergeInto(AssociationRoleIF target, AssociationRoleIF source) { if (target.getAssociation() != source.getAssociation()) { String key1 = KeyGenerator.makeAssociationKey(target.getAssociation()); String key2 = KeyGenerator.makeAssociationKey(source.getAssociation()); if (!key1.equals(key2)) throw new ConstraintViolationException("Cannot merge roles in different " + " associations"); mergeInto(target.getAssociation(), source.getAssociation()); } else { mergeIntoChecked(target, source); source.remove(); } }
AssociationRoleIF role = riter.next(); int matchIndex = -1; TopicIF roleType = role.getType(); for (int i=0; i < size; i++) { if (roleMatches[i] == null) { RoleType fromType = roleTypesFrom.get(i); RoleType toType = roleTypesTo.get(i); if (role.getType().equals(fromType.getTopicIF())) { if (!role.getType().equals(toType.getTopicIF())) role.setType(toType.getTopicIF());