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

work on nested graph library

parent 76ecb91a
No related branches found
No related tags found
1 merge request!17Get impletemented stages and Java 8
package kieker.analysis.graph; package kieker.analysis.graph;
import com.tinkerpop.blueprints.Graph; import kieker.analysis.graph.impl.GraphImpl;
import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
public class GraphTester { public class GraphTester {
public static void main(final String[] args) { public static void main(final String[] args) {
Graph graph1 = new TinkerGraph(); Graph graph = new GraphImpl();
Graph graph2 = new TinkerGraph();
com.tinkerpop.blueprints.Vertex g1n1 = graph1.addVertex("g1::n1"); Vertex node1 = graph.addVertex("n1");
com.tinkerpop.blueprints.Vertex g2n1 = graph2.addVertex("g2::n1"); Vertex node2 = graph.addVertex("n2");
com.tinkerpop.blueprints.Edge edge = g1n1.addEdge("...", g2n1); Graph subgraph = node1.addSubgraph();
System.out.println(graph1); Vertex node11 = subgraph.addVertex("n1::n1");
System.out.println(graph2);
// node2.addEdgeTo(node11);
/*
* Graph graph = new GraphImpl();
*
* Vertex node1 = graph.addVertex("n1");
*
* Vertex node2 = graph.addVertex("n2");
*
* Graph subgraph = node1.addSubgraph();
*
* Vertex node11 = subgraph.addVertex("n1::n1");
*
* node2.addEdgeTo(node11);*
*
*/
} }
} }
...@@ -8,9 +8,9 @@ public interface Vertex extends Element { ...@@ -8,9 +8,9 @@ public interface Vertex extends Element {
public Graph addSubgraph(); public Graph addSubgraph();
// public Iterable<Edge> getEdges(Direction direction, String... labels); // public Iterable<Edge> getEdges(Direction direction);
// public Iterable<Vertex> getVertices(Direction direction, String... labels); // public Iterable<Vertex> getVertices(Direction direction);
public Edge addEdge(Vertex inVertex); public Edge addEdge(Vertex inVertex);
......
package kieker.analysis.graph.impl;
/**
* The ExceptionFactory provides standard exceptions for graphs.
*
* @author Sören Henning
*/
class ExceptionFactory {
// Graph related exceptions
public static IllegalArgumentException vertexIdCanNotBeNull() {
return new IllegalArgumentException("Vertex id can not be null");
}
public static IllegalArgumentException edgeIdCanNotBeNull() {
return new IllegalArgumentException("Edge id can not be null");
}
public static IllegalArgumentException vertexWithIdAlreadyExists(final Object id) {
return new IllegalArgumentException("Vertex with id already exists: " + id);
}
public static IllegalArgumentException edgeWithIdAlreadyExists(final Object id) {
return new IllegalArgumentException("Edge with id already exists: " + id);
}
public static IllegalStateException vertexWithIdDoesNotExist(final Object id) {
return new IllegalStateException("Vertex with id does not exist: " + id);
}
public static IllegalStateException edgeWithIdDoesNotExist(final Object id) {
return new IllegalStateException("Edge with id does not exist: " + id);
}
// Element related exceptions
public static IllegalArgumentException propertyKeyIsReserved(final String key) {
return new IllegalArgumentException("Property key is reserved for all elements: " + key);
}
public static IllegalArgumentException propertyKeyCanNotBeEmpty() {
return new IllegalArgumentException("Property key can not be the empty string");
}
public static IllegalArgumentException propertyKeyCanNotBeNull() {
return new IllegalArgumentException("Property key can not be null");
}
public static IllegalArgumentException propertyValueCanNotBeNull() {
return new IllegalArgumentException("Property value can not be null");
}
}
...@@ -27,7 +27,7 @@ public class GraphImpl implements Graph { ...@@ -27,7 +27,7 @@ public class GraphImpl implements Graph {
} else { } else {
idString = id.toString(); idString = id.toString();
if (vertices.containsKey(idString)) { if (vertices.containsKey(idString)) {
// TODO Throw Exception ExceptionFactory.vertexWithIdAlreadyExists(id) throw ExceptionFactory.vertexWithIdAlreadyExists(id);
} }
} }
...@@ -38,7 +38,9 @@ public class GraphImpl implements Graph { ...@@ -38,7 +38,9 @@ public class GraphImpl implements Graph {
@Override @Override
public Vertex getVertex(final Object id) { public Vertex getVertex(final Object id) {
// TODO exception if not exists if (id == null) {
throw ExceptionFactory.vertexIdCanNotBeNull();
}
String idString = id.toString(); String idString = id.toString();
return this.vertices.get(idString); return this.vertices.get(idString);
} }
...@@ -68,21 +70,23 @@ public class GraphImpl implements Graph { ...@@ -68,21 +70,23 @@ public class GraphImpl implements Graph {
} else { } else {
idString = id.toString(); idString = id.toString();
if (edges.containsKey(idString)) { if (edges.containsKey(idString)) {
// TODO Throw Exception ExceptionFactory.edgeWithIdAlreadyExists(id) throw ExceptionFactory.edgeWithIdAlreadyExists(id);
} }
} }
Edge edge = new EdgeImpl(idString, outVertex, inVertex, this); Edge edge = new EdgeImpl(idString, outVertex, inVertex, this);
edges.put(edge.getId().toString(), edge); this.edges.put(edge.getId().toString(), edge);
((VertexImpl) outVertex).addOutEdge(idString, edge);
// TODO Add Edge to vertices ((VertexImpl) inVertex).addInEdge(idString, edge);
return edge; return edge;
} }
@Override @Override
public Edge getEdge(final Object id) { public Edge getEdge(final Object id) {
// TODO exception if not exists if (id == null) {
throw ExceptionFactory.edgeIdCanNotBeNull();
}
String idString = id.toString(); String idString = id.toString();
return this.edges.get(idString); return this.edges.get(idString);
} }
......
package kieker.analysis.graph.impl; package kieker.analysis.graph.impl;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import kieker.analysis.graph.Edge; import kieker.analysis.graph.Edge;
import kieker.analysis.graph.Graph; import kieker.analysis.graph.Graph;
import kieker.analysis.graph.Vertex; import kieker.analysis.graph.Vertex;
class VertexImpl extends ElementImpl implements Vertex { class VertexImpl extends ElementImpl implements Vertex {
protected Map<String, Set<Edge>> outEdges = new HashMap<String, Set<Edge>>();
protected Map<String, Set<Edge>> inEdges = new HashMap<String, Set<Edge>>();
protected VertexImpl(final String id, final GraphImpl graph) { protected VertexImpl(final String id, final GraphImpl graph) {
super(id, graph); super(id, graph);
} }
@Override @Override
public Boolean hasSubgraph() { public Graph addSubgraph() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return null;
} }
@Override @Override
public Graph getSubgraph() { public Boolean hasSubgraph() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
@Override @Override
public Graph addSubgraph() { public Graph getSubgraph() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
...@@ -33,13 +41,31 @@ class VertexImpl extends ElementImpl implements Vertex { ...@@ -33,13 +41,31 @@ class VertexImpl extends ElementImpl implements Vertex {
return addEdge(null, inVertex); return addEdge(null, inVertex);
} }
@Override
public void remove() {
graph.removeVertex(this);
}
@Override @Override
public Edge addEdge(final Object id, final Vertex inVertex) { public Edge addEdge(final Object id, final Vertex inVertex) {
return this.graph.addEdge(id, this, inVertex); return this.graph.addEdge(id, this, inVertex);
} }
@Override protected void addOutEdge(final String idString, final Edge edge) {
public void remove() { Set<Edge> edges = this.outEdges.get(idString);
graph.removeVertex(this); if (edges == null) {
edges = new HashSet<Edge>();
this.outEdges.put(idString, edges);
}
edges.add(edge);
}
protected void addInEdge(final String idString, final Edge edge) {
Set<Edge> edges = this.inEdges.get(idString);
if (edges == null) {
edges = new HashSet<Edge>();
this.inEdges.put(idString, edges);
}
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