Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more work on BasicQuery. Added a full gamut test case to GraphTestSui…

…te to validate the query() behavior.
  • Loading branch information...
commit 1a19b55d03eaf1b5d513612104560909fa7e69be 1 parent 244bcdc
@okram okram authored
View
63 blueprints-core/src/main/java/com/tinkerpop/blueprints/pgm/Query.java
@@ -1,6 +1,8 @@
package com.tinkerpop.blueprints.pgm;
/**
+ * A Query object defines a collection of filters and modifies that are used to intelligent select edges from a vertex.
+ *
* @author Matthias Brocheler (http://matthiasb.com)
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
@@ -10,24 +12,85 @@
public enum Direction {OUT, IN, BOTH}
+ /**
+ * Filter out the edge if it does not have a property with the specified value.
+ *
+ * @param key the key of the property
+ * @param value the value to check against
+ * @return the modified query object
+ */
public Query has(final String key, final Object value);
+ /**
+ * Filter out the edge if it does not have a property with a comparable value.
+ *
+ * @param key the key of the property
+ * @param value the value to check against
+ * @param compare the comparator to use for comparison
+ * @return the modified query object
+ */
public Query has(final String key, final Object value, final Compare compare);
+ /**
+ * Filter out the edge of its property value is not within the provided interval.
+ *
+ * @param key the key of the property
+ * @param startValue the inclusive start value of the interval
+ * @param endValue the exclusive end value of the interval
+ * @return the modified query object
+ */
public Query interval(final String key, final Object startValue, final Object endValue);
+ /**
+ * The direction of the edges to retrieve.
+ *
+ * @param direction whether to retrieve the incoming, outgoing, or both directions
+ * @return the modified query object
+ */
public Query direction(final Direction direction);
+ /**
+ * Filter out the edge if its label is not in set of provided labels.
+ *
+ * @param labels the labels to check against
+ * @return the modified query object
+ */
public Query labels(final String... labels);
+ /**
+ * Filter out the edge if the max number of edges to retrieve has already been reached.
+ *
+ * @param max the max number of edges to return
+ * @return the modified query object
+ */
public Query limit(final long max);
+ /**
+ * Execute the query and return the matching edges.
+ *
+ * @return the unfiltered edges
+ */
public Iterable<Edge> edges();
+ /**
+ * Execute the query and return the vertices on the other end of the matching edges.
+ *
+ * @return the unfiltered edge's vertices
+ */
public Iterable<Vertex> vertices();
+ /**
+ * Execute the query and return the number of edges that are unfiltered.
+ *
+ * @return the number of unfiltered edges
+ */
public long count();
+ /**
+ * Return the raw ids of the vertices on the other end of the edges.
+ *
+ * @return the raw ids of the vertices on the other end of the edges
+ */
public Object vertexIds();
}
View
74 blueprints-core/src/main/java/com/tinkerpop/blueprints/pgm/impls/BasicQuery.java
@@ -16,9 +16,11 @@
*/
public class BasicQuery implements Query {
+ private static final String[] EMPTY_LABELS = new String[]{};
+
private final Vertex vertex;
public Direction direction = Direction.BOTH;
- public String[] labels;
+ public String[] labels = EMPTY_LABELS;
public long limit = Long.MAX_VALUE;
public List<HasContainer> hasContainers = new LinkedList<HasContainer>();
@@ -94,7 +96,6 @@ public HasContainer(final String key, final Object value, final Compare compare)
public boolean isLegal(final Element element) {
final Object elementValue = element.getProperty(key);
-
switch (compare) {
case EQUAL:
if (null == elementValue)
@@ -129,11 +130,11 @@ public boolean isLegal(final Element element) {
private class QueryIterable<T extends Element> implements Iterable<T> {
private Iterable<Edge> iterable;
- private boolean isVertex;
+ private boolean forVertex;
- public QueryIterable(boolean isVertex) {
- this.isVertex = isVertex;
- List<Iterable<Edge>> temp = new ArrayList<Iterable<Edge>>(2);
+ public QueryIterable(final boolean forVertex) {
+ this.forVertex = forVertex;
+ final List<Iterable<Edge>> temp = new ArrayList<Iterable<Edge>>(2);
if (direction == Direction.OUT || direction == Direction.BOTH) {
temp.add(vertex.getOutEdges(labels));
}
@@ -152,51 +153,58 @@ public QueryIterable(boolean isVertex) {
private class QueryIterator<T extends Element> implements Iterator<T> {
Edge nextEdge = null;
- Iterator<Edge> itty;
+ final Iterator<Edge> itty;
long count = 0;
public QueryIterator() {
this.itty = iterable.iterator();
- this.loadNext();
}
public boolean hasNext() {
- return null != nextEdge;
+ if (null != this.nextEdge) {
+ return true;
+ } else {
+ return this.loadNext();
+ }
}
public T next() {
- if (nextEdge != null) {
- final Edge temp = nextEdge;
- this.loadNext();
- if (isVertex) {
- if (direction == Direction.OUT)
- return (T) temp.getInVertex();
- else if (direction == Direction.IN)
- return (T) temp.getOutVertex();
- else {
- if (temp.getInVertex() == vertex) {
- return (T) temp.getOutVertex();
- } else {
+ while (true) {
+ if (this.nextEdge != null) {
+ final Edge temp = this.nextEdge;
+ this.nextEdge = null;
+ if (forVertex) {
+ if (direction == Direction.OUT)
return (T) temp.getInVertex();
+ else if (direction == Direction.IN)
+ return (T) temp.getOutVertex();
+ else {
+ if (temp.getInVertex() == vertex) {
+ return (T) temp.getOutVertex();
+ } else {
+ return (T) temp.getInVertex();
+ }
}
- }
- } else {
- return (T) temp;
+ } else {
+ return (T) temp;
+ }
}
- } else
- throw new NoSuchElementException();
+
+ if (!this.loadNext())
+ throw new NoSuchElementException();
+ }
}
public void remove() {
throw new UnsupportedOperationException();
}
- private void loadNext() {
- nextEdge = null;
- if (count >= limit) return;
- while (itty.hasNext() && nextEdge == null) {
- Edge edge = itty.next();
+ private boolean loadNext() {
+ this.nextEdge = null;
+ if (count >= limit) return false;
+ while (this.itty.hasNext()) {
+ final Edge edge = this.itty.next();
boolean filter = false;
for (final HasContainer hasContainer : hasContainers) {
if (!hasContainer.isLegal(edge)) {
@@ -207,11 +215,11 @@ private void loadNext() {
if (!filter) {
this.nextEdge = edge;
this.count++;
+ return true;
}
}
+ return false;
}
-
-
}
}
}
View
8 blueprints-core/src/main/java/com/tinkerpop/blueprints/pgm/impls/tg/TinkerVertex.java
@@ -31,14 +31,6 @@ public TinkerVertex getRawVertex() {
return this;
}
- private static List<Edge> getAllEdges(final Map<String, Set<Edge>> theEdges) {
- final List<Edge> totalEdges = new LinkedList<Edge>();
- for (final Collection<Edge> edges : theEdges.values()) {
- totalEdges.addAll(edges);
- }
- return totalEdges;
- }
-
public Iterable<Edge> getInEdges(final String... labels) {
if (labels.length == 0) {
final List<Edge> totalEdges = new LinkedList<Edge>();
View
2  ...re/src/main/java/com/tinkerpop/blueprints/pgm/util/wrappers/readonly/ReadOnlyElement.java
@@ -50,6 +50,6 @@ public int hashCode() {
}
public boolean equals(Object object) {
- return (object.getClass().equals(this.getClass())) && this.rawElement.getId().equals(((ReadOnlyElement) object).getId());
+ return null != object && (object.getClass().equals(this.getClass())) && this.rawElement.getId().equals(((ReadOnlyElement) object).getId());
}
}
View
2  ...core/src/main/java/com/tinkerpop/blueprints/pgm/util/wrappers/wrapped/WrappedElement.java
@@ -36,7 +36,7 @@ public Object getId() {
}
public boolean equals(final Object object) {
- return null != object && this.getClass().equals(object.getClass()) && this.getId().equals(((Element) object).getId());
+ return null != object && (object.getClass().equals(this.getClass())) && this.rawElement.getId().equals(((WrappedElement) object).getId());
}
public int hashCode() {
View
2  ...graph-sail/src/test/java/com/tinkerpop/blueprints/pgm/oupls/sail/TinkerGraphSailTest.java
@@ -16,7 +16,7 @@ protected IndexableGraph createGraph() {
System.out.println(b.stringValue());
System.exit(1);
*/
-
+
return new TinkerGraph();
}
}
View
96 ...s-orient-graph/src/main/java/com/tinkerpop/blueprints/pgm/impls/orientdb/OrientGraph.java
@@ -1,10 +1,5 @@
package com.tinkerpop.blueprints.pgm.impls.orientdb;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import com.orientechnologies.orient.core.db.graph.OGraphDatabase;
import com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract;
import com.orientechnologies.orient.core.id.ORID;
@@ -28,6 +23,11 @@
import com.tinkerpop.blueprints.pgm.impls.orientdb.util.OrientElementSequence;
import com.tinkerpop.blueprints.pgm.util.AutomaticIndexHelper;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
/**
* A Blueprints implementation of the graph database OrientDB (http://www.orientechnologies.com)
*
@@ -66,21 +66,21 @@ public OrientGraph(final String url, final String username, final String passwor
@SuppressWarnings("unchecked")
public <T extends Element> AutomaticIndex<T> createAutomaticIndex(final String indexName, final Class<T> indexClass, final Set<String> indexKeys, final Parameter... indexParameters) {
final OrientGraphContext context = getContext(true);
-
- synchronized( contexts ){
- if (context.autoIndices.containsKey(indexName))
- throw new RuntimeException("Index already exists: " + indexName);
-
- final OrientAutomaticIndex<? extends Element> index = new OrientAutomaticIndex<OrientElement>(this, indexName, (Class<OrientElement>) indexClass, indexKeys);
-
- // ADD THE INDEX IN ALL CURRENT CONTEXTS
- for( OrientGraphContext ctx : contexts )
- ctx.autoIndices.put(index.getIndexName(), index);
-
- // SAVE THE CONFIGURATION INTO THE GLOBAL CONFIG
- saveIndexConfiguration();
-
- return (AutomaticIndex<T>) index;
+
+ synchronized (contexts) {
+ if (context.autoIndices.containsKey(indexName))
+ throw new RuntimeException("Index already exists: " + indexName);
+
+ final OrientAutomaticIndex<? extends Element> index = new OrientAutomaticIndex<OrientElement>(this, indexName, (Class<OrientElement>) indexClass, indexKeys);
+
+ // ADD THE INDEX IN ALL CURRENT CONTEXTS
+ for (OrientGraphContext ctx : contexts)
+ ctx.autoIndices.put(index.getIndexName(), index);
+
+ // SAVE THE CONFIGURATION INTO THE GLOBAL CONFIG
+ saveIndexConfiguration();
+
+ return (AutomaticIndex<T>) index;
}
}
@@ -88,20 +88,20 @@ public OrientGraph(final String url, final String username, final String passwor
public <T extends Element> Index<T> createManualIndex(final String indexName, final Class<T> indexClass, final Parameter... indexParameters) {
final OrientGraphContext context = getContext(true);
- synchronized( contexts ){
- if (context.manualIndices.containsKey(indexName))
- throw new RuntimeException("Index already exists: " + indexName);
-
- final OrientIndex<? extends OrientElement> index = new OrientIndex<OrientElement>(this, indexName, indexClass, Index.Type.MANUAL, null);
-
- // ADD THE INDEX IN ALL CURRENT CONTEXTS
- for( OrientGraphContext ctx : contexts )
- ctx.manualIndices.put(index.getIndexName(), index);
-
- // SAVE THE CONFIGURATION INTO THE GLOBAL CONFIG
- saveIndexConfiguration();
-
- return (Index<T>) index;
+ synchronized (contexts) {
+ if (context.manualIndices.containsKey(indexName))
+ throw new RuntimeException("Index already exists: " + indexName);
+
+ final OrientIndex<? extends OrientElement> index = new OrientIndex<OrientElement>(this, indexName, indexClass, Index.Type.MANUAL, null);
+
+ // ADD THE INDEX IN ALL CURRENT CONTEXTS
+ for (OrientGraphContext ctx : contexts)
+ ctx.manualIndices.put(index.getIndexName(), index);
+
+ // SAVE THE CONFIGURATION INTO THE GLOBAL CONFIG
+ saveIndexConfiguration();
+
+ return (Index<T>) index;
}
}
@@ -145,11 +145,11 @@ public void dropIndex(final String indexName) {
this.autoStartTransaction();
try {
- synchronized( contexts ){
- for( OrientGraphContext ctx : contexts ) {
- ctx.manualIndices.remove(indexName);
- ctx.autoIndices.remove(indexName);
- }
+ synchronized (contexts) {
+ for (OrientGraphContext ctx : contexts) {
+ ctx.manualIndices.remove(indexName);
+ ctx.autoIndices.remove(indexName);
+ }
}
getRawGraph().getMetadata().getIndexManager().dropIndex(indexName);
@@ -476,10 +476,10 @@ private OrientGraphContext openOrCreate(final boolean createDefaultIndices) {
context = new OrientGraphContext();
threadContext.set(context);
-
+
synchronized (contexts) {
- contexts.add( context );
- }
+ contexts.add(context);
+ }
context.rawGraph = new OGraphDatabase(url);
context.rawGraph.setUseCustomTypes(false);
@@ -553,13 +553,13 @@ private void removeContext() {
for (Index<? extends Element> idx : getIndices()) {
((OrientIndex<?>) idx).close();
}
-
- context.manualIndices.clear();
- context.autoIndices.clear();
-
+
+ context.manualIndices.clear();
+ context.autoIndices.clear();
+
synchronized (contexts) {
- contexts.remove( context );
- }
+ contexts.remove(context);
+ }
threadContext.set(null);
}
View
10 ...ient-graph/src/test/java/com/tinkerpop/blueprints/pgm/impls/orientdb/OrientGraphTest.java
@@ -1,8 +1,5 @@
package com.tinkerpop.blueprints.pgm.impls.orientdb;
-import java.io.File;
-import java.lang.reflect.Method;
-
import com.orientechnologies.orient.core.db.graph.ODatabaseGraphTx;
import com.tinkerpop.blueprints.pgm.AutomaticIndexTestSuite;
import com.tinkerpop.blueprints.pgm.EdgeTestSuite;
@@ -16,6 +13,9 @@
import com.tinkerpop.blueprints.pgm.impls.GraphTest;
import com.tinkerpop.blueprints.pgm.util.io.graphml.GraphMLReaderTestSuite;
+import java.io.File;
+import java.lang.reflect.Method;
+
/**
* Test suite for OrientDB graph implementation.
*
@@ -127,8 +127,8 @@ public void doTestSuite(final TestSuite testSuite) throws Exception {
} catch (Exception e) {
}
ODatabaseGraphTx g = new ODatabaseGraphTx("local:" + directory + "/graph");
- if( g.exists() )
- g.open("admin", "admin").drop();
+ if (g.exists())
+ g.open("admin", "admin").drop();
}
}
}
View
4 blueprints-rexster-graph/pom.xml
@@ -61,7 +61,9 @@
<version>2.5</version>
<configuration>
- <argLine>-DtestRexsterGraph=false -Dusername=rexster -Dpassword=rexster -DrexsterGraphURI=http://127.0.0.1:8182/graphs/emptygraph</argLine>
+ <argLine>-DtestRexsterGraph=false -Dusername=rexster -Dpassword=rexster
+ -DrexsterGraphURI=http://127.0.0.1:8182/graphs/emptygraph
+ </argLine>
</configuration>
</plugin>
</plugins>
View
4 .../src/main/java/com/tinkerpop/blueprints/pgm/impls/rexster/util/RexsterAuthentication.java
@@ -23,8 +23,8 @@ public String getUsername() {
public String getPassword() {
return password;
}
-
- public String getAuthenticationHeaderValue(){
+
+ public String getAuthenticationHeaderValue() {
return "Basic " + Base64.encodeBase64URLSafeString((username + ":" + password).getBytes());
}
}
View
4 ...ster-graph/src/test/java/com/tinkerpop/blueprints/pgm/impls/rexster/RexsterGraphTest.java
@@ -17,7 +17,7 @@
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class RexsterGraphTest extends GraphTest {
-
+
private String username = null;
private String password = null;
@@ -102,7 +102,7 @@ public void doTestSuite(final TestSuite testSuite) throws Exception {
this.username = System.getProperty("username");
this.password = System.getProperty("password");
-
+
this.resetGraph();
for (Method method : testSuite.getClass().getDeclaredMethods()) {
if (method.getName().startsWith("test")) {
View
173 blueprints-test/src/main/java/com/tinkerpop/blueprints/pgm/GraphTestSuite.java
@@ -428,7 +428,7 @@ public void testVertexEdgeLabels() {
}
- /*public void testVertexEdgeFilters() {
+ public void testVertexQuery() {
if (!graphTest.isRDFModel) {
Graph graph = graphTest.getGraphInstance();
@@ -449,99 +449,156 @@ public void testVertexEdgeLabels() {
// out edges
- List<Edge> results = asList(a.getOutEdges("friend", new Filter().property("amount", 1.0)));
- assertEquals(results.size(), 1);
+ List results = asList(a.query().direction(Query.Direction.OUT).edges());
+ assertEquals(results.size(), 3);
assertTrue(results.contains(aFriendB));
+ assertTrue(results.contains(aFriendC));
+ assertTrue(results.contains(aHateC));
+ results = asList(a.query().direction(Query.Direction.OUT).vertices());
+ assertEquals(results.size(), 3);
+ assertTrue(results.contains(b));
+ assertTrue(results.contains(c));
+ assertEquals(a.query().direction(Query.Direction.OUT).count(), 3);
- results = asList(a.getOutEdges("blah", new Filter().property("amount", 1.0)));
- assertEquals(results.size(), 0);
- results = asList(a.getOutEdges(new Filter().property("amount", 1.0)));
- assertEquals(results.size(), 2);
+ results = asList(a.query().direction(Query.Direction.OUT).labels("hate", "friend").edges());
+ assertEquals(results.size(), 3);
assertTrue(results.contains(aFriendB));
+ assertTrue(results.contains(aFriendC));
assertTrue(results.contains(aHateC));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("hate", "friend").vertices());
+ assertEquals(results.size(), 3);
+ assertTrue(results.contains(b));
+ assertTrue(results.contains(c));
+ assertEquals(a.query().direction(Query.Direction.OUT).labels("hate", "friend").count(), 3);
- results = asList(a.getOutEdges("friend", new Filter().property("amount", 1.0).property("amount", 1.0)));
- assertEquals(results.size(), 1);
- assertTrue(results.contains(aFriendB));
-
- results = asList(a.getOutEdges("friend", new Filter().property("amount", 1.0), "hate"));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").edges());
assertEquals(results.size(), 2);
assertTrue(results.contains(aFriendB));
- assertTrue(results.contains(aHateC));
+ assertTrue(results.contains(aFriendC));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").vertices());
+ assertEquals(results.size(), 2);
+ assertTrue(results.contains(b));
+ assertTrue(results.contains(c));
+ assertEquals(a.query().direction(Query.Direction.OUT).labels("friend").count(), 2);
- results = asList(a.getOutEdges(new Filter().property("amount", 1.0).property("date", 10)));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 1.0).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(aFriendB));
-
- results = asList(a.getOutEdges(new Filter().property("amount", 1.0).property("date", 10).label("friend")));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 1.0).vertices());
assertEquals(results.size(), 1);
- assertTrue(results.contains(aFriendB));
+ assertTrue(results.contains(b));
+ assertEquals(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 1.0).count(), 1);
- results = asList(a.getOutEdges(new Filter().property("amount", 1.0).property("date", 10), "hate"));
- assertEquals(results.size(), 0);
-
- results = asList(a.getOutEdges(new Filter().range("date", 5, 12)));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.NOT_EQUAL).edges());
assertEquals(results.size(), 1);
- assertTrue(results.contains(aFriendB));
+ assertTrue(results.contains(aFriendC));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.NOT_EQUAL).vertices());
+ assertEquals(results.size(), 1);
+ assertTrue(results.contains(c));
+ assertEquals(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.NOT_EQUAL).count(), 1);
- results = asList(a.getOutEdges(new Filter().range("date", 5, 9)));
- assertEquals(results.size(), 0);
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.LESS_THAN_EQUAL).edges());
+ assertEquals(results.size(), 2);
+ assertTrue(results.contains(aFriendB));
+ assertTrue(results.contains(aFriendC));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.LESS_THAN_EQUAL).vertices());
+ assertEquals(results.size(), 2);
+ assertTrue(results.contains(b));
+ assertTrue(results.contains(c));
+ assertEquals(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 1.0, Query.Compare.LESS_THAN_EQUAL).count(), 2);
- results = asList(a.getOutEdges(new Filter().property("amount", 0.6, Filter.Compare.LESS_THAN)));
+ results = asList(a.query().direction(Query.Direction.OUT).has("amount", 1.0, Query.Compare.LESS_THAN).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(aFriendC));
+ results = asList(a.query().direction(Query.Direction.OUT).has("amount", 1.0, Query.Compare.LESS_THAN).vertices());
+ assertEquals(results.size(), 1);
+ assertTrue(results.contains(c));
+ assertEquals(a.query().direction(Query.Direction.OUT).has("amount", 1.0, Query.Compare.LESS_THAN).count(), 1);
- results = asList(a.getOutEdges(new Filter().property("amount", 0.5, Filter.Compare.LESS_THAN_EQUAL)));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 0.5).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(aFriendC));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").has("amount", 0.5).vertices());
+ assertEquals(results.size(), 1);
+ assertTrue(results.contains(c));
+
+ results = asList(a.query().direction(Query.Direction.IN).labels("hate", "friend").has("amount", 0.5, Query.Compare.GREATER_THAN).edges());
+ assertEquals(results.size(), 1);
+ assertTrue(results.contains(cHateA));
+ results = asList(a.query().direction(Query.Direction.IN).labels("hate", "friend").has("amount", 0.5, Query.Compare.GREATER_THAN).vertices());
+ assertEquals(results.size(), 1);
+ assertTrue(results.contains(c));
+ assertEquals(a.query().direction(Query.Direction.IN).labels("hate", "friend").has("amount", 0.5, Query.Compare.GREATER_THAN).count(), 1);
- results = asList(a.getOutEdges(new Filter().property("amount", 0.49, Filter.Compare.LESS_THAN_EQUAL)));
+ results = asList(a.query().direction(Query.Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN).edges());
+ assertEquals(results.size(), 0);
+ results = asList(a.query().direction(Query.Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN).vertices());
assertEquals(results.size(), 0);
+ assertEquals(a.query().direction(Query.Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN).count(), 0);
- // in edges
+ results = asList(a.query().direction(Query.Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN_EQUAL).edges());
+ assertEquals(results.size(), 1);
+ assertTrue(results.contains(cHateA));
+ results = asList(a.query().direction(Query.Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN_EQUAL).vertices());
+ assertEquals(results.size(), 1);
+ assertTrue(results.contains(c));
+ assertEquals(a.query().direction(Query.Direction.IN).labels("hate").has("amount", 1.0, Query.Compare.GREATER_THAN_EQUAL).count(), 1);
+
+ results = asList(a.query().direction(Query.Direction.OUT).interval("date", 5, 10).edges());
+ assertEquals(results.size(), 0);
+ results = asList(a.query().direction(Query.Direction.OUT).interval("date", 5, 10).vertices());
+ assertEquals(results.size(), 0);
+ assertEquals(a.query().direction(Query.Direction.OUT).interval("date", 5, 10).count(), 0);
- results = asList(b.getInEdges(new Filter().property("amount", 1.0)));
+ results = asList(a.query().direction(Query.Direction.OUT).interval("date", 5, 11).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(aFriendB));
+ results = asList(a.query().direction(Query.Direction.OUT).interval("date", 5, 11).vertices());
+ assertEquals(results.size(), 1);
+ assertTrue(results.contains(b));
+ assertEquals(a.query().direction(Query.Direction.OUT).interval("date", 5, 11).count(), 1);
- results = asList(b.getInEdges(new Filter().property("amount", 0.4, Filter.Compare.GREATER_THAN_EQUAL)));
- assertEquals(results.size(), 2);
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").interval("date", 5, 11).edges());
+ assertEquals(results.size(), 1);
assertTrue(results.contains(aFriendB));
- assertTrue(results.contains(cHateB));
-
- results = asList(c.getInEdges("friend", new Filter().property("amount", 0.4, Filter.Compare.GREATER_THAN)));
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").interval("date", 5, 11).vertices());
assertEquals(results.size(), 1);
- assertTrue(results.contains(aFriendC));
+ assertTrue(results.contains(b));
+ assertEquals(a.query().direction(Query.Direction.OUT).labels("friend").interval("date", 5, 11).count(), 1);
- results = asList(c.getInEdges("friend", "hate", new Filter().property("amount", 0.4, Filter.Compare.GREATER_THAN)));
- assertEquals(results.size(), 2);
- assertTrue(results.contains(aHateC));
+ results = asList(a.query().direction(Query.Direction.BOTH).labels("friend", "hate").edges());
+ assertEquals(results.size(), 4);
+ assertTrue(results.contains(aFriendB));
assertTrue(results.contains(aFriendC));
+ assertTrue(results.contains(aHateC));
+ assertTrue(results.contains(cHateA));
+ results = asList(a.query().direction(Query.Direction.BOTH).labels("friend", "hate").vertices());
+ assertEquals(results.size(), 4);
+ assertTrue(results.contains(b));
+ assertTrue(results.contains(c));
+ // TODO: need to wrap vertex: assertFalse(results.contains(a));
+ assertEquals(a.query().direction(Query.Direction.BOTH).labels("friend", "hate").count(), 4);
+
+ results = asList(a.query().labels("friend", "hate").limit(2).edges());
+ assertEquals(results.size(), 2);
+ results = asList(a.query().labels("friend", "hate").limit(2).vertices());
+ assertEquals(results.size(), 2);
+ assertTrue(results.contains(b));
+ assertTrue(results.contains(c));
+ assertFalse(results.contains(a));
+ assertEquals(a.query().labels("friend", "hate").limit(2).count(), 2);
- // test object type exceptions
-
- try {
- a.getOutEdges(1, "hello");
- assertTrue(false);
- } catch (Exception e) {
- assertTrue(true);
- assertTrue(e instanceof IllegalArgumentException);
-
- }
-
- try {
- a.getInEdges(1, "hello");
- assertTrue(false);
- } catch (Exception e) {
- assertTrue(true);
- assertTrue(e instanceof IllegalArgumentException);
-
- }
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").limit(0).edges());
+ assertEquals(results.size(), 0);
+ results = asList(a.query().direction(Query.Direction.OUT).labels("friend").limit(0).vertices());
+ assertEquals(results.size(), 0);
+ assertEquals(a.query().direction(Query.Direction.OUT).labels("friend").limit(0).count(), 0);
graph.shutdown();
}
- }*/
+
+ }
public void testVertexEdgeLabels2() {
Please sign in to comment.
Something went wrong with that request. Please try again.