Coverage Report - net.sourceforge.combean.graph.containers.statics.PathFromPredMapBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
PathFromPredMapBuilder
90%
9/10
100%
2/2
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.containers.statics;
 23  
 
 24  
 import net.sourceforge.combean.graph.containers.ListAsPath;
 25  
 import net.sourceforge.combean.interfaces.graph.Edge;
 26  
 import net.sourceforge.combean.interfaces.graph.Node;
 27  
 import net.sourceforge.combean.interfaces.graph.containers.NodeMap;
 28  
 import net.sourceforge.combean.interfaces.graph.containers.Path;
 29  
 import net.sourceforge.combean.interfaces.graph.prop.NeighborhoodGraphProp;
 30  
 
 31  
 /**
 32  
  * Static utility class for converting the predecessor map representation
 33  
  * of a path into the actual path.
 34  
  * 
 35  
  * @author schickin
 36  
  *
 37  
  */
 38  0
 public class PathFromPredMapBuilder {
 39  
     
 40  
     /**
 41  
      * Construct a path from a predecessor map.
 42  
      * 
 43  
      * @param g the graph which contains the path
 44  
      * @param predMap the predecessor map
 45  
      * @param target the last node of the path
 46  
      * @return the complete path specified by the last node and the chain of its
 47  
      * predecessors.
 48  
      */
 49  
     public static Path buildPathFromPredMap(NeighborhoodGraphProp g,
 50  
             NodeMap<Edge> predMap, Node target) {
 51  36
         ListAsPath path = new ListAsPath();
 52  36
         path.init(g);
 53  
         
 54  36
         path.setInitialNode(target);
 55  
         
 56  
         while (true) {
 57  135
             Edge edgeToPred = predMap.get(path.getFirstNode());
 58  135
             if (edgeToPred == null) {
 59  36
                 break;
 60  
             }
 61  99
             path.prependEdge(edgeToPred);
 62  99
         }
 63  
         
 64  36
         return path;
 65  
     }
 66  
 
 67  
 
 68  
 }