diff --git a/src/main/java/kieker/analysis/graph/impl/GraphImpl.java b/src/main/java/kieker/analysis/graph/impl/GraphImpl.java index 27dc1641f96c68e723743a34870201cc527b4e37..8fde724fc010c2c6611bb2f2e39628b9b67c8e26 100644 --- a/src/main/java/kieker/analysis/graph/impl/GraphImpl.java +++ b/src/main/java/kieker/analysis/graph/impl/GraphImpl.java @@ -3,6 +3,7 @@ package kieker.analysis.graph.impl; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.Stack; import kieker.analysis.graph.Direction; import kieker.analysis.graph.Edge; @@ -18,8 +19,14 @@ public class GraphImpl extends ElementImpl implements Graph { protected Long currentDefaultId = 0l; + protected VertexImpl parentVertex = null; + public GraphImpl() {} + protected GraphImpl(final VertexImpl parentVertex) { + this.parentVertex = parentVertex; + } + @Override public Vertex addVertex(final Object id) { String idString = null; @@ -71,6 +78,28 @@ public class GraphImpl extends ElementImpl implements Graph { @Override public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex) { + + Stack<VertexImpl> outVertexParents = new Stack<>(); + for (VertexImpl parent = ((VertexImpl) outVertex).graph.parentVertex; parent != null; parent = parent.graph.parentVertex) { + outVertexParents.push(parent); + } + Stack<VertexImpl> inVertexParents = new Stack<>(); + for (VertexImpl parent = ((VertexImpl) inVertex).graph.parentVertex; parent != null; parent = parent.graph.parentVertex) { + inVertexParents.push(parent); + } + + if (outVertexParents.pop() != inVertexParents.pop()) { + // throw exception TODO + } + + GraphImpl firstEqualParent = this; + while (outVertexParents.peek() == inVertexParents.pop()) { + firstEqualParent = outVertexParents.pop().graph; + } + return firstEqualParent.addEdgeChecked(id, outVertex, inVertex); + } + + protected Edge addEdgeChecked(final Object id, final Vertex outVertex, final Vertex inVertex) { String idString; if (id == null) { do { @@ -83,12 +112,6 @@ public class GraphImpl extends ElementImpl implements Graph { } } - // TODO Check whether both vertices have the same root graph - // TODO If not, don't add the edge and throw exception - - // TODO Check whether both vertices are in the same graph - // TODO If not, add edge to the "higher" one - final Edge edge = new EdgeImpl(idString, outVertex, inVertex, this); this.edges.put(edge.getId().toString(), edge); ((VertexImpl) outVertex).addOutEdge(edge); diff --git a/src/main/java/kieker/analysis/graph/util/dot/DotGraphWriter.java b/src/main/java/kieker/analysis/graph/util/dot/DotGraphWriter.java index 343d83944490a9a87597d8194dd512ebba8168f5..91a2522b22ba57d96a99603379c81dc99a82cf4e 100644 --- a/src/main/java/kieker/analysis/graph/util/dot/DotGraphWriter.java +++ b/src/main/java/kieker/analysis/graph/util/dot/DotGraphWriter.java @@ -40,7 +40,7 @@ public class DotGraphWriter { } else { openToken = DotGraph.DIRECTED_START_TOKEN; } - writer.writeln(openToken + ' ' + name + ' ' + DotGraph.START_GRAPH_BRACKET); + writer.writeln(openToken + ' ' + '"' + name + '"' + ' ' + DotGraph.START_GRAPH_BRACKET); writer.indent(); state = DotWriterState.STARTED; } @@ -115,7 +115,7 @@ public class DotGraphWriter { public void addSubgraphStart(final String name) throws IOException { checkState(DotWriterState.STARTED); - writer.writeln(DotGraph.SUB_START_TOKEN + ' ' + name + ' ' + DotGraph.START_GRAPH_BRACKET); + writer.writeln(DotGraph.SUB_START_TOKEN + ' ' + '"' + name + '"' + ' ' + DotGraph.START_GRAPH_BRACKET); writer.indent(); openSubgraphs++; }