AssociationSanity ts = new AssociationSanity(tm); ts.traverse(); HashMap duplicateAssocs = ts.getDuplicateAssociations(); HashMap numberOfDuplicates = ts.getNumberOfDuplicates();
public void traverse() throws NullPointerException { assocs = tm.getAssociations(); Iterator it = assocs.iterator(); while (it.hasNext()) { AssociationIF temp = (AssociationIF)it.next(); String key = createKey(temp); if (checkedAssociations.containsKey(key)) { //This association already exist. //Update number of occurrences and put it back in the //HashMap. Integer tempint = (Integer)numberOfDuplicates.get(key); if (tempint == null){ //first occurrences of this duplicate Association. numberOfDuplicates.put(key, new Integer(2)); } else { //update the number of occurrences for this duplicate assoc. int number = tempint.intValue() + 1; numberOfDuplicates.put(key, new Integer(number)); } //add the duplicate assoc to a HashMap. duplicateAssociations.put(key, temp); } else { //This association has no duplicates - (yet). checkedAssociations.put(key, temp); } } }
assocname = getTopicId(aif.getType()); } catch (NullPointerException e) { assocname = "null"; retur += "$" +rolenames[i] + "$" + getTopicId((TopicIF)types.get(rolenames[i])); } else { retur += "$" +rolenames[i] + "$null";
/** * ******************************************* * methods used to test the sanity checker. * ******************************************* */ public void testDuplicateAssociations() { AssociationSanity test = new AssociationSanity(tm); test.traverse(); assertTrue("type checking (getDuplicateAssociations)", test.getDuplicateAssociations() instanceof HashMap); assertTrue("type checking (getNumberOfDuplicates)", test.getNumberOfDuplicates() instanceof HashMap); assertEquals(1, test.getDuplicateAssociations().size()); }