Coverage Report - net.sourceforge.combean.graph.alg.traversal.ConstructPredMapVisitor
 
Classes in this File Line Coverage Branch Coverage Complexity
ConstructPredMapVisitor
88%
21/24
75%
3/4
0
 
 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.08.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.graph.alg.traversal;
 23  
 
 24  
 import net.sourceforge.combean.graph.containers.NodeMapAdvisor;
 25  
 import net.sourceforge.combean.interfaces.graph.Edge;
 26  
 import net.sourceforge.combean.interfaces.graph.Graph;
 27  
 import net.sourceforge.combean.interfaces.graph.Node;
 28  
 import net.sourceforge.combean.interfaces.graph.alg.traverse.TraversalVisitor;
 29  
 import net.sourceforge.combean.interfaces.graph.containers.NodeMap;
 30  
 import net.sourceforge.combean.interfaces.graph.prop.NeighborhoodGraphProp;
 31  
 
 32  
 /**
 33  
  * @author schickin
 34  
  *
 35  
  */
 36  
 public class ConstructPredMapVisitor extends IdleTraversalVisitor implements
 37  
         TraversalVisitor {
 38  
     
 39  27
     private NodeMap<Edge> predMap = null;
 40  
     
 41  27
     private NeighborhoodGraphProp neigh = null;
 42  
     
 43  27
     private Node target = null;
 44  27
     private boolean targetReached = false;
 45  
 
 46  
     /**
 47  
      * constructor 
 48  
      */
 49  
     public ConstructPredMapVisitor() {
 50  27
         super();
 51  27
     }
 52  
 
 53  
     /**
 54  
      * @return Returns the predMap.
 55  
      */
 56  
     public final NodeMap<Edge> getPredMap() {
 57  27
         return this.predMap;
 58  
     }
 59  
     
 60  
     /**
 61  
      * @param predMap The predMap to set.
 62  
      */
 63  
     public final void setPredMap(NodeMap<Edge> predMap) {
 64  0
         this.predMap = predMap;
 65  0
     }
 66  
     
 67  
     /* (non-Javadoc)
 68  
      * @see net.sourceforge.combean.interfaces.graph.alg.traverse.TraversalVisitor#init(net.sourceforge.combean.interfaces.graph.Graph)
 69  
      */
 70  
     public void init(Graph g) {
 71  27
         this.neigh = (NeighborhoodGraphProp) g;
 72  27
         if (this.predMap == null) {
 73  27
             this.predMap = NodeMapAdvisor.getFastestNodeMap(g);
 74  
         }
 75  27
         this.predMap.init(g);
 76  27
     }
 77  
 
 78  
     /* (non-Javadoc)
 79  
      * @see net.sourceforge.combean.interfaces.graph.alg.traverse.TraversalVisitor#initLocal(net.sourceforge.combean.interfaces.graph.Graph, net.sourceforge.combean.interfaces.graph.Node)
 80  
      */
 81  
     public void initLocal(Graph g, Node startNode) {
 82  27
         init(g);
 83  27
     }
 84  
 
 85  
     /* (non-Javadoc)
 86  
      * @see net.sourceforge.combean.interfaces.graph.alg.traverse.TraversalVisitor#openNeighbor(net.sourceforge.combean.interfaces.graph.Edge, net.sourceforge.combean.interfaces.graph.Node)
 87  
      */
 88  
     public void openNeighbor(Edge e, Node from) {
 89  117
         Node to = this.neigh.getOtherNode(e, from); 
 90  117
         this.predMap.put(to, e);
 91  117
         if (to.equals(this.target)) {
 92  18
             this.targetReached = true;
 93  
         }
 94  117
     }
 95  
 
 96  
     /* (non-Javadoc)
 97  
      * @see net.sourceforge.combean.interfaces.graph.alg.traverse.TraversalVisitor#readyToTerminate()
 98  
      */
 99  
     public boolean readyToTerminate() {
 100  0
         return this.targetReached;
 101  
     }
 102  
     
 103  
     /**
 104  
      * Set target node where the construction of the predecessor map
 105  
      * shall terminate. If no target node is set, all reachable nodes
 106  
      * will be visited.
 107  
      * 
 108  
      * @param target The target to set.
 109  
      */
 110  
     public final void setTarget(Node target) {
 111  27
         this.target = target;
 112  27
     }
 113  
 }