From 0e0bc9e10e50d06da55cc32bac11442c256b9b7b Mon Sep 17 00:00:00 2001 From: SeH <1s1e1h1@gmail.com> Date: Sun, 7 Jun 2015 23:08:17 -0400 Subject: [PATCH] graph test suite works, remaining: edge test suite --- .../java/com/syncleus/spangraph/MapGraph.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/syncleus/spangraph/MapGraph.java b/src/main/java/com/syncleus/spangraph/MapGraph.java index ad896d1..278f96d 100644 --- a/src/main/java/com/syncleus/spangraph/MapGraph.java +++ b/src/main/java/com/syncleus/spangraph/MapGraph.java @@ -80,12 +80,7 @@ abstract public class MapGraph<X extends Serializable> implements Graph { return edgeCollection().size(); } - public enum FileType { - JAVA, - GML, - GRAPHML, - GRAPHSON - } + protected MapGraph() { super(); @@ -230,9 +225,17 @@ abstract public class MapGraph<X extends Serializable> implements Graph { return this.vertices.values(); } + /* + * Return an iterable to all the vertices in the graph that have a particular key/value property. + * If this is not possible for the implementation, then an UnsupportedOperationException can be thrown. + * The graph implementation should use indexing structures to make this efficient else a full vertex-filter scan is required. + */ @Override public Iterable<Vertex> getVertices(String s, Object o) { - return null; + //TODO write a subclass with a property->vertex reverse index + return Iterables.filter(getVertices(), + v -> ((MVertex)v).hasProperty(s, o) + ); } public Iterable<Edge> getEdges() { @@ -242,7 +245,10 @@ abstract public class MapGraph<X extends Serializable> implements Graph { @Override public Iterable<Edge> getEdges(String s, Object o) { - return null; + //TODO write a subclass with a property->edge reverse index + return Iterables.filter(getEdges(), + e -> ((MEdge)e).hasProperty(s, o) + ); } public void removeVertex(final Vertex vertex) { @@ -418,6 +424,12 @@ abstract public class MapGraph<X extends Serializable> implements Graph { this.id = id; } + public boolean hasProperty(String k, Object value) { + if (properties == null) return false; + Serializable x = properties.get(k); + if (x == null) return false; + return x.equals(value); + } public Map<String, Serializable> prop(final boolean createIfMissing) { -- GitLab