| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| JGraphEdgeIterator |
|
| 1.8333333333333333;1,833 |
| 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 28.02.2005 | |
| 20 | * | |
| 21 | */ | |
| 22 | package net.sourceforge.combean.adapters.jgraph; | |
| 23 | ||
| 24 | import java.util.Iterator; | |
| 25 | ||
| 26 | import org.jgraph.graph.GraphModel; | |
| 27 | ||
| 28 | import net.sourceforge.combean.interfaces.graph.Edge; | |
| 29 | import net.sourceforge.combean.interfaces.graph.EdgeIterator; | |
| 30 | ||
| 31 | /** | |
| 32 | * EdgeIterator for using a JGraph GraphModel as Combean Graph | |
| 33 | * | |
| 34 | * @author schickin | |
| 35 | * | |
| 36 | */ | |
| 37 | public class JGraphEdgeIterator implements EdgeIterator { | |
| 38 | ||
| 39 | 33 | private GraphModel g = null; |
| 40 | 33 | private Object node = null; |
| 41 | 33 | private int currChildIndex = 0; |
| 42 | 33 | private Iterator itCurrPort = null; |
| 43 | ||
| 44 | /** | |
| 45 | * constructor | |
| 46 | * | |
| 47 | * @param g the GraphModel where the edge iteration takes place | |
| 48 | * @param node the node of which the incident edges shall be retrieved | |
| 49 | */ | |
| 50 | public JGraphEdgeIterator(GraphModel g, Object node) { | |
| 51 | 33 | super(); |
| 52 | 33 | this.g = g; |
| 53 | 33 | this.node = node; |
| 54 | 33 | this.currChildIndex = 0; |
| 55 | 33 | incrementIterator(); |
| 56 | 33 | } |
| 57 | ||
| 58 | private final Object getCurrChild() { | |
| 59 | 66 | return this.g.getChild(this.node, this.currChildIndex); |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * Advance the currChildIndex until the next child which is a Port | |
| 64 | * to which Edges are connected. | |
| 65 | */ | |
| 66 | private final void gotoNextPortChildWithEdges() { | |
| 67 | 66 | while (this.currChildIndex < this.g.getChildCount(this.node)) { |
| 68 | 33 | if (this.g.isPort(getCurrChild())) { |
| 69 | 33 | this.itCurrPort = this.g.edges(getCurrChild()); |
| 70 | 33 | if (this.itCurrPort.hasNext()) { |
| 71 | 33 | break; |
| 72 | } | |
| 73 | } | |
| 74 | 0 | this.currChildIndex++; |
| 75 | } | |
| 76 | 66 | } |
| 77 | ||
| 78 | /** | |
| 79 | * Advance the currChildIndex and the itCurrPort until the next Edge. | |
| 80 | */ | |
| 81 | private final void incrementIterator() { | |
| 82 | 96 | if (this.itCurrPort == null) { |
| 83 | 33 | gotoNextPortChildWithEdges(); |
| 84 | } | |
| 85 | 63 | else if (!this.itCurrPort.hasNext()) { |
| 86 | 33 | this.currChildIndex++; |
| 87 | 33 | gotoNextPortChildWithEdges(); |
| 88 | } | |
| 89 | 96 | } |
| 90 | ||
| 91 | /* (non-Javadoc) | |
| 92 | * @see net.sourceforge.combean.interfaces.graph.EdgeIterator#hasNext() | |
| 93 | */ | |
| 94 | public boolean hasNext() { | |
| 95 | 108 | return this.currChildIndex < this.g.getChildCount(this.node); |
| 96 | } | |
| 97 | ||
| 98 | /* (non-Javadoc) | |
| 99 | * @see net.sourceforge.combean.interfaces.graph.EdgeIterator#next() | |
| 100 | */ | |
| 101 | public Edge next() { | |
| 102 | 63 | Edge result = new JGraphEdgeAsEdge( |
| 103 | (org.jgraph.graph.Edge) this.itCurrPort.next()); | |
| 104 | 63 | incrementIterator(); |
| 105 | 63 | return result; |
| 106 | } | |
| 107 | } |