01: /*
02: * Created on Nov 21, 2003
03: *
04: * To change the template for this generated file go to
05: * Window>Preferences>Java>Code Generation>Code and Comments
06: */
07: package org.hammurapi.inspectors.metrics.callertrace;
08:
09: import java.util.Enumeration;
10: import java.util.Vector;
11:
12: import org.apache.log4j.Logger;
13:
14: /**
15: * @author mucbj0
16: *
17: * To change the template for this generated type comment go to
18: * Window>Preferences>Java>Code Generation>Code and Comments
19: */
20: public class DepthFirstSearch implements SearchMethod {
21: private static Logger logger = Logger
22: .getLogger(AdjacencyMatrix.class.getName());
23: private AdjacencyMatrix adjacencyMatrix = null;
24: private TraceList resultTraceList = null;
25:
26: //!! should be
27: public TraceList extractTraceList(Object nodeA) {
28: return null;
29: }
30:
31: // not implemented yet
32: public TraceList extractTraceListForKey(String nodeA) {
33: return null;
34: }
35:
36: public Vector traverseFor(Object nodeA) {
37: Vector vc = new Vector();
38: vc.add(nodeA);
39: String successor = this .visitLeftSuccessorsOf(nodeA);
40: logger.info("Found: " + successor);
41: if (!"".equals(successor)) {
42: vc.addAll(traverseFor(successor));
43: }
44: return vc;
45: }
46:
47: /*
48: * Sideeffect: set visited Flag
49: */
50: public String visitLeftSuccessorsOf(Object nodeA) {
51: logger.debug("-> visitLeftSuccessorsOf: " + nodeA);
52: String successor = "";
53: Enumeration enum = adjacencyMatrix.getAllKeys();
54: while (enum.hasMoreElements()) {
55: Object key = (Object) enum.nextElement();
56: Object foundNodeA = adjacencyMatrix.extractStartingNode(key);
57: logger.debug("foundNodeA: " + foundNodeA);
58: if (foundNodeA.equals(nodeA) && !adjacencyMatrix.isVisited(key)) {
59: adjacencyMatrix.setVisitFlag(key);
60: return adjacencyMatrix.extractSuccessorNode(key);
61: }
62: }
63: return successor;
64: }
65:
66: /**
67: * @return Returns the adjacencyMatrix.
68: */
69: public AdjacencyMatrix getAdjacencyMatrix() {
70: return adjacencyMatrix;
71: }
72:
73: /**
74: * @param adjacencyMatrix The adjacencyMatrix to set.
75: */
76: public void setAdjacencyMatrix(AdjacencyMatrix adjacencyMatrix) {
77: this .adjacencyMatrix = adjacencyMatrix;
78: }
79:
80: /**
81: * @return Returns the resultTraceList.
82: */
83: public TraceList getResultTraceList() {
84: return resultTraceList;
85: }
86:
87: /**
88: * @param resultTraceList The resultTraceList to set.
89: */
90: public void setResultTraceList(TraceList resultTraceList) {
91: this.resultTraceList = resultTraceList;
92: }
93: }
|