Coverage Report - net.sourceforge.combean.graph.prop.statics.GraphStringifier
 
Classes in this File Line Coverage Branch Coverage Complexity
GraphStringifier
0%
0/39
0%
0/6
2
 
 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 17.04.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.graph.prop.statics;
 23  
 
 24  
 import net.sourceforge.combean.interfaces.graph.EdgeIterator;
 25  
 import net.sourceforge.combean.interfaces.graph.Graph;
 26  
 import net.sourceforge.combean.interfaces.graph.Node;
 27  
 import net.sourceforge.combean.interfaces.graph.NodeIterator;
 28  
 import net.sourceforge.combean.interfaces.graph.containers.FixedPath;
 29  
 import net.sourceforge.combean.interfaces.graph.prop.GlobalNodesGraphProp;
 30  
 import net.sourceforge.combean.interfaces.graph.prop.OutgoingEdgeNeighborhoodGraphProp;
 31  
 
 32  
 /**
 33  
  * Utilitiy class which converts graphs and substructures of graphs into
 34  
  * human-readable string representations (for debugging purposes)
 35  
  * 
 36  
  * @author schickin
 37  
  *
 38  
  */
 39  0
 public class GraphStringifier {
 40  
 
 41  
     /**
 42  
      * Convert a path to a string
 43  
      * 
 44  
      * @param path the path to be converted
 45  
      * @return a string representation of path
 46  
      */
 47  
     public static String convertToString(FixedPath path) {
 48  0
         StringBuffer result = new StringBuffer();
 49  0
         result.append("path {");
 50  0
         NodeIterator itPathNodes = path.getNodeIterator();
 51  0
         EdgeIterator itPathEdges = path.getEdgeIterator();
 52  0
         while (itPathEdges.hasNext()) {
 53  0
             result.append("node {");
 54  0
             result.append(itPathNodes.next());
 55  0
             result.append("} edge {");
 56  0
             result.append(itPathEdges.next());
 57  0
             result.append("} ");
 58  
         }
 59  0
         result.append("node {");
 60  0
         result.append(itPathNodes.next());
 61  0
         result.append("}");
 62  0
         result.append("}");
 63  
         
 64  0
         return result.toString();
 65  
     }
 66  
     
 67  
     /**
 68  
      * Convert the edges in an edge iteration to a String
 69  
      * 
 70  
      * @param itEdges the iterator for which all edges of the iteration shall
 71  
      * be converted to a string.
 72  
      * @return the string representing the edges in the iteration.
 73  
      */
 74  
     public static String convertEdgeIterationToString(EdgeIterator itEdges) {
 75  0
         StringBuffer result = new StringBuffer();
 76  
 
 77  0
         result.append("edge iterator contents {");
 78  0
         while (itEdges.hasNext()) {
 79  0
             result.append(" edge {");
 80  0
             result.append(itEdges.next());
 81  0
             result.append("}");
 82  
         }
 83  
         
 84  0
         return result.toString();
 85  
     }
 86  
     
 87  
     /**
 88  
      * Convert a graph to a string consisting of all adjacency lists
 89  
      * of outgoing edges
 90  
      * 
 91  
      * @param g the graph to be converted
 92  
      * @return the adjacency lists of outgoing edges of g
 93  
      */
 94  
     public static String convertOutgoingAdjacencyListsToString(Graph g) {
 95  0
         OutgoingEdgeNeighborhoodGraphProp outG = (OutgoingEdgeNeighborhoodGraphProp)
 96  
             GraphPropertyInitializer.requireGraphProperty(g,
 97  
                     OutgoingEdgeNeighborhoodGraphProp.class);
 98  0
         GlobalNodesGraphProp globNodes = (GlobalNodesGraphProp)
 99  
             GraphPropertyInitializer.requireGraphProperty(g,
 100  
                     GlobalNodesGraphProp.class);
 101  
         
 102  0
         StringBuffer result = new StringBuffer();
 103  0
         result.append("graph outgoing edges {");
 104  
         
 105  0
         NodeIterator itAllNodes = globNodes.getAllNodesIterator();
 106  0
         while (itAllNodes.hasNext()) {
 107  0
             Node v = itAllNodes.next();
 108  0
             result.append("node {");
 109  0
             result.append(v);
 110  0
             result.append("} outgoing edges {");
 111  0
             EdgeIterator outEdges = outG.getOutgoingEdges(v);
 112  0
             result.append(convertEdgeIterationToString(outEdges));
 113  0
             result.append("} ");
 114  0
         }
 115  0
         result.append("}");
 116  
         
 117  0
         return result.toString();
 118  
     }
 119  
 }