From 15bd424fecc4481abb95d7d1487f004ea3d13a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Henning?= <stu114708@informatik.uni-kiel.de> Date: Thu, 25 Feb 2016 08:59:40 +0100 Subject: [PATCH] work on nested graph library --- .../kieker/analysis/graph/GraphTester.java | 42 +++++++++++++++++++ .../java/kieker/analysis/graph/Subgraph.java | 5 --- .../java/kieker/analysis/graph/Vertex.java | 6 ++- .../analysis/graph/impl/ElementImpl.java | 2 +- .../kieker/analysis/graph/impl/GraphImpl.java | 5 ++- .../analysis/graph/impl/VertexImpl.java | 13 ++++-- 6 files changed, 60 insertions(+), 13 deletions(-) delete mode 100644 src/main/java/kieker/analysis/graph/Subgraph.java diff --git a/src/main/java/kieker/analysis/graph/GraphTester.java b/src/main/java/kieker/analysis/graph/GraphTester.java index bc151543..8e7f719d 100644 --- a/src/main/java/kieker/analysis/graph/GraphTester.java +++ b/src/main/java/kieker/analysis/graph/GraphTester.java @@ -27,6 +27,44 @@ public class GraphTester { assert node1 == node1snd; + System.out.println("Master graph"); + + for (Vertex vertex : graph.getVertices()) { + System.out.println(vertex.getId()); + } + + for (Edge edge : graph.getEdges()) { + System.out.println(edge.getId()); + } + + // BlueprintsExporter blueprintsExporter = new BlueprintsExporter(graph); + // System.out.println(blueprintsExporter.exportGraph()); + + node1snd.remove(); + + for (Vertex vertex : graph.getVertices()) { + System.out.println(vertex.getId()); + } + + node1.addChildGraph(); + + Vertex node1sub1 = node1.getChildGraph().addVertex("n1::s1"); + Vertex node1sub2 = node1.getChildGraph().addVertex("n1::s2"); + Vertex node1sub3 = node1.getChildGraph().addVertex("n1::s3"); + node1sub3.addEdge("wormhole", node4); + + System.out.println("Node 1's child graph"); + + for (Vertex vertex : node1.getChildGraph().getVertices()) { + System.out.println(vertex.getId()); + } + + for (Edge edge : node1.getChildGraph().getEdges()) { + System.out.println(edge.getId()); + } + + System.out.println("Master graph"); + for (Vertex vertex : graph.getVertices()) { System.out.println(vertex.getId()); } @@ -37,6 +75,10 @@ public class GraphTester { // node2.addEdgeTo(node11); + // Export to Blueprints + // BlueprintsExporter blueprintsExporter = new BlueprintsExporter(graph); + // System.out.println(blueprintsExporter.exportGraph()); + } } diff --git a/src/main/java/kieker/analysis/graph/Subgraph.java b/src/main/java/kieker/analysis/graph/Subgraph.java deleted file mode 100644 index e331bed3..00000000 --- a/src/main/java/kieker/analysis/graph/Subgraph.java +++ /dev/null @@ -1,5 +0,0 @@ -package kieker.analysis.graph; - -public interface Subgraph { - -} diff --git a/src/main/java/kieker/analysis/graph/Vertex.java b/src/main/java/kieker/analysis/graph/Vertex.java index f231c78d..788a08e3 100644 --- a/src/main/java/kieker/analysis/graph/Vertex.java +++ b/src/main/java/kieker/analysis/graph/Vertex.java @@ -2,10 +2,12 @@ package kieker.analysis.graph; public interface Vertex extends Element { - public Graph getChildGraph(); - public Graph addChildGraph(); + public boolean hasChildGraph(); + + public Graph getChildGraph(); + public Iterable<Edge> getEdges(Direction direction); public Iterable<Vertex> getVertices(Direction direction); diff --git a/src/main/java/kieker/analysis/graph/impl/ElementImpl.java b/src/main/java/kieker/analysis/graph/impl/ElementImpl.java index e980e4b9..f1c2dd91 100644 --- a/src/main/java/kieker/analysis/graph/impl/ElementImpl.java +++ b/src/main/java/kieker/analysis/graph/impl/ElementImpl.java @@ -11,7 +11,7 @@ abstract class ElementImpl implements Element { protected Map<String, Object> properties = new HashMap<String, Object>(); protected final String id; - protected final GraphImpl graph; // TODO Maybe Graph as type? + protected final GraphImpl graph; protected ElementImpl(final String id, final GraphImpl graph) { this.graph = graph; diff --git a/src/main/java/kieker/analysis/graph/impl/GraphImpl.java b/src/main/java/kieker/analysis/graph/impl/GraphImpl.java index b5202fbf..9848b4d4 100644 --- a/src/main/java/kieker/analysis/graph/impl/GraphImpl.java +++ b/src/main/java/kieker/analysis/graph/impl/GraphImpl.java @@ -57,7 +57,10 @@ public class GraphImpl implements Graph { throw ExceptionFactory.vertexWithIdDoesNotExist(vertex.getId()); } - for (Edge edge : vertex.getEdges(Direction.BOTH)) { + for (Edge edge : vertex.getEdges(Direction.IN)) { + this.removeEdge(edge); + } + for (Edge edge : vertex.getEdges(Direction.OUT)) { this.removeEdge(edge); } diff --git a/src/main/java/kieker/analysis/graph/impl/VertexImpl.java b/src/main/java/kieker/analysis/graph/impl/VertexImpl.java index fa049476..feed76b4 100644 --- a/src/main/java/kieker/analysis/graph/impl/VertexImpl.java +++ b/src/main/java/kieker/analysis/graph/impl/VertexImpl.java @@ -13,6 +13,7 @@ class VertexImpl extends ElementImpl implements Vertex { protected Map<String, Edge> outEdges = new HashMap<String, Edge>(); protected Map<String, Edge> inEdges = new HashMap<String, Edge>(); + private Graph childGraph; protected VertexImpl(final String id, final GraphImpl graph) { super(id, graph); @@ -20,14 +21,18 @@ class VertexImpl extends ElementImpl implements Vertex { @Override public Graph addChildGraph() { - // TODO Auto-generated method stub - return null; + this.childGraph = new GraphImpl(); + return getChildGraph(); + } + + @Override + public boolean hasChildGraph() { + return (this.childGraph == null); } @Override public Graph getChildGraph() { - // TODO Auto-generated method stub - return null; + return childGraph; } @Override -- GitLab