Coverage Report - net.sourceforge.combean.adapters.drasys.graph.DRAGraphWithEditIAsGraph
 
Classes in this File Line Coverage Branch Coverage Complexity
DRAGraphWithEditIAsGraph
83%
19/23
N/A
1,571
 
 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 23.03.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.adapters.drasys.graph;
 23  
 
 24  
 import net.sourceforge.combean.interfaces.graph.Edge;
 25  
 import net.sourceforge.combean.interfaces.graph.Node;
 26  
 import net.sourceforge.combean.interfaces.graph.prop.ConstructableGraphProp;
 27  
 import net.sourceforge.combean.util.except.GraphModificationException;
 28  
 import drasys.or.graph.DuplicateEdgeException;
 29  
 import drasys.or.graph.EdgeI;
 30  
 import drasys.or.graph.EditI;
 31  
 import drasys.or.graph.SparseGraph;
 32  
 import drasys.or.graph.VertexNotFoundException;
 33  
 
 34  
 /**
 35  
  * @author schickin
 36  
  *
 37  
  */
 38  
 public class DRAGraphWithEditIAsGraph extends DRAGraphWithAddVertexIAsGraph implements
 39  
         ConstructableGraphProp {
 40  
 
 41  276
     private EditI draGraph = null;
 42  
     
 43  
     /**
 44  
      * constructor for an empty graph
 45  
      * (uses a standard graph implementation from the OR-Objects library)
 46  
      */
 47  
     public DRAGraphWithEditIAsGraph() {
 48  240
         super(new SparseGraph());
 49  
         
 50  240
         this.draGraph = (EditI) getDraGraph();
 51  240
     }
 52  
     
 53  
     /**
 54  
      * @param draGraph
 55  
      */
 56  
     public DRAGraphWithEditIAsGraph(EditI draGraph) {
 57  36
         super(draGraph);
 58  
         
 59  36
         this.draGraph = draGraph;
 60  36
     }
 61  
 
 62  
     /* (non-Javadoc)
 63  
      * @see net.sourceforge.combean.interfaces.graph.AddEdgeGraphProp#addEdge(net.sourceforge.combean.interfaces.graph.Node, net.sourceforge.combean.interfaces.graph.Node)
 64  
      */
 65  
     public final Edge addEdge(Node from, Node to) {
 66  1392
         Edge result = null;
 67  
         try {
 68  1392
             Object fromKey =
 69  
                 ((DRAGraphVertexAsNode) from).getVertexI().getKey();
 70  1392
             Object toKey =
 71  
                 ((DRAGraphVertexAsNode) to).getVertexI().getKey();
 72  1392
             result = addDraEdge(fromKey, toKey);
 73  
         }
 74  0
         catch (DuplicateEdgeException e) {
 75  0
             throw new GraphModificationException("edge already exists", e);
 76  
         }
 77  0
         catch (VertexNotFoundException e) {
 78  0
             throw new GraphModificationException("vertex not found", e);
 79  1392
         }
 80  1392
         return result;
 81  
     }
 82  
     
 83  
     /**
 84  
      * @return the wrapped EditI object
 85  
      */
 86  
     public final EditI getEditI() {
 87  1392
         return this.draGraph;
 88  
     }
 89  
 
 90  
     /* (non-Javadoc)
 91  
      * @see net.sourceforge.combean.interfaces.graph.AddEdgeGraphProp#ensureEdgeCapacity(int)
 92  
      */
 93  
     public void ensureEdgeCapacity(int edgeCapacity) {
 94  51
         this.draGraph.ensureEdgeCapacity(edgeCapacity);
 95  51
     }
 96  
 
 97  
     /**
 98  
      * Add an edge, given the keys of the incident nodes
 99  
      * 
 100  
      * @param fromKey the key of the source node
 101  
      * @param toKey the key of the target node
 102  
      * @return the added edge
 103  
      * @throws DuplicateEdgeException
 104  
      * @throws VertexNotFoundException
 105  
      */
 106  
     protected Edge addDraEdge(Object fromKey, Object toKey)
 107  
     throws DuplicateEdgeException, VertexNotFoundException {
 108  1392
         EdgeI newEdge = getEditI().addEdge(fromKey, toKey, null,
 109  
                 true /* isDirected */, getNewEdgeKey());
 110  1392
         return convertToEdge(newEdge);
 111  
     }
 112  
     
 113  
     /**
 114  
      * @return a key for a newly added edge
 115  
      */
 116  
     protected Object getNewEdgeKey() {
 117  24
         return null;
 118  
     }
 119  
     
 120  
 }