Permalink
Browse files

added MockSequalizable.equals(). Updated Query with Query.has(key,com…

…pare,value). The equivalent of Query.has(key,value,compare) has been deprecated.
  • Loading branch information...
1 parent 6f14fbc commit 8b49a3eeab6eeb4f55bc3c3dbb0b0ee71761c8db @okram okram committed Mar 28, 2013
@@ -10,9 +10,13 @@
public GraphQuery has(final String key, final Object value);
@Override
+ @Deprecated
public <T extends Comparable<T>> GraphQuery has(final String key, final T value, final Compare compare);
@Override
+ public <T extends Comparable<T>> GraphQuery has(final String key, final Compare compare, final T value);
+
+ @Override
public <T extends Comparable<T>> GraphQuery interval(final String key, final T startValue, final T endValue);
@Override
@@ -43,9 +43,20 @@ else if (this.equals(LESS_THAN))
* @param compare the comparator to use for comparison
* @return the modified query object
*/
+ @Deprecated
public <T extends Comparable<T>> Query has(final String key, final T value, final Compare compare);
/**
+ * Filter out the edge if it does not have a property with a comparable value.
+ *
+ * @param key the key of the property
+ * @param compare the comparator to use for comparison
+ * @param value the value to check against
+ * @return the modified query object
+ */
+ public <T extends Comparable<T>> Query has(final String key, final Compare compare, final T value);
+
+ /**
* Filter out the edge of its property value is not within the provided interval.
*
* @param key the key of the property
@@ -44,9 +44,13 @@
public VertexQuery has(final String key, final Object value);
@Override
+ @Deprecated
public <T extends Comparable<T>> VertexQuery has(final String key, final T value, final Compare compare);
@Override
+ public <T extends Comparable<T>> VertexQuery has(final String key, final Compare compare, final T value);
+
+ @Override
public <T extends Comparable<T>> VertexQuery interval(final String key, final T startValue, final T endValue);
@Override
@@ -31,6 +31,10 @@ public GraphQuery has(final String key, final Object value) {
}
public <T extends Comparable<T>> GraphQuery has(final String key, final T value, final Compare compare) {
+ return this.has(key, compare, value);
+ }
+
+ public <T extends Comparable<T>> GraphQuery has(final String key, final Compare compare, final T value) {
this.hasContainers.add(new HasContainer(key, value, compare));
return this;
}
@@ -3,8 +3,8 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
-import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.VertexQuery;
import java.util.ArrayList;
import java.util.Iterator;
@@ -31,6 +31,10 @@ public VertexQuery has(final String key, final Object value) {
}
public <T extends Comparable<T>> VertexQuery has(final String key, final T value, final Compare compare) {
+ return this.has(key, compare, value);
+ }
+
+ public <T extends Comparable<T>> VertexQuery has(final String key, final Compare compare, final T value) {
this.hasContainers.add(new HasContainer(key, value, compare));
return this;
}
@@ -21,7 +21,11 @@ public GraphQuery has(final String key, final Object value) {
}
public <T extends Comparable<T>> GraphQuery has(final String key, final T value, final Compare compare) {
- this.query = this.query.has(key, value, compare);
+ return this.has(key, compare, value);
+ }
+
+ public <T extends Comparable<T>> GraphQuery has(final String key, final Compare compare, final T value) {
+ this.query = this.query.has(key, compare, value);
return this;
}
@@ -2,8 +2,8 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
-import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.VertexQuery;
/**
* A WrapperQuery is useful for wrapping the construction and results of a Vertex.query().
@@ -25,7 +25,11 @@ public VertexQuery has(final String key, final Object value) {
}
public <T extends Comparable<T>> VertexQuery has(final String key, final T value, final Compare compare) {
- this.query = this.query.has(key, value, compare);
+ return this.has(key, compare, value);
+ }
+
+ public <T extends Comparable<T>> VertexQuery has(final String key, final Compare compare, final T value) {
+ this.query = this.query.has(key, compare, value);
return this;
}
@@ -3,8 +3,8 @@
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
-import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.Vertex;
+import com.tinkerpop.blueprints.VertexQuery;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
@@ -39,6 +39,10 @@ public VertexQuery has(final String key, final Object value) {
}
public <T extends Comparable<T>> VertexQuery has(final String key, final T value, final Compare compare) {
+ return this.has(key, compare, value);
+ }
+
+ public <T extends Comparable<T>> VertexQuery has(final String key, final Compare compare, final T value) {
this.hasContainers.add(new HasContainer(key, value, compare));
return this;
}
@@ -83,31 +83,31 @@ public void testVertexQuery() {
assertTrue(results.contains(b));
assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0).count(), 1);
- results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.NOT_EQUAL).edges());
+ results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", VertexQuery.Compare.NOT_EQUAL, 1.0).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(aFriendC));
- results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.NOT_EQUAL).vertices());
+ results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", VertexQuery.Compare.NOT_EQUAL, 1.0).vertices());
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.NOT_EQUAL).count(), 1);
+ assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", VertexQuery.Compare.NOT_EQUAL, 1.0).count(), 1);
- results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.LESS_THAN_EQUAL).edges());
+ results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", VertexQuery.Compare.LESS_THAN_EQUAL, 1.0).edges());
assertEquals(results.size(), 2);
assertTrue(results.contains(aFriendB));
assertTrue(results.contains(aFriendC));
- results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.LESS_THAN_EQUAL).vertices());
+ results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", VertexQuery.Compare.LESS_THAN_EQUAL, 1.0).vertices());
assertEquals(results.size(), 2);
assertTrue(results.contains(b));
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", 1.0, VertexQuery.Compare.LESS_THAN_EQUAL).count(), 2);
+ assertEquals(a.query().direction(Direction.OUT).labels("friend").has("amount", VertexQuery.Compare.LESS_THAN_EQUAL, 1.0).count(), 2);
- results = asList(a.query().direction(Direction.OUT).has("amount", 1.0, VertexQuery.Compare.LESS_THAN).edges());
+ results = asList(a.query().direction(Direction.OUT).has("amount", VertexQuery.Compare.LESS_THAN, 1.0).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(aFriendC));
- results = asList(a.query().direction(Direction.OUT).has("amount", 1.0, VertexQuery.Compare.LESS_THAN).vertices());
+ results = asList(a.query().direction(Direction.OUT).has("amount", VertexQuery.Compare.LESS_THAN, 1.0).vertices());
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.OUT).has("amount", 1.0, VertexQuery.Compare.LESS_THAN).count(), 1);
+ assertEquals(a.query().direction(Direction.OUT).has("amount", VertexQuery.Compare.LESS_THAN, 1.0).count(), 1);
results = asList(a.query().direction(Direction.OUT).labels("friend").has("amount", 0.5).edges());
assertEquals(results.size(), 1);
@@ -116,27 +116,27 @@ public void testVertexQuery() {
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- results = asList(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", 0.5, VertexQuery.Compare.GREATER_THAN).edges());
+ results = asList(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", VertexQuery.Compare.GREATER_THAN, 0.5).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(cHateA));
- results = asList(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", 0.5, VertexQuery.Compare.GREATER_THAN).vertices());
+ results = asList(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", VertexQuery.Compare.GREATER_THAN, 0.5).vertices());
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", 0.5, VertexQuery.Compare.GREATER_THAN).count(), 1);
+ assertEquals(a.query().direction(Direction.IN).labels("hate", "friend").has("amount", VertexQuery.Compare.GREATER_THAN, 0.5).count(), 1);
- results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN).edges());
+ results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", VertexQuery.Compare.GREATER_THAN, 1.0).edges());
assertEquals(results.size(), 0);
- results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN).vertices());
+ results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", VertexQuery.Compare.GREATER_THAN, 1.0).vertices());
assertEquals(results.size(), 0);
- assertEquals(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN).count(), 0);
+ assertEquals(a.query().direction(Direction.IN).labels("hate").has("amount", VertexQuery.Compare.GREATER_THAN, 1.0).count(), 0);
- results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN_EQUAL).edges());
+ results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", VertexQuery.Compare.GREATER_THAN_EQUAL, 1.0).edges());
assertEquals(results.size(), 1);
assertTrue(results.contains(cHateA));
- results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN_EQUAL).vertices());
+ results = asList(a.query().direction(Direction.IN).labels("hate").has("amount", VertexQuery.Compare.GREATER_THAN_EQUAL, 1.0).vertices());
assertEquals(results.size(), 1);
assertTrue(results.contains(c));
- assertEquals(a.query().direction(Direction.IN).labels("hate").has("amount", 1.0, VertexQuery.Compare.GREATER_THAN_EQUAL).count(), 1);
+ assertEquals(a.query().direction(Direction.IN).labels("hate").has("amount", VertexQuery.Compare.GREATER_THAN_EQUAL, 1.0).count(), 1);
results = asList(a.query().direction(Direction.OUT).interval("date", 5, 10).edges());
assertEquals(results.size(), 0);
@@ -228,12 +228,12 @@ public void testGraphQueryForVertices() {
assertEquals(count(vertices), 1);
// assertEquals(vertices.iterator().next().getProperty("name"), "marko");
- vertices = graph.query().has("age", 29, Query.Compare.GREATER_THAN_EQUAL).vertices();
+ vertices = graph.query().has("age", Query.Compare.GREATER_THAN_EQUAL, 29).vertices();
assertEquals(count(vertices), 1);
assertEquals(vertices.iterator().next().getProperty("name"), "marko");
assertEquals(vertices.iterator().next().getProperty("age"), 33);
- vertices = graph.query().has("age", 28, Query.Compare.GREATER_THAN_EQUAL).vertices();
+ vertices = graph.query().has("age", Query.Compare.GREATER_THAN_EQUAL, 28).vertices();
assertEquals(count(vertices), 2);
names = new HashSet<String>();
for (Vertex v : vertices) {
@@ -16,4 +16,14 @@ public void setTestField(String testField) {
this.testField = testField;
}
+ @Override
+ public boolean equals(Object oth) {
+ if (this == oth) return true;
+ else if (oth == null) return false;
+ else if (!getClass().isInstance(oth)) return false;
+ MockSerializable m = (MockSerializable) oth;
+ if (testField == null) {
+ return (m.testField == null);
+ } else return testField.equals(m.testField);
+ }
}

0 comments on commit 8b49a3e

Please sign in to comment.