You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/05/29 20:41:09 UTC

[1/6] incubator-tinkerpop git commit: Finalize a variable.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/neo4j-gremlin-apache c19398c1d -> 7b528b218


Finalize a variable.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/da00130c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/da00130c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/da00130c

Branch: refs/heads/neo4j-gremlin-apache
Commit: da00130c63a89792bc8c69a3b7a1458fe7103165
Parents: 0b4e555
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 29 12:22:06 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 29 12:22:06 2015 -0400

----------------------------------------------------------------------
 .../gremlin/driver/ser/JsonMessageSerializerV1d0Test.java          | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/da00130c/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerV1d0Test.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerV1d0Test.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerV1d0Test.java
index ef7dcc2..fe81f70 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerV1d0Test.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerV1d0Test.java
@@ -106,7 +106,7 @@ public class JsonMessageSerializerV1d0Test {
     @Test
     public void serializeToJsonIteratorNullElement() throws Exception {
 
-        ArrayList<FunObject> funList = new ArrayList<>();
+        final ArrayList<FunObject> funList = new ArrayList<>();
         funList.add(new FunObject("x"));
         funList.add(null);
         funList.add(new FunObject("y"));


[4/6] incubator-tinkerpop git commit: Add tests for ElementHelper.

Posted by ok...@apache.org.
Add tests for ElementHelper.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/5a41ae8c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/5a41ae8c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/5a41ae8c

Branch: refs/heads/neo4j-gremlin-apache
Commit: 5a41ae8c67141ad1cd7a48128ff378bfad8edfb3
Parents: c1d15ca
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 29 13:38:58 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 29 13:38:58 2015 -0400

----------------------------------------------------------------------
 .../gremlin/structure/util/ElementHelper.java   | 26 +++++--
 .../structure/util/ElementHelperTest.java       | 74 +++++++++++++++-----
 2 files changed, 79 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/5a41ae8c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
index 024e07f..0245086 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
@@ -117,19 +117,31 @@ public final class ElementHelper {
     }
 
     /**
-     * Remove a key from the set of key value pairs. Assumes that validations have already taken place to
+     * Remove a key from the set of key/value pairs. Assumes that validations have already taken place to
      * assure that key positions contain strings and that there are an even number of elements. If after removal
      * there are no values left, the key value list is returned as empty.
+     *
+     * @param keyToRemove the key to remove
+     * @param keyValues the list to remove the accessor from
+     * @return the key/values without the specified accessor or an empty array if no values remain after removal
      */
     public static Optional<Object[]> remove(final String keyToRemove, final Object... keyValues) {
         return ElementHelper.remove((Object) keyToRemove, keyValues);
     }
 
+    /**
+     * Removes an accessor from the set of key/value pairs. Assumes that validations have already taken place to
+     * assure that key positions contain strings and that there are an even number of elements. If after removal
+     * there are no values left, the key value list is returned as empty.
+     *
+     * @param accessor to remove
+     * @param keyValues the list to remove the accessor from
+     * @return the key/values without the specified accessor or an empty array if no values remain after removal
+     */
     public static Optional<Object[]> remove(final T accessor, final Object... keyValues) {
         return ElementHelper.remove((Object) accessor, keyValues);
     }
 
-
     private static Optional<Object[]> remove(final Object keyToRemove, final Object... keyValues) {
         final List list = Arrays.asList(keyValues);
         final List revised = IntStream.range(0, list.size())
@@ -162,6 +174,13 @@ public final class ElementHelper {
         }
     }
 
+    /**
+     * Replaces one key with a different key.
+     *
+     * @param keyValues the list of key/values to alter
+     * @param oldKey the key to replace
+     * @param newKey the new key
+     */
     public static Object[] replaceKey(final Object[] keyValues, final Object oldKey, final Object newKey) {
         final Object[] kvs = new Object[keyValues.length];
         for (int i = 0; i < keyValues.length; i = i + 2) {
@@ -246,7 +265,7 @@ public final class ElementHelper {
     }
 
     /**
-     * Assign key/value pairs as properties to a {@link org.apache.tinkerpop.gremlin.structure.Vertex}.  If the value of {@link T#id} or
+     * Assign key/value pairs as properties to a {@link Vertex}.  If the value of {@link T#id} or
      * {@link T#label} is in the set of pairs, then they are ignored.
      *
      * @param vertex            the vertex to attach the properties to
@@ -331,7 +350,6 @@ public final class ElementHelper {
      * @param a The first {@link org.apache.tinkerpop.gremlin.structure.Element}
      * @param b The second {@link org.apache.tinkerpop.gremlin.structure.Element} (as an {@link Object})
      * @return true if elements and equal and false otherwise
-     * @throws IllegalArgumentException if either argument is null
      */
     public static boolean areEqual(final Element a, final Object b) {
         if (null == b || null == a)

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/5a41ae8c/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
index 2187298..0c8dd4a 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
@@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Property;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.javatuples.Pair;
 import org.junit.Test;
 
@@ -77,6 +78,17 @@ public class ElementHelperTest {
     }
 
     @Test
+    public void shouldValidatePropertyAndNotAllowHiddenKey() {
+        final String key = Graph.Hidden.hide("key");
+        try {
+            ElementHelper.validateProperty(key, "test");
+            fail("Should fail as property key cannot be hidden");
+        } catch (IllegalArgumentException iae) {
+            assertEquals(Property.Exceptions.propertyKeyCanNotBeAHiddenKey(key).getMessage(), iae.getMessage());
+        }
+    }
+
+    @Test
     public void shouldHaveValidProperty() {
         ElementHelper.validateProperty("aKey", "value");
     }
@@ -162,7 +174,7 @@ public class ElementHelperTest {
     }
 
     @Test
-    public void shouldAttachKeyValuesButNotLabelsOrId() {
+    public void shouldAttachPropertiesButNotLabelsOrId() {
         final Element mockElement = mock(Element.class);
         ElementHelper.attachProperties(mockElement, "test", 123, T.id, 321, T.label, "friends");
         verify(mockElement, times(1)).property("test", 123);
@@ -171,13 +183,13 @@ public class ElementHelperTest {
     }
 
     @Test(expected = ClassCastException.class)
-    public void shouldFailTryingToAttachNonStringKey() {
+    public void shouldFailTryingToAttachPropertiesNonStringKey() {
         final Element mockElement = mock(Element.class);
         ElementHelper.attachProperties(mockElement, "test", 123, 321, "test");
     }
 
     @Test
-    public void shouldFailTryingToAttachKeysToNullElement() {
+    public void shouldFailTryingToAttachPropertiesToNullElement() {
         try {
             ElementHelper.attachProperties(null, "test", 123, 321, "test");
             fail("Should throw exception since the element argument is null");
@@ -186,26 +198,30 @@ public class ElementHelperTest {
         }
     }
 
-    /*@Test
-    public void shouldFailElementAreEqualTestBecauseFirstArgumentIsNull() {
-        try {
-            ElementHelper.areEqual((Element) null, "some object");
-            fail("Should throw exception since the first argument is null");
-        } catch (IllegalArgumentException iae) {
-            assertEquals(Graph.Exceptions.argumentCanNotBeNull("a").getMessage(), iae.getMessage());
-        }
+    @Test
+    public void shouldAttachPropertiesWithCardinalityButNotLabelsOrId() {
+        final Vertex mockElement = mock(Vertex.class);
+        ElementHelper.attachProperties(mockElement, VertexProperty.Cardinality.single, "test", 123, T.id, 321, T.label, "friends");
+        verify(mockElement, times(1)).property(VertexProperty.Cardinality.single, "test", 123);
+        verify(mockElement, times(0)).property(VertexProperty.Cardinality.single, T.id.getAccessor(), 321);
+        verify(mockElement, times(0)).property(VertexProperty.Cardinality.single, T.label.getAccessor(), "friends");
+    }
+
+    @Test(expected = ClassCastException.class)
+    public void shouldFailTryingToAttachPropertiesWithCardinalityNonStringKey() {
+        final Element mockElement = mock(Vertex.class);
+        ElementHelper.attachProperties(mockElement, VertexProperty.Cardinality.single, "test", 123, 321, "test");
     }
 
     @Test
-    public void shouldFailElementAreEqualTestBecauseSecondArgumentIsNull() {
-        final Element mockElement = mock(Element.class);
+    public void shouldFailTryingToAttachPropertiesWithCardinalityToNullElement() {
         try {
-            ElementHelper.areEqual(mockElement, null);
-            fail("Should throw exception since the second argument is null");
+            ElementHelper.attachProperties((Vertex) null, VertexProperty.Cardinality.single, "test", 123, 321, "test");
+            fail("Should throw exception since the element argument is null");
         } catch (IllegalArgumentException iae) {
-            assertEquals(Graph.Exceptions.argumentCanNotBeNull("b").getMessage(), iae.getMessage());
+            assertEquals(Graph.Exceptions.argumentCanNotBeNull("vertex").getMessage(), iae.getMessage());
         }
-    }*/
+    }
 
     @Test
     public void shouldDetermineElementsAreEqualAsTheyAreSameObject() {
@@ -437,6 +453,19 @@ public class ElementHelperTest {
     }
 
     @Test
+    public void shouldRemoveAccessor() {
+        final Optional<Object[]> kvs = ElementHelper.remove(T.id, "1", "this", T.id, 6l, "3", "other", "4", 1);
+        assertEquals(6, kvs.get().length);
+        assertTrue(Stream.of(kvs.get()).noneMatch(kv -> kv.equals("2") || kv.equals(6l)));
+    }
+
+    @Test
+    public void shouldRemoveAccessorAndReturnEmpty() {
+        final Optional<Object[]> kvs = ElementHelper.remove(T.id, T.id, "this");
+        assertEquals(Optional.empty(), kvs);
+    }
+
+    @Test
     public void shouldUpsertKeyValueByAddingIt() {
         final Object[] oldKvs = new Object[]{"k", "v"};
         final Object[] newKvs = ElementHelper.upsert(oldKvs, "k1", "v1");
@@ -452,4 +481,15 @@ public class ElementHelperTest {
         assertEquals(4, newKvs.length);
         assertEquals("v1", newKvs[3]);
     }
+
+    @Test
+    public void shouldReplaceKey() {
+        final Object[] oldKvs = new Object[]{"k", "v", "k1", "v0"};
+        final Object[] newKvs = ElementHelper.replaceKey(oldKvs, "k", "k2");
+        assertEquals(4, newKvs.length);
+        assertEquals("k2", newKvs[0]);
+        assertEquals("v", newKvs[1]);
+        assertEquals("k1", newKvs[2]);
+        assertEquals("v0", newKvs[3]);
+    }
 }


[5/6] incubator-tinkerpop git commit: Add license header.

Posted by ok...@apache.org.
Add license header.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/a1d26bed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/a1d26bed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/a1d26bed

Branch: refs/heads/neo4j-gremlin-apache
Commit: a1d26bede1f3ad564a1c3478b72ff1ffa78791da
Parents: 5a41ae8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 29 14:01:57 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 29 14:01:57 2015 -0400

----------------------------------------------------------------------
 .../gremlin/structure/util/ComparatorsTest.java   | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a1d26bed/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ComparatorsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ComparatorsTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ComparatorsTest.java
index d42a8e5..eb182fd 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ComparatorsTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ComparatorsTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.tinkerpop.gremlin.structure.util;
 
 import org.apache.tinkerpop.gremlin.TestHelper;


[2/6] incubator-tinkerpop git commit: Add unit tests to Comparators.

Posted by ok...@apache.org.
Add unit tests to Comparators.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/530c63e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/530c63e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/530c63e8

Branch: refs/heads/neo4j-gremlin-apache
Commit: 530c63e82d491f636a75a8cbd41a3b6ec3063c7e
Parents: da00130
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 29 12:46:09 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 29 12:46:09 2015 -0400

----------------------------------------------------------------------
 .../gremlin/structure/util/Comparators.java     | 26 +++++-
 .../gremlin/structure/util/ComparatorsTest.java | 93 ++++++++++++++++++++
 .../structure/util/ElementHelperTest.java       |  5 ++
 3 files changed, 122 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/530c63e8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Comparators.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Comparators.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Comparators.java
index 657c9c7..86ceb27 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Comparators.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Comparators.java
@@ -27,13 +27,35 @@ import java.util.Comparator;
 import java.util.Map;
 
 /**
+ * A collection of commonly used {@link Comparator} instances.
+ *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public final class Comparators {
+
+    private Comparators() {}
+
+    /**
+     * Sorts {@link Element} objects  by the {@code toString()} value of {@link Element#id()} using
+     * {@link String#CASE_INSENSITIVE_ORDER}.
+     */
     public static final Comparator<Element> ELEMENT_COMPARATOR = Comparator.comparing(e -> e.id().toString(), String.CASE_INSENSITIVE_ORDER);
+
+    /**
+     * Sorts {@link Vertex} objects  by the {@code toString()} value of {@link Vertex#id()} using
+     * {@link String#CASE_INSENSITIVE_ORDER}.
+     */
     public static final Comparator<Vertex> VERTEX_COMPARATOR = Comparator.comparing(e -> e.id().toString(), String.CASE_INSENSITIVE_ORDER);
+
+    /**
+     * Sorts {@link Edge} objects  by the {@code toString()} value of {@link Edge#id()} using
+     * {@link String#CASE_INSENSITIVE_ORDER}.
+     */
     public static final Comparator<Edge> EDGE_COMPARATOR = Comparator.comparing(e -> e.id().toString(), String.CASE_INSENSITIVE_ORDER);
+
+    /**
+     * Sorts {@link Property} objects  by the value of {@link Property#key()} using
+     * {@link String#CASE_INSENSITIVE_ORDER}.
+     */
     public static final Comparator<Property> PROPERTY_COMPARATOR = Comparator.comparing(Property::key, String.CASE_INSENSITIVE_ORDER);
-    public static final Comparator<Map.Entry<String, Property>> PROPERTY_ENTRY_COMPARATOR = Comparator.comparing(Map.Entry::getKey, String.CASE_INSENSITIVE_ORDER);
-    public static final Comparator<Map.Entry<String, Object>> OBJECT_ENTRY_COMPARATOR = Comparator.comparing(Map.Entry::getKey, String.CASE_INSENSITIVE_ORDER);
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/530c63e8/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ComparatorsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ComparatorsTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ComparatorsTest.java
new file mode 100644
index 0000000..d42a8e5
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ComparatorsTest.java
@@ -0,0 +1,93 @@
+package org.apache.tinkerpop.gremlin.structure.util;
+
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class ComparatorsTest {
+    @Test
+    public void shouldBeUtilityClass() throws Exception {
+        TestHelper.assertIsUtilityClass(Comparators.class);
+    }
+
+    @Test
+    public void shouldSortElement() {
+        final Element a = mock(Element.class);
+        when(a.id()).thenReturn("Ant");
+        final Element b = mock(Element.class);
+        when(b.id()).thenReturn("Bat");
+        final Element c = mock(Element.class);
+        when(c.id()).thenReturn("Cat");
+
+        final List<Element> l = Arrays.asList(c, b, a);
+        l.sort(Comparators.ELEMENT_COMPARATOR);
+
+        assertEquals(a.id(), l.get(0).id());
+        assertEquals(b.id(), l.get(1).id());
+        assertEquals(c.id(), l.get(2).id());
+    }
+
+    @Test
+    public void shouldSortVertex() {
+        final Vertex a = mock(Vertex.class);
+        when(a.id()).thenReturn("Ant");
+        final Vertex b = mock(Vertex.class);
+        when(b.id()).thenReturn("Bat");
+        final Vertex c = mock(Vertex.class);
+        when(c.id()).thenReturn("Cat");
+
+        final List<Vertex> l = Arrays.asList(c, b, a);
+        l.sort(Comparators.VERTEX_COMPARATOR);
+
+        assertEquals(a.id(), l.get(0).id());
+        assertEquals(b.id(), l.get(1).id());
+        assertEquals(c.id(), l.get(2).id());
+    }
+
+    @Test
+    public void shouldSortEdge() {
+        final Edge a = mock(Edge.class);
+        when(a.id()).thenReturn("Ant");
+        final Edge b = mock(Edge.class);
+        when(b.id()).thenReturn("Bat");
+        final Edge c = mock(Edge.class);
+        when(c.id()).thenReturn("Cat");
+
+        final List<Edge> l = Arrays.asList(c, b, a);
+        l.sort(Comparators.EDGE_COMPARATOR);
+
+        assertEquals(a.id(), l.get(0).id());
+        assertEquals(b.id(), l.get(1).id());
+        assertEquals(c.id(), l.get(2).id());
+    }
+
+    @Test
+    public void shouldSortProperty() {
+        final Property a = mock(Property.class);
+        when(a.key()).thenReturn("Ant");
+        final Property b = mock(Property.class);
+        when(b.key()).thenReturn("Bat");
+        final Property c = mock(Property.class);
+        when(c.key()).thenReturn("Cat");
+
+        final List<Property> l = Arrays.asList(c, b, a);
+        l.sort(Comparators.PROPERTY_COMPARATOR);
+
+        assertEquals(a.key(), l.get(0).key());
+        assertEquals(b.key(), l.get(1).key());
+        assertEquals(c.key(), l.get(2).key());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/530c63e8/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
index 452a15b..2187298 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.tinkerpop.gremlin.structure.util;
 
+import org.apache.tinkerpop.gremlin.TestHelper;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Element;
@@ -40,6 +41,10 @@ import static org.mockito.Mockito.*;
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class ElementHelperTest {
+    @Test
+    public void shouldBeUtilityClass() throws Exception {
+        TestHelper.assertIsUtilityClass(ElementHelper.class);
+    }
 
     @Test
     public void shouldValidatePropertyAndNotAllowNullValue() {


[3/6] incubator-tinkerpop git commit: Removed ElementHelper.getOrCreate()

Posted by ok...@apache.org.
Removed ElementHelper.getOrCreate()

The method wasn't in use and it seemed a bit naive in its implementation.  It assumed that the user was working with a Graph that supportsUserSuppliedIds and only involved id lookup.  Real-world getOrCreate tends to be more complex.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/c1d15cad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/c1d15cad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/c1d15cad

Branch: refs/heads/neo4j-gremlin-apache
Commit: c1d15cad58860f35ce53039cd5f425f9f4f3212e
Parents: 530c63e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 29 12:52:59 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 29 12:52:59 2015 -0400

----------------------------------------------------------------------
 .../gremlin/structure/util/ElementHelper.java   | 22 +-------------------
 1 file changed, 1 insertion(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c1d15cad/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
index 931f1ae..024e07f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
@@ -48,8 +48,7 @@ import java.util.stream.Stream;
  */
 public final class ElementHelper {
 
-    private ElementHelper() {
-    }
+    private ElementHelper() {}
 
     /**
      * Determine whether the Element label can be legally set. This is typically used as a pre-condition check.
@@ -66,25 +65,6 @@ public final class ElementHelper {
             throw Element.Exceptions.labelCanNotBeAHiddenKey(label);
     }
 
-    /*public static void validateLabels(final String... labels) throws IllegalArgumentException {
-        for (final String label : labels) {
-            validateLabel(label);
-        }
-    }*/
-
-    /**
-     * Check if the vertex, by ID, exists. If it does return it, else create it and return it.
-     *
-     * @param graph the graph to check for the existence of the vertex
-     * @param id    the id of the vertex to look for
-     * @param label the label of the vertex to set if the vertex does not exist
-     * @return a pre-existing vertex or a newly created vertex
-     */
-    public static Vertex getOrAddVertex(final Graph graph, final Object id, final String label) {
-        final Iterator<Vertex> iterator = graph.vertices(id);
-        return iterator.hasNext() ? iterator.next() : graph.addVertex(T.id, id, T.label, label);
-    }
-
     /**
      * Determines whether the property key/value for the specified thing can be legally set. This is typically used as
      * a pre-condition check prior to setting a property.


[6/6] incubator-tinkerpop git commit: merged master.

Posted by ok...@apache.org.
merged master.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/7b528b21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/7b528b21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/7b528b21

Branch: refs/heads/neo4j-gremlin-apache
Commit: 7b528b218b98eefd95f979525850800985bf8e9f
Parents: c19398c a1d26be
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri May 29 12:41:20 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri May 29 12:41:20 2015 -0600

----------------------------------------------------------------------
 .../gremlin/structure/util/Comparators.java     |  26 ++++-
 .../gremlin/structure/util/ElementHelper.java   |  53 +++++----
 .../gremlin/structure/util/ComparatorsTest.java | 111 +++++++++++++++++++
 .../structure/util/ElementHelperTest.java       |  79 ++++++++++---
 .../ser/JsonMessageSerializerV1d0Test.java      |   2 +-
 5 files changed, 224 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7b528b21/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
----------------------------------------------------------------------
diff --cc gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
index b5aa7f3,0245086..9f2a19a
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
@@@ -66,35 -65,6 +65,16 @@@ public final class ElementHelper 
              throw Element.Exceptions.labelCanNotBeAHiddenKey(label);
      }
  
-     /*public static void validateLabels(final String... labels) throws IllegalArgumentException {
-         for (final String label : labels) {
-             validateLabel(label);
-         }
-     }*/
- 
-     /**
-      * Check if the vertex, by ID, exists. If it does return it, else create it and return it.
-      *
-      * @param graph the graph to check for the existence of the vertex
-      * @param id    the id of the vertex to look for
-      * @param label the label of the vertex to set if the vertex does not exist
-      * @return a pre-existing vertex or a newly created vertex
-      */
-     public static Vertex getOrAddVertex(final Graph graph, final Object id, final String label) {
-         final Iterator<Vertex> iterator = graph.vertices(id);
-         return iterator.hasNext() ? iterator.next() : graph.addVertex(T.id, id, T.label, label);
-     }
- 
 +    public static void validateMixedElementIds(final Class<? extends Element> clazz, final Object... ids) {
 +        if (ids.length > 1) {
 +            final boolean element = clazz.isAssignableFrom(ids[0].getClass());
 +            for (int i = 1; i < ids.length; i++) {
 +                if (clazz.isAssignableFrom(ids[i].getClass()) != element)
 +                    throw Graph.Exceptions.idArgsMustBeEitherIdOrElement();
 +            }
 +        }
 +    }
 +
      /**
       * Determines whether the property key/value for the specified thing can be legally set. This is typically used as
       * a pre-condition check prior to setting a property.
@@@ -276,27 -265,8 +275,28 @@@
      }
  
      /**
 -     * Assign key/value pairs as properties to a {@link Vertex}.  If the value of {@link T#id} or
 +     * Assign key/value pairs as properties to an {@link org.apache.tinkerpop.gremlin.structure.Vertex}.  If the value of {@link T#id} or
-      * {@link T#label} is in the set of pairs, then they are ignored. The {@link org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality} of the key is determined from the {@link org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures}.
+      * {@link T#label} is in the set of pairs, then they are ignored.
++     * The {@link org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality} of the key is determined from the {@link org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures}.
 +     *
 +     * @param vertex            the graph vertex to assign the {@code propertyKeyValues}
 +     * @param propertyKeyValues the key/value pairs to assign to the {@code element}
 +     * @throws ClassCastException       if the value of the key is not a {@link String}
 +     * @throws IllegalArgumentException if the value of {@code element} is null
 +     */
 +    public static void attachProperties(final Vertex vertex, final Object... propertyKeyValues) {
 +        if (null == vertex)
 +            throw Graph.Exceptions.argumentCanNotBeNull("vertex");
 +
 +        for (int i = 0; i < propertyKeyValues.length; i = i + 2) {
 +            if (!propertyKeyValues[i].equals(T.id) && !propertyKeyValues[i].equals(T.label))
 +                vertex.property(vertex.graph().features().vertex().getCardinality((String) propertyKeyValues[i]), (String) propertyKeyValues[i], propertyKeyValues[i + 1]);
 +        }
 +    }
 +
 +    /**
-      * Assign key/value pairs as properties to a {@link org.apache.tinkerpop.gremlin.structure.Vertex}.  If the value of {@link T#id} or
-      * {@link T#label} is in the set of pairs, then they are ignored.
++     * Assign key/value pairs as properties to a {@link org.apache.tinkerpop.gremlin.structure.Vertex}.
++     * If the value of {@link T#id} or {@link T#label} is in the set of pairs, then they are ignored.
       *
       * @param vertex            the vertex to attach the properties to
       * @param cardinality       the cardinality of the key value pair settings

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7b528b21/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
----------------------------------------------------------------------
diff --cc gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
index 0ca3814,0c8dd4a..e8ec27c
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelperTest.java
@@@ -18,12 -18,14 +18,14 @@@
   */
  package org.apache.tinkerpop.gremlin.structure.util;
  
+ import org.apache.tinkerpop.gremlin.TestHelper;
 -import org.apache.tinkerpop.gremlin.structure.T;
  import org.apache.tinkerpop.gremlin.structure.Edge;
  import org.apache.tinkerpop.gremlin.structure.Element;
  import org.apache.tinkerpop.gremlin.structure.Graph;
  import org.apache.tinkerpop.gremlin.structure.Property;
 +import org.apache.tinkerpop.gremlin.structure.T;
  import org.apache.tinkerpop.gremlin.structure.Vertex;
+ import org.apache.tinkerpop.gremlin.structure.VertexProperty;
  import org.javatuples.Pair;
  import org.junit.Test;