Coverage Report - net.sourceforge.combean.adapters.drasys.graph.DRAGraphWithAddVertexIAsGraph
 
Classes in this File Line Coverage Branch Coverage Complexity
DRAGraphWithAddVertexIAsGraph
88%
14/16
N/A
1,333
 
 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 22.03.2005
 20  
  *
 21  
  */
 22  
 package net.sourceforge.combean.adapters.drasys.graph;
 23  
 
 24  
 import net.sourceforge.combean.interfaces.graph.Node;
 25  
 import net.sourceforge.combean.interfaces.graph.prop.AddNodeGraphProp;
 26  
 import net.sourceforge.combean.util.except.GraphModificationException;
 27  
 import drasys.or.graph.AddVertexI;
 28  
 import drasys.or.graph.DuplicateVertexException;
 29  
 import drasys.or.graph.VertexI;
 30  
 
 31  
 /**
 32  
  * @author schickin
 33  
  *
 34  
  */
 35  
 public class DRAGraphWithAddVertexIAsGraph extends DRAGraphAsGraph implements
 36  
         AddNodeGraphProp {
 37  
     
 38  279
     private AddVertexI draGraph = null;
 39  
 
 40  
     /**
 41  
      * @param draGraph
 42  
      */
 43  
     public DRAGraphWithAddVertexIAsGraph(AddVertexI draGraph) {
 44  279
         super(draGraph);
 45  
         
 46  279
         this.draGraph = draGraph;
 47  279
     }
 48  
 
 49  
     /* (non-Javadoc)
 50  
      * @see net.sourceforge.combean.interfaces.graph.AddNodeGraphProp#addNode()
 51  
      */
 52  
     public final Node addNode() {
 53  1278
         Node result = null;
 54  
         try {
 55  1278
          result = addDraVertex();
 56  
         }
 57  0
         catch (DuplicateVertexException e) {
 58  0
             throw new GraphModificationException("node cannot be added", e);
 59  1278
         }
 60  1278
         return result;
 61  
     }
 62  
     
 63  
     /* (non-Javadoc)
 64  
      * @see net.sourceforge.combean.interfaces.graph.AddNodeGraphProp#ensureNodeCapacity()
 65  
      */
 66  
     public final void ensureNodeCapacity(int nodeCapacity) {
 67  54
          this.draGraph.ensureVertexCapacity(nodeCapacity);
 68  54
     }
 69  
     
 70  
     /* (non-Javadoc)
 71  
      * @see net.sourceforge.combean.interfaces.graph.AddNodeGraphProp#freeze()
 72  
      */
 73  
     public final void freeze() {
 74  
         /*
 75  
          nothing to do
 76  
          */
 77  54
     }
 78  
     
 79  
     /* (non-Javadoc)
 80  
      * @see net.sourceforge.combean.adapters.drasys.DRAGraphWithAddVertexIAsGraph#addDraVertex()
 81  
      */
 82  
     protected Node addDraVertex()
 83  
     throws DuplicateVertexException {
 84  1278
         VertexI newVertex = this.draGraph.addVertex(getNewNodeKey());
 85  1278
         return convertToNode(newVertex);
 86  
     }
 87  
     
 88  
     /**
 89  
      * @return a key for a newly added node
 90  
      */
 91  
     protected Object getNewNodeKey() {
 92  
         // TODO more intelligent handling for graph with external vertex keys
 93  57
         return new Integer(this.draGraph.sizeOfVertices());
 94  
     }
 95  
 }