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 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 | |
|
36 | |
|
37 | |
|
38 | |
public class DRAGraphWithEditIAsGraph extends DRAGraphWithAddVertexIAsGraph implements |
39 | |
ConstructableGraphProp { |
40 | |
|
41 | 276 | private EditI draGraph = null; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public DRAGraphWithEditIAsGraph() { |
48 | 240 | super(new SparseGraph()); |
49 | |
|
50 | 240 | this.draGraph = (EditI) getDraGraph(); |
51 | 240 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public DRAGraphWithEditIAsGraph(EditI draGraph) { |
57 | 36 | super(draGraph); |
58 | |
|
59 | 36 | this.draGraph = draGraph; |
60 | 36 | } |
61 | |
|
62 | |
|
63 | |
|
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 | |
|
85 | |
|
86 | |
public final EditI getEditI() { |
87 | 1392 | return this.draGraph; |
88 | |
} |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public void ensureEdgeCapacity(int edgeCapacity) { |
94 | 51 | this.draGraph.ensureEdgeCapacity(edgeCapacity); |
95 | 51 | } |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
protected Edge addDraEdge(Object fromKey, Object toKey) |
107 | |
throws DuplicateEdgeException, VertexNotFoundException { |
108 | 1392 | EdgeI newEdge = getEditI().addEdge(fromKey, toKey, null, |
109 | |
true , getNewEdgeKey()); |
110 | 1392 | return convertToEdge(newEdge); |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
protected Object getNewEdgeKey() { |
117 | 24 | return null; |
118 | |
} |
119 | |
|
120 | |
} |