Coverage Report - net.sourceforge.combean.adapters.drasys.graph.DRAGraphAsGraph
 
Classes in this File Line Coverage Branch Coverage Complexity
DRAGraphAsGraph
82%
23/28
100%
2/2
1,1
 
 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 19.03.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.adapters.drasys.graph;
 23  
 
 24  
 import java.util.Enumeration;
 25  
 
 26  
 import net.sourceforge.combean.graph.iterators.CombinedPairEdgeIterator;
 27  
 import net.sourceforge.combean.interfaces.graph.Edge;
 28  
 import net.sourceforge.combean.interfaces.graph.EdgeIterator;
 29  
 import net.sourceforge.combean.interfaces.graph.Graph;
 30  
 import net.sourceforge.combean.interfaces.graph.Node;
 31  
 import net.sourceforge.combean.interfaces.graph.NodeIterator;
 32  
 import net.sourceforge.combean.interfaces.graph.prop.DirectedEdgeNeighborhoodGraphProp;
 33  
 import net.sourceforge.combean.interfaces.graph.prop.GlobalEdgesGraphProp;
 34  
 import net.sourceforge.combean.interfaces.graph.prop.GlobalNodesGraphProp;
 35  
 import drasys.or.graph.EdgeI;
 36  
 import drasys.or.graph.GraphI;
 37  
 import drasys.or.graph.SparseGraph;
 38  
 import drasys.or.graph.VertexI;
 39  
 
 40  
 /**
 41  
  * @author schickin
 42  
  *
 43  
  */
 44  
 public class DRAGraphAsGraph implements
 45  
 Graph,
 46  
 DirectedEdgeNeighborhoodGraphProp,
 47  
 GlobalEdgesGraphProp,
 48  
 GlobalNodesGraphProp {
 49  
     
 50  315
     private GraphI draGraph = null;
 51  
 
 52  
     public DRAGraphAsGraph() {
 53  0
         super();
 54  0
         this.draGraph = new SparseGraph();
 55  0
     }
 56  
     
 57  
     /**
 58  
      * 
 59  
      */
 60  
     public DRAGraphAsGraph(GraphI draGraph) {
 61  315
         super();
 62  315
         this.draGraph = draGraph;
 63  315
     }
 64  
 
 65  
     /* (non-Javadoc)
 66  
      * @see net.sourceforge.combean.interfaces.graph.Graph#getNodeClass()
 67  
      */
 68  
     public Class getNodeClass() {
 69  0
          return DRAGraphVertexAsNode.class;
 70  
     }
 71  
 
 72  
     /* (non-Javadoc)
 73  
      * @see net.sourceforge.combean.interfaces.graph.Graph#getEdgeClass()
 74  
      */
 75  
     public Class getEdgeClass() {
 76  0
         return DRAGraphEdgeAsEdge.class;
 77  
     }
 78  
 
 79  
     /* (non-Javadoc)
 80  
      * @see net.sourceforge.combean.interfaces.graph.GlobalEdgesGraphProp#getAllEdgesIterator()
 81  
      */
 82  
     public final EdgeIterator getAllEdgesIterator() {
 83  9
          return convertToEdgeIterator(this.draGraph.edges());
 84  
     }
 85  
     
 86  
     /* (non-Javadoc)
 87  
      * @see net.sourceforge.combean.interfaces.graph.GlobalEdgesGraphProp#getNumEdges()
 88  
      */
 89  
     public final int getNumEdges() {
 90  2286
          return this.draGraph.sizeOfEdges();
 91  
     }
 92  
     
 93  
     /* (non-Javadoc)
 94  
      * @see net.sourceforge.combean.interfaces.graph.GlobalNodesGraphProp#getAllNodesIterator()
 95  
      */
 96  
     public final NodeIterator getAllNodesIterator() {
 97  12
         return convertToNodeIterator(this.draGraph.vertices());
 98  
     }
 99  
     
 100  
     /* (non-Javadoc)
 101  
      * @see net.sourceforge.combean.interfaces.graph.GlobalNodesGraphProp#getNumNodes()
 102  
      */
 103  
     public final int getNumNodes() {
 104  2025
          return this.draGraph.sizeOfVertices();
 105  
     }
 106  
     
 107  
     /* (non-Javadoc)
 108  
      * @see net.sourceforge.combean.interfaces.graph.OutgoingEdgeNeighborhoodGraphProp#getOutgoingEdges(net.sourceforge.combean.interfaces.graph.Node)
 109  
      */
 110  
     public final EdgeIterator getOutgoingEdges(Node v) {
 111  324
          return convertToEdgeIterator(
 112  
                  ((DRAGraphVertexAsNode) v).getVertexI().outEdges());
 113  
     }
 114  
     
 115  
     /* (non-Javadoc)
 116  
      * @see net.sourceforge.combean.interfaces.graph.IncomingEdgeNeighborhoodGraphProp#getIncomingEdges(net.sourceforge.combean.interfaces.graph.Node)
 117  
      */
 118  
     
 119  
     public final EdgeIterator getIncomingEdges(Node v) {
 120  93
         return convertToEdgeIterator(
 121  
                 ((DRAGraphVertexAsNode) v).getVertexI().inEdges());
 122  
     }
 123  
     
 124  
     /* (non-Javadoc)
 125  
      * @see net.sourceforge.combean.interfaces.graph.NeighborhoodGraphProp#getFirstNode(net.sourceforge.combean.interfaces.graph.Edge)
 126  
      */
 127  
     public final Node getFirstNode(Edge e) {
 128  1566
          return convertToNode(
 129  
                  ((DRAGraphEdgeAsEdge) e).getEdgeI().getFromVertex());
 130  
     }
 131  
     
 132  
     /* (non-Javadoc)
 133  
      * @see net.sourceforge.combean.interfaces.graph.NeighborhoodGraphProp#getIncidentEdges(net.sourceforge.combean.interfaces.graph.Node)
 134  
      */
 135  
     public final EdgeIterator getIncidentEdges(Node v) {
 136  204
         return new CombinedPairEdgeIterator(
 137  
                 convertToEdgeIterator(
 138  
                         ((DRAGraphVertexAsNode) v).getVertexI().inEdges()),
 139  
                 convertToEdgeIterator(
 140  
                         ((DRAGraphVertexAsNode) v).getVertexI().outEdges()));
 141  
     }
 142  
     
 143  
     /* (non-Javadoc)
 144  
      * @see net.sourceforge.combean.interfaces.graph.NeighborhoodGraphProp#getOtherNode(net.sourceforge.combean.interfaces.graph.Edge, net.sourceforge.combean.interfaces.graph.Node)
 145  
      */
 146  
     public final Node getOtherNode(Edge e, Node v) {
 147  1218
         Node first = getFirstNode(e);
 148  1218
         if (first.equals(v)) {
 149  846
             return getSecondNode(e);
 150  
         }
 151  372
         return first;
 152  
     }
 153  
     
 154  
     /* (non-Javadoc)
 155  
      * @see net.sourceforge.combean.interfaces.graph.NeighborhoodGraphProp#getSecondNode(net.sourceforge.combean.interfaces.graph.Edge)
 156  
      */
 157  
     public final Node getSecondNode(Edge e) {
 158  1284
         return convertToNode(
 159  
                 ((DRAGraphEdgeAsEdge) e).getEdgeI().getToVertex());
 160  
     }
 161  
     
 162  
     /**
 163  
      * @return Returns the draGraph.
 164  
      */
 165  
     public final GraphI getDraGraph() {
 166  3702
         return this.draGraph;
 167  
     }
 168  
     
 169  
     public final Object getEdgeValue(Edge e) {
 170  3
         return ((DRAGraphEdgeAsEdge) e).getEdgeI().getValue();
 171  
     }
 172  
     
 173  
     protected Node convertToNode(VertexI draVertex) {
 174  7617
         return new DRAGraphVertexAsNode(draVertex);
 175  
     }
 176  
     
 177  
     protected Edge convertToEdge(EdgeI draEdge) {
 178  2259
         return new DRAGraphEdgeAsEdge(draEdge);
 179  
     }
 180  
     
 181  
     private NodeIterator convertToNodeIterator(Enumeration draVertexEnum) {
 182  12
         return new DRAGraphNodeIterator(draVertexEnum, this);
 183  
     }
 184  
     
 185  
     private EdgeIterator convertToEdgeIterator(Enumeration draEdgeEnum) {
 186  834
         return new DRAGraphEdgeIterator(draEdgeEnum, this);
 187  
     }
 188  
 }