/** * Gets the number of times this association occurres in the topicmap. */ public int getNumberOfOccurrences(String key) { return ((InternalAssociation)associations.get(key)).getNumberOfOccurrences(); }
/** * Adds an association to the collection of assocation with the same * types, and roles. */ protected void addAssociation(AssociationIF association) { associations.add(association); addAssociationRoles(association); }
public String[] getAssociationDetails(String key, AssociationIF association) { if (key == null || !associations.containsKey(key)) return null; return ((InternalAssociation)associations.get(key)).getAssociationDetails(association); }
TopicCounter test = new TopicCounter(tm); test.count(); } catch (NullPointerException e) { fail("Cought an \"unexpected\" null pointer exception"); assertTrue("check (getTopicTypes)", test.getTopicTypes() instanceof HashMap); assertTrue("check (getAssociationTypes)", test.getAssociationTypes() instanceof HashMap); assertTrue("check (getOccurrenceTypes)", test.getOccurrenceTypes() instanceof HashMap); test.getNumberOfTopics() == tm.getTopics().size()); assertEquals(15, test.getNumberOfTopics()); test.getNumberOfAssociations() == tm.getAssociations().size()); assertEquals(3, test.getNumberOfAssociations()); assertEquals(3, test.getNumberOfOccurrences()); test.getNumberOfOccurrences() != 0); assertTrue("Variable numberOfAssociations not null", test.getNumberOfAssociations() != 0); assertTrue("Variable numberOfOcurrences not null", test.getNumberOfOccurrences() != 0); test = new TopicCounter(null);
public void testNoTypeCount() { NoTypeCount test = new NoTypeCount(tm); test.traverse(); //Type checking. assertTrue("check type (getNoTypeTopics)", test.getNoTypeTopics() instanceof Collection); // note: comparing with previous version: // +1 because names must have a type since 5.1.0 and this type topic has no type assertEquals(11, test.getNoTypeTopics().size()); assertTrue("check type (getNoTypeAssociations)", test.getNoTypeAssociations() instanceof Collection); assertEquals(0, test.getNoTypeAssociations().size()); assertTrue("check type (getNoTypeOccurrences)", test.getNoTypeOccurrences() instanceof Collection); assertEquals(0, test.getNoTypeOccurrences().size()); //set test.tm = null test = new NoTypeCount(null); try { test.traverse(); fail("Should raise a NullPointerException"); } catch (NullPointerException e) { //Test succesfull } }
/** * Handles all the assciation dependecies. */ protected void countAssociationDep() { TopicAssocDep topicassocdep = new TopicAssocDep(tm); //HashMap assocTypes; //Print out the result. print("\n\n\n Association Dependencies: \n\n\n"); Iterator it = topicassocdep.getAssociations().iterator(); while (it.hasNext()) { String a = (String)it.next(); StringTokenizer st = new StringTokenizer(a, "$"); String string = st.nextToken(); print("\n\nThe association \"" + string + "\" has roles:\n"); while (st.hasMoreTokens()) { string = st.nextToken(); print("\"" + string+ "\"\n"); } print("and occurs " + topicassocdep.getNumberOfOccurrences(a) + " times\n"); } }//end of countAssociationDep
private void traverse(Collection assocs) { Iterator it = assocs.iterator(); while (it.hasNext()) { AssociationIF temp = (AssociationIF)it.next(); String key = createKey(temp); InternalAssociation assoc; if (associations.containsKey(key)) { assoc = (InternalAssociation)associations.get(key); assoc.increment(); } else { assoc = new InternalAssociation(temp); associations.put(key, assoc); } assoc.addAssociation(temp); } }
public void testTopicAssocDep() { TopicAssocDep test = new TopicAssocDep(tm); //Type checking assertTrue("check type (getAssociations()) with 'foo'", test.getAssociations() instanceof Collection); try { test = new TopicAssocDep(null); // test.getAssociationDependencies(); // traverse() is now executed in constructor fail("Should raise a NullPointerException"); } catch (NullPointerException e) { //Test succesfull } }
/** * Gets the association roles ordered aplhabetically */ public String[] getAssociationRoleTypesOrdered(String key) { if (key == null || !associations.containsKey(key)) return null; return ((InternalAssociation)associations.get(key)).getAssociationRoleTypesOrdered(); }
/** * Gets the id for the association type. */ public String getAssociationTypeId(String key) { if (key == null || !associations.containsKey(key)) return NULL; return ((InternalAssociation)associations.get(key)).getAssociationTypeId(); }
/** * Gets the name of the association. */ public String getAssociationType(String key) { if (key == null || !associations.containsKey(key)) return NULL; return ((InternalAssociation)associations.get(key)).getAssociationType(); }
/** * Return a hashmap containg the id and the name of all the topictypes for all the * topics that play in this association. */ public HashMap getAssociationRoles(String key) { if (key == null || !associations.containsKey(key)) return null; return ((InternalAssociation)associations.get(key)).getAssociationRoles(); }
/** * Returns a hashmap containg the id of the assocrltype, and the name of assocrltype */ public HashMap getAssociationRoleTypes(String key) { if (key == null || !associations.containsKey(key)) return null; return ((InternalAssociation)associations.get(key)).getAssociationRoleTypes(); }
public Collection makeStrings(Collection topics) { Collection result = new ArrayList(); Iterator it = topics.iterator(); while (it.hasNext()) { TopicIF topic = (TopicIF)it.next(); result.add(getName(topic)); } return result; }
public TopicAssocDep(TopicMapIF tm) throws NullPointerException { this.tm = tm; associations = new HashMap(); traverse(tm.getAssociations()); }
InternalAssociation(AssociationIF association) { this.associationtype = association.getType(); this.association = association; roleTypes = addAssocRoleTypes(association); number_of_assocs = 1; assocRoles = new HashMap(); associations = new ArrayList(); //roles = getAssociationRoleTypesOrdered(); }
/** * 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); }
/** * Returns a Collection of the different associations that have this associationtype. */ public Collection getAssociationDetails(String key) { if (key == null || !associations.containsKey(key)) return null; return ((InternalAssociation)associations.get(key)).getAssociationDetails(); }
/** * Returns the players of of this association ordred by the role types. */ protected String[] getAssociationDetails(AssociationIF association) { String[] result = new String[association.getRoles().size()]; Iterator it = association.getRoles().iterator(); while (it.hasNext()) { AssociationRoleIF role = (AssociationRoleIF)it.next(); String name = getName(role.getType()); roles = getAssociationRoleTypesOrdered(); for (int i = 0; i < roles.length; i++) { // Inserts the correct player name and id in the correct alphabetical order. if (name.equals(roles[i]) && result[i] == null) { result[i] = getName(role.getPlayer()) + "$" + role.getPlayer().getObjectId(); } } } return result; }