| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 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 | |
|
| 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 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public Class getNodeClass() { |
| 69 | 0 | return DRAGraphVertexAsNode.class; |
| 70 | |
} |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
public Class getEdgeClass() { |
| 76 | 0 | return DRAGraphEdgeAsEdge.class; |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
public final EdgeIterator getAllEdgesIterator() { |
| 83 | 9 | return convertToEdgeIterator(this.draGraph.edges()); |
| 84 | |
} |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
public final int getNumEdges() { |
| 90 | 2286 | return this.draGraph.sizeOfEdges(); |
| 91 | |
} |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
public final NodeIterator getAllNodesIterator() { |
| 97 | 12 | return convertToNodeIterator(this.draGraph.vertices()); |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
public final int getNumNodes() { |
| 104 | 2025 | return this.draGraph.sizeOfVertices(); |
| 105 | |
} |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
public final EdgeIterator getOutgoingEdges(Node v) { |
| 111 | 324 | return convertToEdgeIterator( |
| 112 | |
((DRAGraphVertexAsNode) v).getVertexI().outEdges()); |
| 113 | |
} |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
public final EdgeIterator getIncomingEdges(Node v) { |
| 120 | 93 | return convertToEdgeIterator( |
| 121 | |
((DRAGraphVertexAsNode) v).getVertexI().inEdges()); |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
public final Node getFirstNode(Edge e) { |
| 128 | 1566 | return convertToNode( |
| 129 | |
((DRAGraphEdgeAsEdge) e).getEdgeI().getFromVertex()); |
| 130 | |
} |
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 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 | |
|
| 144 | |
|
| 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 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
public final Node getSecondNode(Edge e) { |
| 158 | 1284 | return convertToNode( |
| 159 | |
((DRAGraphEdgeAsEdge) e).getEdgeI().getToVertex()); |
| 160 | |
} |
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 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 | |
} |