Cd_graph { {{ public HashMap commonPartMap; public void flatten(final ClassGraph cg) { /** 1. Go to concrete classes 2. For each concrete class, find a list of superclasses 3. For each superclass in the list, append the parts to the concrete class 4. Remove common parts from the abstract classes **/ /* The HashMap association of key: AbstractClass (String) to value: CommonParts (Any_vertex_List) */ commonPartMap = this.getCommonPartMap(cg); Strategy s = new Strategy("from Cd_graph bypassing Alternat_ns to Any_vertex_List"); cg.traverse(this, s, new Visitor() { public Ident currentAdj; // The current adjacency being examined public void before(Adjacency host){currentAdj = host.get_source().get_vertex_name(); } public void before (Any_vertex_List host) { // parents for this adjacency Vector parents = new Vector(); String tempChild = currentAdj.toString(); String tempParent = getParent( tempChild ); while (tempParent != null) { parents.add(tempParent); tempParent = getParent( tempParent ); // Get the parent of the parent } // For each parent, add their common parts Iterator i = parents.iterator(); Any_vertex_List partsToAdd; // Temp holder for common parts while (i.hasNext()) { String currParent = (String) i.next(); // Get a pointer to the common parts for the current parent partsToAdd = ((Any_vertex_List) commonPartMap.get(currParent)); while ( partsToAdd.hasMoreElements() ) { host.push((Any_vertex) partsToAdd.nextElement() ); } } // End while loop } }); // End traverse /* Remove all common parts */ this.removeCommonParts(cg); } // End flatten public HashMap getCommonPartMap(final ClassGraph cg) { // Returns a hashmap of // key: String of the abstract classname // value: List of its common parts Strategy s = new Strategy("from Cd_graph through Alternat_ns to Any_vertex_List"); return (HashMap) cg.traverse(this, s, new Visitor() { public HashMap commonParts; public Ident currentAdj; // The current adjacency being examined public void start() { commonParts = new HashMap(); } public void before(Adjacency host){currentAdj = host.get_source().get_vertex_name();} public void before (Any_vertex_List host) { // Add the common parts to the Map commonParts.put( currentAdj.toString(), host ); } public Object getReturnValue(){return commonParts;} }); // End traverse }// End getCommonPartMap() public void removeCommonParts(final ClassGraph cg) { // Removes all common parts of abstract classes. // for use with the flattening algorithm Strategy s = new Strategy("from Cd_graph through Alternat_ns to Any_vertex_List"); cg.traverse(this, s, new Visitor() { public void before (Any_vertex_List host) { host.set_first(null); } }); // End traverse }// End removeCommonParts() }} }