| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DRAGraphAsConstructableNumberedGraph |
|
| 0.0;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 16.04.2005 | |
| 20 | * | |
| 21 | */ | |
| 22 | package net.sourceforge.combean.adapters.drasys.graph; | |
| 23 | ||
| 24 | import java.util.ArrayList; | |
| 25 | ||
| 26 | import net.sourceforge.combean.interfaces.graph.Edge; | |
| 27 | import net.sourceforge.combean.interfaces.graph.Node; | |
| 28 | import net.sourceforge.combean.interfaces.graph.prop.ConstructableNumberedGraphProp; | |
| 29 | import net.sourceforge.combean.util.except.IllegalParameterException; | |
| 30 | import drasys.or.graph.DuplicateEdgeException; | |
| 31 | import drasys.or.graph.EditI; | |
| 32 | import drasys.or.graph.VertexNotFoundException; | |
| 33 | ||
| 34 | /** | |
| 35 | * @author schickin | |
| 36 | * | |
| 37 | */ | |
| 38 | public class DRAGraphAsConstructableNumberedGraph extends | |
| 39 | DRAGraphWithEditIAsGraph implements ConstructableNumberedGraphProp { | |
| 40 | ||
| 41 | 237 | ArrayList<Edge> allEdges = null; |
| 42 | ||
| 43 | /** | |
| 44 | * constructor for an empty graph | |
| 45 | * (uses a standard graph implementation from the OR-Objects library) | |
| 46 | */ | |
| 47 | public DRAGraphAsConstructableNumberedGraph() { | |
| 48 | 225 | super(); |
| 49 | ||
| 50 | 225 | this.allEdges = new ArrayList<Edge>(); |
| 51 | 225 | } |
| 52 | ||
| 53 | /** | |
| 54 | * Constructor for wrapping a given EditI graph | |
| 55 | * | |
| 56 | * @param draGraph the graph to be wrapped (must be empty) | |
| 57 | */ | |
| 58 | public DRAGraphAsConstructableNumberedGraph(EditI draGraph) { | |
| 59 | 12 | super(draGraph); |
| 60 | ||
| 61 | 12 | if (draGraph.sizeOfVertices() != 0 || draGraph.sizeOfEdges() != 0) { |
| 62 | 0 | throw new IllegalParameterException("constructor for non-empty EditI-Objects not yet implemented"); |
| 63 | } | |
| 64 | ||
| 65 | 12 | this.allEdges = new ArrayList<Edge>(); |
| 66 | 12 | } |
| 67 | ||
| 68 | /* (non-Javadoc) | |
| 69 | * @see net.sourceforge.combean.interfaces.graph.GlobalIndexedNodesGraphProp#getNode(int) | |
| 70 | */ | |
| 71 | public Node getNode(int index) { | |
| 72 | 3462 | return convertToNode(getDraGraph().getVertex(new Integer(index))); |
| 73 | } | |
| 74 | ||
| 75 | /* (non-Javadoc) | |
| 76 | * @see net.sourceforge.combean.interfaces.graph.GlobalIndexedEdgesGraphProp#getEdge(int) | |
| 77 | */ | |
| 78 | public Edge getEdge(int index) { | |
| 79 | 936 | return this.allEdges.get(index); |
| 80 | } | |
| 81 | ||
| 82 | /* (non-Javadoc) | |
| 83 | * @see net.sourceforge.combean.interfaces.graph.AddEdgeGraphProp#ensureEdgeCapacity(int) | |
| 84 | */ | |
| 85 | public void ensureEdgeCapacity(int edgeCapacity) { | |
| 86 | 27 | super.ensureEdgeCapacity(edgeCapacity); |
| 87 | 27 | this.allEdges.ensureCapacity(edgeCapacity); |
| 88 | 27 | } |
| 89 | ||
| 90 | /* (non-Javadoc) | |
| 91 | * @see net.sourceforge.combean.interfaces.graph.prop.GlobalNumberedNodesGraphProp#getNodeNumber(net.sourceforge.combean.interfaces.graph.Node) | |
| 92 | */ | |
| 93 | public int getNodeNumber(Node v) { | |
| 94 | 4071 | DRAGraphVertexAsNode draVertex = (DRAGraphVertexAsNode) v; |
| 95 | 4071 | return ((Number) draVertex.getVertexI().getKey()).intValue(); |
| 96 | } | |
| 97 | ||
| 98 | /* (non-Javadoc) | |
| 99 | * @see net.sourceforge.combean.interfaces.graph.prop.GlobalNumberedEdgesGraphProp#getEdgeNumber(net.sourceforge.combean.interfaces.graph.Edge) | |
| 100 | */ | |
| 101 | public int getEdgeNumber(Edge e) { | |
| 102 | 1413 | DRAGraphEdgeAsEdge draEdge = (DRAGraphEdgeAsEdge) e; |
| 103 | 1413 | return ((Number) draEdge.getEdgeI().getKey()).intValue(); |
| 104 | } | |
| 105 | ||
| 106 | /* (non-Javadoc) | |
| 107 | * @see net.sourceforge.combean.adapters.drasys.DRAGraphWithEditIAsGraph#addDraEdge(java.lang.Object, java.lang.Object) | |
| 108 | */ | |
| 109 | protected Edge addDraEdge(Object fromKey, Object toKey) | |
| 110 | throws DuplicateEdgeException, VertexNotFoundException { | |
| 111 | 1368 | Edge result = super.addDraEdge(fromKey, toKey); |
| 112 | 1368 | this.allEdges.add(result); |
| 113 | 1368 | return result; |
| 114 | } | |
| 115 | ||
| 116 | /* (non-Javadoc) | |
| 117 | * @see net.sourceforge.combean.adapters.drasys.DRAGraphWithEditIAsGraph#getNewEdgeKey() | |
| 118 | */ | |
| 119 | protected Object getNewEdgeKey() { | |
| 120 | 1368 | return new Integer(getNumEdges()); |
| 121 | } | |
| 122 | ||
| 123 | /* (non-Javadoc) | |
| 124 | * @see net.sourceforge.combean.adapters.drasys.DRAGraphWithAddVertexIAsGraph#getNewNodeKey() | |
| 125 | */ | |
| 126 | protected Object getNewNodeKey() { | |
| 127 | 1221 | return new Integer(getNumNodes()); |
| 128 | } | |
| 129 | } |