forked from tinkerpop/blueprints
/
WrappedGraph.java
81 lines (65 loc) · 2.49 KB
/
WrappedGraph.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.tinkerpop.blueprints.pgm.util.wrappers.wrapped;
import com.tinkerpop.blueprints.pgm.Edge;
import com.tinkerpop.blueprints.pgm.Graph;
import com.tinkerpop.blueprints.pgm.Vertex;
import com.tinkerpop.blueprints.pgm.WrappableGraph;
import com.tinkerpop.blueprints.pgm.impls.StringFactory;
import com.tinkerpop.blueprints.pgm.util.wrappers.wrapped.util.WrappedEdgeSequence;
import com.tinkerpop.blueprints.pgm.util.wrappers.wrapped.util.WrappedVertexSequence;
/**
* WrappedGraph serves as a template for writing a wrapper graph.
* The intention is that the code in this template is copied and adjusted accordingly.
*
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class WrappedGraph<T extends Graph> implements Graph, WrappableGraph<T> {
protected T rawGraph;
public WrappedGraph(final T rawGraph) {
this.rawGraph = rawGraph;
}
public void clear() {
this.rawGraph.clear();
}
public void shutdown() {
this.rawGraph.shutdown();
}
public Vertex addVertex(final Object id) {
return new WrappedVertex(this.rawGraph.addVertex(id));
}
public Vertex getVertex(final Object id) {
final Vertex vertex = this.rawGraph.getVertex(id);
if (null == vertex)
return null;
else
return new WrappedVertex(vertex);
}
public Iterable<Vertex> getVertices() {
return new WrappedVertexSequence(this.rawGraph.getVertices().iterator());
}
public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
return new WrappedEdge(this.rawGraph.addEdge(id, ((WrappedVertex) outVertex).getRawVertex(), ((WrappedVertex) inVertex).getRawVertex(), label));
}
public Edge getEdge(final Object id) {
final Edge edge = this.rawGraph.getEdge(id);
if (null == edge)
return null;
else
return new WrappedEdge(edge);
}
public Iterable<Edge> getEdges() {
return new WrappedEdgeSequence(this.rawGraph.getEdges().iterator());
}
public void removeEdge(final Edge edge) {
this.rawGraph.removeEdge(((WrappedEdge) edge).getRawEdge());
}
public void removeVertex(final Vertex vertex) {
this.rawGraph.removeVertex(((WrappedVertex) vertex).getRawVertex());
}
@Override
public T getRawGraph() {
return this.rawGraph;
}
public String toString() {
return StringFactory.graphString(this, this.rawGraph.toString());
}
}