diff --git a/src/main/java/kieker/analysis/graph/Direction.java b/src/main/java/kieker/analysis/graph/Direction.java new file mode 100644 index 0000000000000000000000000000000000000000..fea516c1ee0703a83a49d4b823501b0191875bce --- /dev/null +++ b/src/main/java/kieker/analysis/graph/Direction.java @@ -0,0 +1,22 @@ +package kieker.analysis.graph; + +/** + * Direction is used to denote the direction of an edge or location of a vertex on an edge. + * + * @author Sören Henning + * + */ +public enum Direction { + + OUT, IN, BOTH; + + public Direction opposite() { + if (this.equals(OUT)) { + return IN; + } else if (this.equals(IN)) { + return OUT; + } else { + return BOTH; + } + } +} diff --git a/src/main/java/kieker/analysis/graph/Edge.java b/src/main/java/kieker/analysis/graph/Edge.java index bc29f7609f3a64e4b5299995c99d5f0e4cb7823f..82f8065b9435de8d791b38b4ce77c6d375957394 100644 --- a/src/main/java/kieker/analysis/graph/Edge.java +++ b/src/main/java/kieker/analysis/graph/Edge.java @@ -2,6 +2,6 @@ package kieker.analysis.graph; public interface Edge extends Element { - // public Vertex getVertex(Direction direction) throws IllegalArgumentException; + public Vertex getVertex(Direction direction) throws IllegalArgumentException; } diff --git a/src/main/java/kieker/analysis/graph/GraphTester.java b/src/main/java/kieker/analysis/graph/GraphTester.java index 3c619c9f7b51a3d7403a63fd32d6b272fa2551c7..03566b68899f3f6e2d6cab21551ccf7edef6751b 100644 --- a/src/main/java/kieker/analysis/graph/GraphTester.java +++ b/src/main/java/kieker/analysis/graph/GraphTester.java @@ -12,7 +12,7 @@ public class GraphTester { Vertex node2 = graph.addVertex("n2"); - Graph subgraph = node1.addSubgraph(); + Graph subgraph = node1.addChildGraph(); Vertex node11 = subgraph.addVertex("n1::n1"); diff --git a/src/main/java/kieker/analysis/graph/Vertex.java b/src/main/java/kieker/analysis/graph/Vertex.java index 9434544396e077dac3479404f7c44619224bab1e..6d6b02a8ff266ffea82800cb4419ebd21ce157c1 100644 --- a/src/main/java/kieker/analysis/graph/Vertex.java +++ b/src/main/java/kieker/analysis/graph/Vertex.java @@ -2,15 +2,13 @@ package kieker.analysis.graph; public interface Vertex extends Element { - public Boolean hasSubgraph(); + public Graph getChildGraph(); - public Graph getSubgraph(); + public Graph addChildGraph(); - public Graph addSubgraph(); + public Iterable<Edge> getEdges(Direction direction); - // public Iterable<Edge> getEdges(Direction direction); - - // public Iterable<Vertex> getVertices(Direction direction); + public Iterable<Vertex> getVertices(Direction direction); public Edge addEdge(Vertex inVertex); diff --git a/src/main/java/kieker/analysis/graph/impl/EdgeImpl.java b/src/main/java/kieker/analysis/graph/impl/EdgeImpl.java index 05cc2949555802a70be9cf7db7827359cc3cc370..6b0dbae34ae08f8336c9a51955f0237c0963d1d2 100644 --- a/src/main/java/kieker/analysis/graph/impl/EdgeImpl.java +++ b/src/main/java/kieker/analysis/graph/impl/EdgeImpl.java @@ -1,5 +1,6 @@ package kieker.analysis.graph.impl; +import kieker.analysis.graph.Direction; import kieker.analysis.graph.Edge; import kieker.analysis.graph.Vertex; @@ -19,6 +20,15 @@ class EdgeImpl extends ElementImpl implements Edge { this.graph.removeEdge(this); } - // public Vertex getVertex(Direction direction) throws IllegalArgumentException; + @Override + public Vertex getVertex(final Direction direction) throws IllegalArgumentException { + if (direction.equals(Direction.IN)) { + return this.inVertex; + } else if (direction.equals(Direction.OUT)) { + return this.outVertex; + } else { + throw ExceptionFactory.bothIsNotSupported(); + } + } } diff --git a/src/main/java/kieker/analysis/graph/impl/ExceptionFactory.java b/src/main/java/kieker/analysis/graph/impl/ExceptionFactory.java index 1fe1e2464383e685b63e333cc70f9272d7566cd7..63605411798372bd59ab02c3e734e3ade1548faf 100644 --- a/src/main/java/kieker/analysis/graph/impl/ExceptionFactory.java +++ b/src/main/java/kieker/analysis/graph/impl/ExceptionFactory.java @@ -33,6 +33,10 @@ class ExceptionFactory { return new IllegalStateException("Edge with id does not exist: " + id); } + public static IllegalArgumentException bothIsNotSupported() { + return new IllegalArgumentException("A direction of BOTH is not supported"); + } + // Element related exceptions public static IllegalArgumentException propertyKeyIsReserved(final String key) { diff --git a/src/main/java/kieker/analysis/graph/impl/GraphImpl.java b/src/main/java/kieker/analysis/graph/impl/GraphImpl.java index 4cdc8d6623ae1f9bddf3e5d50c8c66456adf7c8d..33a2372693319d0fa66f03e2a0e50efa00fa1aca 100644 --- a/src/main/java/kieker/analysis/graph/impl/GraphImpl.java +++ b/src/main/java/kieker/analysis/graph/impl/GraphImpl.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import kieker.analysis.graph.Direction; import kieker.analysis.graph.Edge; import kieker.analysis.graph.Graph; import kieker.analysis.graph.Vertex; @@ -52,12 +53,15 @@ public class GraphImpl implements Graph { @Override public void removeVertex(final Vertex vertex) { - // TODO Check whether the vertex exists - - // TODO Remove all edges + if (!this.vertices.containsKey(vertex.getId().toString())) { + throw ExceptionFactory.vertexWithIdDoesNotExist(vertex.getId()); + } - // TODO remove this vertex from map + for (Edge edge : vertex.getEdges(Direction.BOTH)) { + this.removeEdge(edge); + } + this.vertices.remove(vertex.getId().toString()); } @Override @@ -98,8 +102,17 @@ public class GraphImpl implements Graph { @Override public void removeEdge(final Edge edge) { - // TODO Auto-generated method stub + if (!this.edges.containsKey(edge.getId().toString())) { + throw ExceptionFactory.edgeWithIdDoesNotExist(edge.getId()); + } + + final VertexImpl outVertex = (VertexImpl) edge.getVertex(Direction.OUT); + outVertex.outEdges.remove(edge.getId().toString()); + + final VertexImpl inVertex = (VertexImpl) edge.getVertex(Direction.IN); + inVertex.inEdges.remove(edge.getId().toString()); + this.edges.remove(edge.getId().toString()); } private String getDefaultId() { diff --git a/src/main/java/kieker/analysis/graph/impl/VertexImpl.java b/src/main/java/kieker/analysis/graph/impl/VertexImpl.java index 9ac75f7e8b21acbdfba2e33c60633fc431627111..5611e523f6cbf823c678afe2fd748d763a2bdb29 100644 --- a/src/main/java/kieker/analysis/graph/impl/VertexImpl.java +++ b/src/main/java/kieker/analysis/graph/impl/VertexImpl.java @@ -5,6 +5,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import kieker.analysis.graph.Direction; import kieker.analysis.graph.Edge; import kieker.analysis.graph.Graph; import kieker.analysis.graph.Vertex; @@ -19,26 +20,34 @@ class VertexImpl extends ElementImpl implements Vertex { } @Override - public Graph addSubgraph() { + public Graph addChildGraph() { // TODO Auto-generated method stub return null; } @Override - public Boolean hasSubgraph() { + public Graph getChildGraph() { // TODO Auto-generated method stub - return false; + return null; } @Override - public Graph getSubgraph() { + public Iterable<Edge> getEdges(final Direction direction) { // TODO Auto-generated method stub return null; + /* + * if (direction.equals(Direction.OUT)) { + * return this.getOutEdges(labels); + * } else if (direction.equals(Direction.IN)) + * return this.getInEdges(labels); + * } + */ } @Override - public Edge addEdge(final Vertex inVertex) { - return addEdge(null, inVertex); + public Iterable<Vertex> getVertices(final Direction direction) { + // TODO Auto-generated method stub + return null; } @Override @@ -46,6 +55,11 @@ class VertexImpl extends ElementImpl implements Vertex { graph.removeVertex(this); } + @Override + public Edge addEdge(final Vertex inVertex) { + return addEdge(null, inVertex); + } + @Override public Edge addEdge(final Object id, final Vertex inVertex) { return this.graph.addEdge(id, this, inVertex); @@ -68,4 +82,5 @@ class VertexImpl extends ElementImpl implements Vertex { } edges.add(edge); } + }