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

work on nested graph library

parent c7edfff3
No related branches found
No related tags found
1 merge request!17Get impletemented stages and Java 8
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;
}
}
}
......@@ -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;
}
......@@ -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");
......
......@@ -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);
......
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();
}
}
}
......@@ -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) {
......
......@@ -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() {
......
......@@ -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);
}
}
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