// util.beh // // This file contains various utillity functions which are used throughout // the program. Cd_graph { {{ // Returns the Adjacency represented by id. Returns null if no match is // found. public Adjacency search(Ident id) { TraversalGraph tg = new TraversalGraph( "from Cd_graph bypassing ParentList to Adjacency", Main.cg ); return (Adjacency) tg.traverse(this, new FindClassVisitor(id)); } }} } // Visitor class which implements the Cd_graph::search() method. Searches // the Cd_graph for the Adjacency represented by id. The variable rv // stores the return value. FindClassVisitor { {{ public FindClassVisitor(Ident id) { super(); set_rv(null); set_id(id); } public void before(Adjacency a) { if (id.equals(a.fetchIdent())) rv = a; } public Object getReturnValue() { return rv; } }} } Adjacency { {{ // Returns an Ident representation of the Adjacency. public Ident fetchIdent() { TraversalGraph tg = new TraversalGraph( "from Adjacency bypassing {Neighbors, Vertex_Comma_list} to " + Main.IdentLoc, Main.cg ); return (Ident) tg.fetch(this); } // Returns an Adjacency_List consisting of all immediate superclasses. // If there are no superclasses defined in the class dictionary // then null is returned. public Adjacency_List fetchParents() { TraversalGraph tg = new TraversalGraph( "from Adjacency to-stop Adjacency_List", Main.cg ); return (Adjacency_List) tg.fetch(this); } }} } Term { {{ // Returns the Ident representation of the Term object. public Ident fetchIdent() { // This traversal does not work, not sure why... Will just fetch the // Ident directly for now... // // TraversalGraph tg = new TraversalGraph( // "from Term only-through Vertex to " + Main.IdentLoc, // Main.cg // ); // return (Ident) tg.fetch(this); return vertex.get_vertex_name(); } }} }