From 998b6475f80cc5eba24265cb32e898e18fd75a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Henning?= <stu114708@informatik.uni-kiel.de> Date: Mon, 11 Jan 2016 17:23:38 +0100 Subject: [PATCH] work on nested graph implementation --- .../analysis/dev/nestedgraph/NestedGraph.java | 144 ++++++++++++++++-- .../dev/nestedgraph/NestedGraphPartition.java | 15 ++ 2 files changed, 147 insertions(+), 12 deletions(-) diff --git a/src/main/java/kieker/analysis/dev/nestedgraph/NestedGraph.java b/src/main/java/kieker/analysis/dev/nestedgraph/NestedGraph.java index f9adb83c..1b622107 100644 --- a/src/main/java/kieker/analysis/dev/nestedgraph/NestedGraph.java +++ b/src/main/java/kieker/analysis/dev/nestedgraph/NestedGraph.java @@ -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(); } } diff --git a/src/main/java/kieker/analysis/dev/nestedgraph/NestedGraphPartition.java b/src/main/java/kieker/analysis/dev/nestedgraph/NestedGraphPartition.java index 91ec108a..afecb4d3 100644 --- a/src/main/java/kieker/analysis/dev/nestedgraph/NestedGraphPartition.java +++ b/src/main/java/kieker/analysis/dev/nestedgraph/NestedGraphPartition.java @@ -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; } -- GitLab