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 Collection<TopicIF> getRoleTypes() { Collection<TopicIF> result = new CompactHashSet<TopicIF>(); for (AssociationRoleIF role : this.<AssociationRoleIF>loadCollectionField(Association.LF_roles)) { TopicIF type = role.getType(); if (type != null) result.add(role.getType()); } return result; }
private static AssociationRoleIF extractRoleOfType(List roles, TopicIF rtype) { int length = roles.size(); for (int i=0; i < length; i++) { AssociationRoleIF r = (AssociationRoleIF)roles.get(i); if (ObjectUtils.equals(rtype, r.getType())) { roles.remove(i); return r; } } return null; }
/** * Gets the assoc types ordered. */ protected String[] getAssociationRoleTypesOrdered() { Collection roletypes = new ArrayList(); Iterator it = association.getRoles().iterator(); while (it.hasNext()) { String name = getName(((AssociationRoleIF)it.next()).getType()); roletypes.add(name); } return sortAlpha(roletypes); }
protected TopicIF getPlayer(AssociationIF assoc, TopicIF roleType) { Iterator<AssociationRoleIF> it = assoc.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF role = it.next(); if (roleType.equals(role.getType())) return role.getPlayer(); } return null; }
@Override public Collection<AssociationRoleIF> getRolesByType(TopicIF roletype) { Collection<AssociationRoleIF> result = new CompactHashSet<AssociationRoleIF>(); for (AssociationRoleIF role : this.<AssociationRoleIF>loadCollectionField(Association.LF_roles)) { if (role.getType() == roletype) result.add(role); } return result; }
@Override public Collection<AssociationRoleIF> getRolesByType(TopicIF roletype) { if (roletype == null) throw new NullPointerException("Role type must not be null."); CrossTopicMapException.check(roletype, this); Collection<AssociationRoleIF> result = new CompactHashSet<AssociationRoleIF>(); for (AssociationRoleIF role : this.<AssociationRoleIF>loadCollectionField(LF_roles)) if (role.getType() == roletype) result.add(role); return result; }
public static boolean hasBinaryAssociation(TopicIF player1, TopicIF aType, TopicIF rType1, TopicIF rType2) { for (AssociationRoleIF role : player1.getRolesByType(rType1, aType)) { AssociationIF assoc = role.getAssociation(); for (AssociationRoleIF role2 : assoc.getRoles()) if (!Objects.equals(role2, role) && role2.getType().equals(rType2)) return true; } return false; }
@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 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 static boolean hasBinaryAssociation(TopicIF player1, TopicIF aType, TopicIF rType1, TopicIF rType2) { for (AssociationRoleIF role : player1.getRolesByType(rType1, aType)) { AssociationIF assoc = role.getAssociation(); for (AssociationRoleIF role2 : assoc.getRoles()) if (ObjectUtils.different(role2, role) && role2.getType().equals(rType2)) return true; } return false; }
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 void processEvent(Object object, String event, Object new_value, Object old_value) { AssociationRoleIF arole = (AssociationRoleIF) object; // unregister old entry if (old_value != null) removeEntry(new ParameterArray(new Object[] { i(tm), i(old_value), i(arole.getType()) }), arole); // register new entry if (new_value != null) addEntry(new ParameterArray(new Object[] { i(tm), i(new_value), i(arole.getType()) }), arole); } }
@Override public void processEvent(Object object, String event, Object new_value, Object old_value) { AssociationRoleIF added = (AssociationRoleIF) new_value; // ignore event if player is null TopicIF player = added.getPlayer(); if (player == null) return; // register entry addEntry(new ParameterArray(new Object[] { i(tm), i(player), i(added.getType()) }), added); } }
@Override public void run(MasterTest mt) { AssociationRoleIF r = (AssociationRoleIF)topicmap.getObjectById(mt.objectId); assertTrue("Role type is set", r.getType().getSubjectIdentifiers().contains(URILocator.create("type:cleared"))); } });
@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); } } });
@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"); }