@Override public Set<Topic> getRoleTypes() { return topicMap.wrapSet(wrapped.getRoleTypes()); }
/** * Filter out the topics that are used to type association roles. */ private SortedSet<TopicIF> roleTypes(Collection<AssociationIF> associations, Collection<TopicIF> topicInstances) { SortedSet<TopicIF> roleTypes = new TreeSet<TopicIF>(topicComparator); Iterator<AssociationIF> it = associations.iterator(); while (it.hasNext()) { Iterator<TopicIF> typesIt = it.next().getRoleTypes().iterator(); while (typesIt.hasNext()) { TopicIF currentType = typesIt.next(); if (topicInstances.remove(currentType)) roleTypes.add(currentType); } } return roleTypes; }
@Get public Collection<TopicIF> getRoleTypes() { AssociationIF association = Parameters.ID.withExpected(AssociationIF.class).optional(this); if (association == null) { return getIndex(ClassInstanceIndexIF.class).getAssociationRoleTypes(); } else { return association.getRoleTypes(); } } }
public void testRoleTypes() { assertTrue("role type set not empty initially", assoc.getRoleTypes().size() == 0); AssociationRoleIF role2 = builder.makeAssociationRole(assoc, builder.makeTopic(), builder.makeTopic()); // builder adds role to assoc assertTrue("the null type is being counted as a role type", assoc.getRoleTypes().size() == 1); TopicIF type = builder.makeTopic(); AssociationRoleIF role = builder.makeAssociationRole(assoc, type, builder.makeTopic()); assertTrue("role type lost", assoc.getRoleTypes().size() == 2); assertTrue("role type identity lost", assoc.getRoleTypes().contains(type)); AssociationRoleIF role3 = builder.makeAssociationRole(assoc, type, builder.makeTopic()); assertTrue("duplicate role types returned", assoc.getRoleTypes().size() == 2); }