| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DFSNodeStackVisitor |
|
| 1.2857142857142858;1,286 |
| 1 | /* | |
| 2 | This file is part of Combean. | |
| 3 | ||
| 4 | Combean is free software; you can redistribute it and/or modify | |
| 5 | it under the terms of the GNU General Public License as published by | |
| 6 | the Free Software Foundation; either version 2 of the License, or | |
| 7 | (at your option) any later version. | |
| 8 | ||
| 9 | Combean is distributed in the hope that it will be useful, | |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 | GNU General Public License for more details. | |
| 13 | ||
| 14 | You should have received a copy of the GNU General Public License | |
| 15 | along with Combean; if not, write to the Free Software | |
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 17 | */ | |
| 18 | /* | |
| 19 | * Created on 20.02.2005 | |
| 20 | * | |
| 21 | */ | |
| 22 | package net.sourceforge.combean.graph.alg.traversal; | |
| 23 | ||
| 24 | import net.sourceforge.combean.graph.containers.StackAsNodeStack; | |
| 25 | import net.sourceforge.combean.interfaces.graph.Graph; | |
| 26 | import net.sourceforge.combean.interfaces.graph.Node; | |
| 27 | import net.sourceforge.combean.interfaces.graph.containers.NodeStack; | |
| 28 | ||
| 29 | /** | |
| 30 | * Maintains a stack of currently opened nodes during the DFS. | |
| 31 | * (i.e. the stack of nodes that one would have during a classic recursive | |
| 32 | * implementation of the DFS). | |
| 33 | * | |
| 34 | * @author schickin | |
| 35 | * | |
| 36 | */ | |
| 37 | public class DFSNodeStackVisitor extends DFSNodeNumberingVisitor { | |
| 38 | ||
| 39 | 15 | private NodeStack stack = null; |
| 40 | ||
| 41 | /** | |
| 42 | * constructor. | |
| 43 | */ | |
| 44 | public DFSNodeStackVisitor() { | |
| 45 | 15 | super(); |
| 46 | 15 | this.stack = null; |
| 47 | 15 | } |
| 48 | ||
| 49 | /** | |
| 50 | * @return Returns the stack. | |
| 51 | */ | |
| 52 | public final NodeStack getStack() { | |
| 53 | 3 | return this.stack; |
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * Set the stack which shall be used. If left unset, an ordinary | |
| 58 | * java.util.Stack is used. | |
| 59 | * | |
| 60 | * @param stack The stack to set. | |
| 61 | */ | |
| 62 | public final void setStack(NodeStack stack) { | |
| 63 | 0 | this.stack = stack; |
| 64 | 0 | } |
| 65 | ||
| 66 | /* (non-Javadoc) | |
| 67 | * @see net.sourceforge.combean.interfaces.graph.alg.traverse.TraversalVisitor#init(net.sourceforge.combean.interfaces.graph.Graph) | |
| 68 | */ | |
| 69 | public void init(Graph g) { | |
| 70 | 15 | super.init(g); |
| 71 | 15 | if (this.stack == null) { |
| 72 | 15 | this.stack = new StackAsNodeStack(); |
| 73 | } | |
| 74 | 15 | } |
| 75 | ||
| 76 | /* (non-Javadoc) | |
| 77 | * @see net.sourceforge.combean.interfaces.graph.alg.traverse.TraversalVisitor#initLocal(net.sourceforge.combean.interfaces.graph.Graph, net.sourceforge.combean.interfaces.graph.Node) | |
| 78 | */ | |
| 79 | public void initLocal(Graph g, Node startNode) { | |
| 80 | 3 | super.initLocal(g, startNode); |
| 81 | 3 | if (this.stack == null) { |
| 82 | 0 | this.stack = new StackAsNodeStack(); |
| 83 | } | |
| 84 | 3 | } |
| 85 | /* (non-Javadoc) | |
| 86 | * @see net.sourceforge.combean.interfaces.graph.alg.traverse.TraversalVisitor#visitNode(net.sourceforge.combean.interfaces.graph.Node) | |
| 87 | */ | |
| 88 | public void visitNode(Node v) { | |
| 89 | 93 | this.stack.push(v); |
| 90 | 93 | super.visitNode(v); |
| 91 | 93 | } |
| 92 | ||
| 93 | /* (non-Javadoc) | |
| 94 | * @see net.sourceforge.combean.interfaces.graph.alg.traverse.DFSVisitor#leaveNode(net.sourceforge.combean.interfaces.graph.Node) | |
| 95 | */ | |
| 96 | public void leaveNode(Node v) { | |
| 97 | 78 | super.leaveNode(v); |
| 98 | 78 | this.stack.pop(); |
| 99 | 78 | } |
| 100 | } |