Skip to content
Snippets Groups Projects
Commit 998b6475 authored by Sören Henning's avatar Sören Henning
Browse files

work on nested graph implementation

parent f880d8be
No related branches found
No related tags found
1 merge request!17Get impletemented stages and Java 8
......@@ -4,19 +4,30 @@ import java.util.HashSet;
import java.util.Set;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Features;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.StringFactory;
import com.tinkerpop.blueprints.util.wrappers.WrapperGraph;
import com.tinkerpop.blueprints.util.wrappers.partition.PartitionGraph;
import com.tinkerpop.blueprints.util.wrappers.wrapped.WrappedGraph;
public class NestedGraph extends WrappedGraph<Graph> {
public class NestedGraph<T extends Graph> implements Graph, WrapperGraph<T> {
protected PartitionGraph<T> baseGraph;
private final Features features;
private static final String PARTITION_KEY = "__nested-graph-partition";
private static final String DEFAULT_PARTITION = "";
private final Set<NestedGraphPartition> partitions = new HashSet<>();
public NestedGraph(final Graph baseGraph) {
super(new PartitionGraph<Graph>(baseGraph, PARTITION_KEY, ""));
public NestedGraph(final T baseGraph) {
this.baseGraph = new PartitionGraph<>(baseGraph, PARTITION_KEY, "");
this.features = this.baseGraph.getFeatures().copyFeatures();
this.features.isWrapper = true;
}
public void addPartition(final NestedGraphPartition partition) {
......@@ -29,24 +40,133 @@ public class NestedGraph extends WrappedGraph<Graph> {
public Iterable<Vertex> getVerticesForPartition(final NestedGraphPartition partition) {
// TODO
baseGraph.removeReadPartition(DEFAULT_PARTITION);
baseGraph.addReadPartition(partition.getName());
return null;
Set<Vertex> vertices = new HashSet<Vertex>();
for (Vertex vertex : baseGraph.getVertices()) {
vertices.add(vertex);
}
baseGraph.removeReadPartition(partition.getName());
baseGraph.addReadPartition(DEFAULT_PARTITION);
return vertices;
}
public Iterable<Edge> getEdgesForPartition(final NestedGraphPartition partition) {
// TODO
baseGraph.removeReadPartition(DEFAULT_PARTITION);
baseGraph.addReadPartition(partition.getName());
Set<Edge> edges = new HashSet<Edge>();
for (Edge edge : baseGraph.getEdges()) {
edges.add(edge);
}
baseGraph.removeReadPartition(partition.getName());
baseGraph.addReadPartition(DEFAULT_PARTITION);
return edges;
}
public Vertex addVertexToPartition(final Object id, final NestedGraphPartition partition) {
baseGraph.setWritePartition(partition.getName());
Vertex vertex = baseGraph.addVertex(id);
baseGraph.setWritePartition(DEFAULT_PARTITION);
return vertex;
}
public Edge addEdgeToPartition(final Object id, final Vertex outVertex, final Vertex inVertex, final String label, final NestedGraphPartition partition) {
baseGraph.setWritePartition(partition.getName());
Edge edge = baseGraph.addEdge(id, outVertex, inVertex, label);
baseGraph.setWritePartition(DEFAULT_PARTITION);
return edge;
}
@Override
public Vertex addVertex(final Object id) {
return baseGraph.addVertex(id);
}
@Override
public Vertex getVertex(final Object id) {
return baseGraph.getVertex(id);
}
@Override
public Iterable<Vertex> getVertices() {
return this.baseGraph.getVertices();
}
@Override
public Iterable<Vertex> getVertices(final String key, final Object value) {
return this.baseGraph.getVertices(key, value);
}
@Override
public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
return baseGraph.addEdge(id, outVertex, inVertex, label);
}
@Override
public Edge getEdge(final Object id) {
return baseGraph.getEdge(id);
}
@Override
public Iterable<Edge> getEdges() {
return baseGraph.getEdges();
}
@Override
public Iterable<Edge> getEdges(final String key, final Object value) {
return this.baseGraph.getEdges(key, value);
}
@Override
public void removeEdge(final Edge edge) {
baseGraph.removeEdge(edge);
}
@Override
public void removeVertex(final Vertex vertex) {
baseGraph.removeVertex(vertex);
}
@Override
public T getBaseGraph() {
return baseGraph.getBaseGraph();
}
@Override
public GraphQuery query() {
return this.baseGraph.query();
}
return null;
@Override
public String toString() {
return StringFactory.graphString(this, this.baseGraph.toString());
}
public void addVertexToPartition(final Vertex vertex, final NestedGraphPartition partition) {
// TODO
@Override
public Features getFeatures() {
return this.features;
}
public void addEdgeToPartition(final Edge edge, final NestedGraphPartition partition) {
// TODO
@Override
public void shutdown() {
this.baseGraph.shutdown();
}
}
......@@ -7,10 +7,17 @@ public class NestedGraphPartition {
private String name;
private String label;
private final Set<NestedGraphPartition> subPartitions = new HashSet<>();
public NestedGraphPartition(final String name) {
this(name, null);
}
public NestedGraphPartition(final String name, final String label) {
this.name = name;
this.label = label;
}
public String getName() {
......@@ -21,6 +28,14 @@ public class NestedGraphPartition {
this.name = name;
}
public String getLabel() {
return label;
}
public void setLabel(final String label) {
this.label = label;
}
public Iterable<NestedGraphPartition> getSubPartitions() {
return subPartitions;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment