You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/03/11 18:28:27 UTC

[01/19] incubator-tinkerpop git commit: Remove groovy specific version of ArrayIterator.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/newapi a8c46c5b5 -> 1209663db


Remove groovy specific version of ArrayIterator.

This class was already implemented in gremlin-core - didn't need both.


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

Branch: refs/heads/newapi
Commit: f3e56473b4825b7b26a1ddff59a96db96141c8e7
Parents: 0ef3857
Author: Stephen Mallette <sp...@apache.org>
Authored: Mon Mar 9 14:23:39 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Mon Mar 9 14:23:39 2015 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/console/Console.groovy    |  2 +-
 .../gremlin/console/util/ArrayIterator.groovy   | 49 --------------------
 2 files changed, 1 insertion(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f3e56473/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index efdabf5..db50891 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -20,10 +20,10 @@ package org.apache.tinkerpop.gremlin.console
 
 import org.apache.tinkerpop.gremlin.console.commands.*
 import org.apache.tinkerpop.gremlin.console.plugin.PluggedIn
-import org.apache.tinkerpop.gremlin.console.util.ArrayIterator
 import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader
 import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin
 import jline.console.history.FileHistory
+import org.apache.tinkerpop.gremlin.util.iterator.ArrayIterator
 import org.codehaus.groovy.tools.shell.ExitNotification
 import org.codehaus.groovy.tools.shell.Groovysh
 import org.codehaus.groovy.tools.shell.IO

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f3e56473/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/util/ArrayIterator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/util/ArrayIterator.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/util/ArrayIterator.groovy
deleted file mode 100644
index b6503ef..0000000
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/util/ArrayIterator.groovy
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.console.util
-
-import org.apache.tinkerpop.gremlin.process.FastNoSuchElementException
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-class ArrayIterator implements Iterator {
-
-    private final Object[] array
-    private int count = 0
-
-    public ArrayIterator(final Object[] array) {
-        this.array = array
-    }
-
-    public void remove() {
-        throw new UnsupportedOperationException()
-    }
-
-    public Object next() {
-        if (count > array.length)
-            throw FastNoSuchElementException.instance()
-
-        return array[count++]
-    }
-
-    public boolean hasNext() {
-        return count < array.length
-    }
-}


[14/19] incubator-tinkerpop git commit: Add IteratorUtil.reduce and associated tests.

Posted by sp...@apache.org.
Add IteratorUtil.reduce and associated tests.


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

Branch: refs/heads/newapi
Commit: 144c5e74492f5e414faadc6a6fbbd7155536814a
Parents: e7d623d
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 13:22:47 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 13:22:47 2015 -0400

----------------------------------------------------------------------
 .../gremlin/util/iterator/IteratorUtils.java    | 28 ++++++++++++++
 .../util/iterator/IteratorUtilsTest.java        | 39 ++++++++++++++++++++
 2 files changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/144c5e74/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
index 7d37a5d..d946bf0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
@@ -26,6 +26,8 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.function.BiFunction;
+import java.util.function.BinaryOperator;
 import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
@@ -142,6 +144,32 @@ public final class IteratorUtils {
         return map;
     }
 
+    public static <S> S reduce(final Iterator<S> iterator, final S identity, final BinaryOperator<S> accumulator) {
+        S result = identity;
+        while (iterator.hasNext()) {
+            result = accumulator.apply(result, iterator.next());
+        }
+
+        return result;
+    }
+
+    public static <S> S reduce(final Iterable<S> iterable, final S identity, final BinaryOperator<S> accumulator) {
+        return reduce(iterable.iterator(), identity, accumulator);
+    }
+
+    public static <S, E> E reduce(final Iterator<S> iterator, final E identity, final BiFunction<E, S, E> accumulator) {
+        E result = identity;
+        while (iterator.hasNext()) {
+            result = accumulator.apply(result, iterator.next());
+        }
+
+        return result;
+    }
+
+    public static <S, E> E reduce(final Iterable<S> iterable, final E identity, final BiFunction<E, S, E> accumulator) {
+        return reduce(iterable.iterator(), identity, accumulator);
+    }
+
     ///////////////
 
     public static final <S, E> Iterator<E> map(final Iterator<S> iterator, final Function<S, E> function) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/144c5e74/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index 42f185c..d8c66ed 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -390,6 +390,45 @@ public class IteratorUtilsTest {
         assertIterator(IteratorUtils.concat(iterable1.iterator(), iterable2.iterator()), 6);
     }
 
+    @Test
+    public void shouldReduceFromIteratorWithBinaryOperator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("1");
+        iterable.add("2");
+        iterable.add("3");
+
+        assertEquals("test123", IteratorUtils.reduce(iterable.iterator(), "test", (a, b) -> a + b));
+    }
+
+    @Test
+    public void shouldReduceFromIterableWithBinaryOperator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("1");
+        iterable.add("2");
+        iterable.add("3");
+
+        assertEquals("test123", IteratorUtils.reduce(iterable, "test", (a,b) -> a + b));
+    }
+
+    @Test
+    public void shouldReduceFromIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("1");
+        iterable.add("2");
+        iterable.add("3");
+
+        assertEquals(new Integer(16), IteratorUtils.reduce(iterable.iterator(), 10, (accumulator, val) -> accumulator + Integer.parseInt(val)));
+    }
+
+    @Test
+    public void shouldReduceFromIterable() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("1");
+        iterable.add("2");
+        iterable.add("3");
+
+        assertEquals(new Integer(16), IteratorUtils.reduce(iterable, 10, (accumulator, val) -> accumulator + Integer.parseInt(val)));
+    }
 
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {


[03/19] incubator-tinkerpop git commit: Add matches features to IteratorUtils.

Posted by sp...@apache.org.
Add matches features to IteratorUtils.


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

Branch: refs/heads/newapi
Commit: 95666275c4e93343055a0d2f5e967e3048612756
Parents: de553fc
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 08:16:31 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 08:16:31 2015 -0400

----------------------------------------------------------------------
 .../gremlin/util/iterator/IteratorUtils.java    | 30 ++++++++++++++++++++
 1 file changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/95666275/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
index 56cc93e..7d37a5d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
@@ -90,6 +90,36 @@ public final class IteratorUtils {
         return fill(iterator, new ArrayList<>());
     }
 
+    public static <T> boolean allMatch(final Iterator<T> iterator, final Predicate<T> predicate) {
+        while (iterator.hasNext()) {
+            if (!predicate.test(iterator.next())) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    public static <T> boolean anyMatch(final Iterator<T> iterator, final Predicate<T> predicate) {
+        while (iterator.hasNext()) {
+            if (predicate.test(iterator.next())) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public static <T> boolean noneMatch(final Iterator<T> iterator, final Predicate<T> predicate) {
+        while (iterator.hasNext()) {
+            if (predicate.test(iterator.next())) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
     public static <K, S> Map<K, S> collectMap(final Iterator<S> iterator, final Function<S, K> key) {
         return collectMap(iterator, key, Function.identity());
     }


[18/19] incubator-tinkerpop git commit: Merge branch 'newapi' of https://git-wip-us.apache.org/repos/asf/incubator-tinkerpop into newapi

Posted by sp...@apache.org.
Merge branch 'newapi' of https://git-wip-us.apache.org/repos/asf/incubator-tinkerpop into newapi

Conflicts:
	tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java


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

Branch: refs/heads/newapi
Commit: 57b647d242122840927d44d703a3ee1a77a7483a
Parents: c099978 a8c46c5
Author: Stephen Mallette <sp...@apache.org>
Authored: Wed Mar 11 12:40:53 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Wed Mar 11 12:40:53 2015 -0400

----------------------------------------------------------------------
 .../gremlin/process/TraversalContext.java       |  12 +-
 .../gremlin/process/TraversalEngine.java        |   8 +
 .../gremlin/process/TraversalStrategies.java    |  12 --
 .../traversal/TraversalClassSupplier.java       |  44 +++++
 .../traversal/TraversalVertexProgram.java       |   4 -
 .../graph/traversal/GraphTraversalContext.java  |  41 +++--
 .../traversal/step/HasContainerHolder.java      |   2 +
 .../graph/traversal/step/filter/HasStep.java    |   5 +
 .../traversal/step/sideEffect/GraphStep.java    |   8 +-
 .../engine/ComputerTraversalEngine.java         |  13 +-
 .../engine/StandardTraversalEngine.java         |  10 +-
 .../traversal/step/SideEffectRegistrar.java     |  27 ----
 .../strategy/decoration/ElementIdStrategy.java  |  67 ++++++++
 .../strategy/decoration/ReadOnlyStrategy.java   |  50 ++++++
 .../tinkerpop/gremlin/structure/Graph.java      |  18 +--
 .../gremlin/structure/util/StringFactory.java   |   8 +
 .../gremlin/process/ComputerTestHelper.groovy   |   5 +-
 .../computer/GroovyGraphComputerTest.groovy     |  24 +--
 .../AbstractImportCustomizerProvider.java       |   5 +-
 .../apache/tinkerpop/gremlin/GraphProvider.java |   3 +-
 .../structure/io/script/script-output.groovy    |  12 +-
 .../traversal/GraphTraversalMethodsTest.java    | 161 -------------------
 .../groovy/plugin/HadoopRemoteAcceptor.java     |  12 +-
 .../giraph/HadoopGiraphGraphProvider.java       |  12 +-
 .../spark/HadoopSparkGraphProvider.java         |  11 +-
 .../io/script/ScriptRecordReaderWriterTest.java |  18 +--
 .../gremlin/neo4j/structure/Neo4jGraphTest.java |  43 ++---
 .../traversal/sideEffect/TinkerGraphStep.java   |  12 +-
 .../process/TinkerGraphComputerProvider.java    |  35 ++++
 .../tinkergraph/structure/TinkerGraphTest.java  |  10 +-
 30 files changed, 369 insertions(+), 323 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/57b647d2/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java
----------------------------------------------------------------------


[13/19] incubator-tinkerpop git commit: Add tests for IteratorUtils.concat.

Posted by sp...@apache.org.
Add tests for IteratorUtils.concat.


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

Branch: refs/heads/newapi
Commit: e7d623d51ba8a630e3b848e627807e3c7e4f55d7
Parents: b662049
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 12:49:11 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 12:49:11 2015 -0400

----------------------------------------------------------------------
 .../gremlin/util/iterator/IteratorUtilsTest.java     | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e7d623d5/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index 7cdf7b2..42f185c 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -375,6 +375,21 @@ public class IteratorUtilsTest {
         assertIterator(IteratorUtils.filter(iterable, s -> s.equals("test1")).iterator(), 1);
     }
 
+    @Test
+    public void shouldConcatIterators() {
+        final List<String> iterable1 = new ArrayList<>();
+        iterable1.add("test1");
+        iterable1.add("test2");
+        iterable1.add("test3");
+
+        final List<String> iterable2 = new ArrayList<>();
+        iterable2.add("test4");
+        iterable2.add("test5");
+        iterable2.add("test6");
+
+        assertIterator(IteratorUtils.concat(iterable1.iterator(), iterable2.iterator()), 6);
+    }
+
 
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {


[04/19] incubator-tinkerpop git commit: Add unit test for IteratorUtils.

Posted by sp...@apache.org.
Add unit test for IteratorUtils.


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

Branch: refs/heads/newapi
Commit: c94ca2e81452eeb16b86ef8501f90652f535a995
Parents: 9566627
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 08:32:02 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 08:32:02 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 28 ++++++++++++++++++++
 1 file changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c94ca2e8/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
new file mode 100644
index 0000000..884e124
--- /dev/null
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -0,0 +1,28 @@
+package org.apache.tinkerpop.gremlin.util.iterator;
+
+import org.junit.Test;
+
+import java.util.Iterator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IteratorUtilsTest {
+    @Test
+    public void shouldIterateSingleObject() {
+        final Iterator<String> itty = IteratorUtils.of("test");
+        assertEquals("test", itty.next());
+        assertFalse(itty.hasNext());
+    }
+
+    @Test
+    public void shouldIteratePairOfObjects() {
+        final Iterator<String> itty = IteratorUtils.of("test1", "test2");
+        assertEquals("test1", itty.next());
+        assertEquals("test2", itty.next());
+        assertFalse(itty.hasNext());
+    }
+}


[19/19] incubator-tinkerpop git commit: Fixed compile errors in gremlin-driver after refactoring for GraphTraversalContext.

Posted by sp...@apache.org.
Fixed compile errors in gremlin-driver after refactoring for GraphTraversalContext.


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

Branch: refs/heads/newapi
Commit: 1209663db756375d66e5643ff3bdeeb244273a7d
Parents: 57b647d
Author: Stephen Mallette <sp...@apache.org>
Authored: Wed Mar 11 13:28:01 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Wed Mar 11 13:28:01 2015 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/driver/ResultTest.java    |  4 +--
 .../ser/GryoMessageSerializerV1D0Test.java      | 33 ++++++++++----------
 .../JsonMessageSerializerGremlinV1d0Test.java   | 27 +++++++++-------
 .../ser/JsonMessageSerializerV1d0Test.java      | 11 ++++---
 4 files changed, 41 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1209663d/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultTest.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultTest.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultTest.java
index 0516716..3f44a55 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultTest.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultTest.java
@@ -111,7 +111,7 @@ public class ResultTest {
 
     @Test
     public void shouldGetVertex() {
-        final Vertex v = g.V(1).next();
+        final Vertex v = g.vertices(1).next();
         final ResponseMessage msg = ResponseMessage.build(id).result(v).create();
         final Result result = new Result(msg);
 
@@ -123,7 +123,7 @@ public class ResultTest {
 
     @Test
     public void shouldGetEdge() {
-        final Edge e = g.E(11).next();
+        final Edge e = g.edges(11).next();
         final ResponseMessage msg = ResponseMessage.build(id).result(e).create();
         final Result result = new Result(msg);
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1209663d/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1D0Test.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1D0Test.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1D0Test.java
index 158039a..c952e7b 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1D0Test.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1D0Test.java
@@ -21,8 +21,8 @@ package org.apache.tinkerpop.gremlin.driver.ser;
 import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversalContext;
 import org.apache.tinkerpop.gremlin.structure.Compare;
-import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -30,10 +30,10 @@ import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
-import org.apache.tinkerpop.gremlin.util.StreamFactory;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufAllocator;
 import io.netty.buffer.UnpooledByteBufAllocator;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.junit.Test;
 
 import java.util.ArrayList;
@@ -162,7 +162,7 @@ public class GryoMessageSerializerV1D0Test {
         final Edge e = v1.addEdge("test", v2);
         e.property("abc", 123);
 
-        final Iterable<Edge> iterable = g.E().toList();
+        final Iterable<Edge> iterable = IteratorUtils.list(g.edges());
 
         final ResponseMessage response = convertBinary(iterable);
         assertCommon(response);
@@ -174,12 +174,12 @@ public class GryoMessageSerializerV1D0Test {
         assertEquals(2l, deserializedEdge.id());
         assertEquals("test", deserializedEdge.label());
 
-        assertEquals(new Integer(123), (Integer) deserializedEdge.value("abc"));
-        assertEquals(1, StreamFactory.stream(deserializedEdge.iterators().propertyIterator()).count());
-        assertEquals(0l, deserializedEdge.iterators().vertexIterator(Direction.OUT).next().id());
-        assertEquals(Vertex.DEFAULT_LABEL, deserializedEdge.iterators().vertexIterator(Direction.OUT).next().label());
-        assertEquals(1l, deserializedEdge.iterators().vertexIterator(Direction.IN).next().id());
-        assertEquals(Vertex.DEFAULT_LABEL, deserializedEdge.iterators().vertexIterator(Direction.IN).next().label());
+        assertEquals(123, deserializedEdge.values("abc").next());
+        assertEquals(1, IteratorUtils.count(deserializedEdge.properties()));
+        assertEquals(0l, deserializedEdge.outVertex().id());
+        assertEquals(Vertex.DEFAULT_LABEL, deserializedEdge.outVertex().label());
+        assertEquals(1l, deserializedEdge.inVertex().id());
+        assertEquals(Vertex.DEFAULT_LABEL, deserializedEdge.inVertex().label());
     }
 
     @Test
@@ -197,7 +197,7 @@ public class GryoMessageSerializerV1D0Test {
 
         v.property("friends", friends);
 
-        final List list = g.V().toList();
+        final List list = IteratorUtils.list(g.vertices());
 
         final ResponseMessage response = convertBinary(list);
         assertCommon(response);
@@ -209,9 +209,9 @@ public class GryoMessageSerializerV1D0Test {
         assertEquals(0l, deserializedVertex.id());
         assertEquals(Vertex.DEFAULT_LABEL, deserializedVertex.label());
 
-        assertEquals(1, StreamFactory.stream(deserializedVertex.iterators().propertyIterator()).count());
+        assertEquals(1, IteratorUtils.count(deserializedVertex.properties()));
 
-        final List<Object> deserializedInnerList = (List<Object>) deserializedVertex.iterators().valueIterator("friends").next();
+        final List<Object> deserializedInnerList = (List<Object>) deserializedVertex.values("friends").next();
         assertEquals(3, deserializedInnerList.size());
         assertEquals("x", deserializedInnerList.get(0));
         assertEquals(5, deserializedInnerList.get(1));
@@ -224,7 +224,8 @@ public class GryoMessageSerializerV1D0Test {
 
     @Test
     public void serializeToMapWithElementForKey() throws Exception {
-        final TinkerGraph g = TinkerFactory.createClassic();
+        final TinkerGraph graph = TinkerFactory.createClassic();
+        final GraphTraversalContext g = graph.traversal();
         final Map<Vertex, Integer> map = new HashMap<>();
         map.put(g.V().has("name", Compare.eq, "marko").next(), 1000);
 
@@ -235,11 +236,11 @@ public class GryoMessageSerializerV1D0Test {
         assertEquals(1, deserializedMap.size());
 
         final Vertex deserializedMarko = deserializedMap.keySet().iterator().next();
-        assertEquals("marko", deserializedMarko.iterators().valueIterator("name").next().toString());
+        assertEquals("marko", deserializedMarko.values("name").next().toString());
         assertEquals(1, deserializedMarko.id());
         assertEquals(Vertex.DEFAULT_LABEL, deserializedMarko.label());
-        assertEquals(new Integer(29), (Integer) deserializedMarko.iterators().valueIterator("age").next());
-        assertEquals(2, StreamFactory.stream(deserializedMarko.iterators().propertyIterator()).count());
+        assertEquals(29, deserializedMarko.values("age").next());
+        assertEquals(2, IteratorUtils.count(deserializedMarko.properties()));
 
         assertEquals(new Integer(1000), deserializedMap.values().iterator().next());
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1209663d/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerGremlinV1d0Test.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerGremlinV1d0Test.java b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerGremlinV1d0Test.java
index da3764b..b0c5d74 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerGremlinV1d0Test.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/JsonMessageSerializerGremlinV1d0Test.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.driver.ser;
 import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversalContext;
 import org.apache.tinkerpop.gremlin.structure.Compare;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -32,6 +33,7 @@ import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufAllocator;
 import io.netty.buffer.UnpooledByteBufAllocator;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.junit.Test;
 
 import java.util.ArrayList;
@@ -111,13 +113,13 @@ public class JsonMessageSerializerGremlinV1d0Test {
 
     @Test
     public void serializeEdge() throws Exception {
-        final Graph g = TinkerGraph.open();
-        final Vertex v1 = g.addVertex();
-        final Vertex v2 = g.addVertex();
+        final Graph graph = TinkerGraph.open();
+        final Vertex v1 = graph.addVertex();
+        final Vertex v2 = graph.addVertex();
         final Edge e = v1.addEdge("test", v2);
         e.property("abc", 123);
 
-        final Iterable<Edge> iterable = g.E().toList();
+        final Iterable<Edge> iterable = IteratorUtils.list(graph.edges());
 
         final ResponseMessage response = convert(iterable);
         assertCommon(response);
@@ -142,13 +144,13 @@ public class JsonMessageSerializerGremlinV1d0Test {
 
     @Test
     public void serializeEdgeProperty() throws Exception {
-        final Graph g = TinkerGraph.open();
-        final Vertex v1 = g.addVertex();
-        final Vertex v2 = g.addVertex();
+        final Graph graph = TinkerGraph.open();
+        final Vertex v1 = graph.addVertex();
+        final Vertex v2 = graph.addVertex();
         final Edge e = v1.addEdge("test", v2);
         e.property("abc", 123);
 
-        final Iterable<Property<Object>> iterable = e.properties("abc").toList();
+        final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
         final ResponseMessage response = convert(iterable);
         assertCommon(response);
 
@@ -159,8 +161,8 @@ public class JsonMessageSerializerGremlinV1d0Test {
 
     @Test
     public void serializeVertexWithEmbeddedMap() throws Exception {
-        final Graph g = TinkerGraph.open();
-        final Vertex v = g.addVertex();
+        final Graph graph = TinkerGraph.open();
+        final Vertex v = graph.addVertex();
         final Map<String, Object> map = new HashMap<>();
         map.put("x", 500);
         map.put("y", "some");
@@ -172,7 +174,7 @@ public class JsonMessageSerializerGremlinV1d0Test {
 
         v.property("friends", friends);
 
-        final List list = g.V().toList();
+        final List list = IteratorUtils.list(graph.vertices());
 
         final ResponseMessage response = convert(list);
         assertCommon(response);
@@ -200,7 +202,8 @@ public class JsonMessageSerializerGremlinV1d0Test {
 
     @Test
     public void serializeToJsonMapWithElementForKey() throws Exception {
-        final TinkerGraph g = TinkerFactory.createClassic();
+        final TinkerGraph graph = TinkerFactory.createClassic();
+        final GraphTraversalContext g = graph.traversal();
         final Map<Vertex, Integer> map = new HashMap<>();
         map.put(g.V().has("name", Compare.eq, "marko").next(), 1000);
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1209663d/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 cb51161..bb79ac8 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
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.driver.ser;
 import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.GraphTraversalContext;
 import org.apache.tinkerpop.gremlin.structure.Compare;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -29,6 +30,7 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.junit.Test;
@@ -157,7 +159,7 @@ public class JsonMessageSerializerV1d0Test {
         final Edge e = v1.addEdge("test", v2);
         e.property("abc", 123);
 
-        final Iterable<Edge> iterable = g.E().toList();
+        final Iterable<Edge> iterable = IteratorUtils.list(g.edges());
         final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());
 
         final JSONObject json = new JSONObject(results);
@@ -191,7 +193,7 @@ public class JsonMessageSerializerV1d0Test {
         final Edge e = v1.addEdge("test", v2);
         e.property("abc", 123);
 
-        final Iterable<Property<Object>> iterable = e.properties("abc").toList();
+        final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
         final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());
 
         final JSONObject json = new JSONObject(results);
@@ -224,7 +226,7 @@ public class JsonMessageSerializerV1d0Test {
 
         v.property("friends", friends);
 
-        final Iterable iterable = g.V().toList();
+        final Iterable iterable = IteratorUtils.list(g.vertices());
         final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());
         final JSONObject json = new JSONObject(results);
 
@@ -258,7 +260,8 @@ public class JsonMessageSerializerV1d0Test {
 
     @Test
     public void serializeToJsonMapWithElementForKey() throws Exception {
-        final TinkerGraph g = TinkerFactory.createClassic();
+        final TinkerGraph graph = TinkerFactory.createClassic();
+        final GraphTraversalContext g = graph.traversal();
         final Map<Vertex, Integer> map = new HashMap<>();
         map.put(g.V().has("name", Compare.eq, "marko").next(), 1000);
 


[12/19] incubator-tinkerpop git commit: Add tests for IteratorUtils.filter.

Posted by sp...@apache.org.
Add tests for IteratorUtils.filter.


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

Branch: refs/heads/newapi
Commit: b662049d5c0612a8d2d1de6412031d15b0a0bab8
Parents: 9e11a29
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 12:47:35 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 12:47:35 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 61 ++++++++++++++++++++
 1 file changed, 61 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b662049d/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index ec36d29..7cdf7b2 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -315,6 +315,67 @@ public class IteratorUtilsTest {
         assertIterator(IteratorUtils.map(iterable, s -> "test" + s).iterator(), 3);
     }
 
+    @Test
+    public void shouldFilterAllFromIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        assertIterator(IteratorUtils.filter(iterable.iterator(), s -> s.startsWith("dfaa")), 0);
+    }
+
+    @Test
+    public void shouldFilterNoneFromIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        assertIterator(IteratorUtils.filter(iterable.iterator(), s -> s.startsWith("test")), 3);
+    }
+
+    @Test
+    public void shouldFilterSomeFromIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        assertIterator(IteratorUtils.filter(iterable.iterator(), s -> s.equals("test1")), 1);
+    }
+
+    @Test
+    public void shouldFilterAllFromIterable() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        assertIterator(IteratorUtils.filter(iterable, s -> s.startsWith("dfaa")).iterator(), 0);
+    }
+
+    @Test
+    public void shouldFilterNoneFromIterable() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        assertIterator(IteratorUtils.filter(iterable, s -> s.startsWith("test")).iterator(), 3);
+    }
+
+    @Test
+    public void shouldFilterSomeFromIterable() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        assertIterator(IteratorUtils.filter(iterable, s -> s.equals("test1")).iterator(), 1);
+    }
+
+
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {
             assertEquals("test" + (ix + 1), itty.next());


[05/19] incubator-tinkerpop git commit: Add IteratorUtils tests for converting arbitrary objects to iterator.

Posted by sp...@apache.org.
Add IteratorUtils tests for converting arbitrary objects to iterator.


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

Branch: refs/heads/newapi
Commit: f3d99939c94a1916571ea694e7c8ef8e3b55bd05
Parents: c94ca2e
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 08:45:22 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 08:45:22 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 83 ++++++++++++++++++--
 1 file changed, 77 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f3d99939/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index 884e124..a9bfe4b 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -2,7 +2,11 @@ package org.apache.tinkerpop.gremlin.util.iterator;
 
 import org.junit.Test;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -13,16 +17,83 @@ import static org.junit.Assert.assertFalse;
 public class IteratorUtilsTest {
     @Test
     public void shouldIterateSingleObject() {
-        final Iterator<String> itty = IteratorUtils.of("test");
-        assertEquals("test", itty.next());
-        assertFalse(itty.hasNext());
+        assertIterator(IteratorUtils.of("test1"), 1);
     }
 
     @Test
     public void shouldIteratePairOfObjects() {
-        final Iterator<String> itty = IteratorUtils.of("test1", "test2");
-        assertEquals("test1", itty.next());
-        assertEquals("test2", itty.next());
+        assertIterator(IteratorUtils.of("test1", "test2"), 2);
+    }
+
+    @Test
+    public void shouldConvertIterableToIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.convertToIterator(iterable), iterable.size());
+    }
+
+    @Test
+    public void shouldConvertIteratorToIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.convertToIterator(iterable.iterator()), iterable.size());
+    }
+
+    @Test
+    public void shouldConvertArrayToIterator() {
+        final String[] iterable = new String[3];
+        iterable[0] = "test1";
+        iterable[1] = "test2";
+        iterable[2] = "test3";
+        assertIterator(IteratorUtils.convertToIterator(iterable), iterable.length);
+    }
+
+    @Test
+    public void shouldConvertThrowableToIterator() {
+        final Exception ex = new Exception("test1");
+        assertIterator(IteratorUtils.convertToIterator(ex), 1);
+    }
+
+    @Test
+    public void shouldConvertStreamToIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.convertToIterator(iterable.stream()), iterable.size());
+    }
+
+    @Test
+    public void shouldConvertMapToIterator() {
+        final Map<String,String> m = new HashMap<>();
+        m.put("key1", "val1");
+        m.put("key2", "val2");
+        m.put("key3", "val3");
+
+        final Iterator itty = IteratorUtils.convertToIterator(m);
+        for (int ix = 0; ix < m.size(); ix++) {
+            final Map.Entry entry = (Map.Entry) itty.next();
+            assertEquals("key" + (ix + 1), entry.getKey());
+            assertEquals("val" + (ix + 1), entry.getValue());
+        }
+
+        assertFalse(itty.hasNext());
+    }
+
+    @Test
+    public void shouldConvertAnythingElseToIteratorByWrapping() {
+        assertIterator(IteratorUtils.convertToIterator("test1"), 1);
+    }
+
+    public <S> void assertIterator(final Iterator<S> itty, final int size) {
+        for (int ix = 0; ix < size; ix++) {
+            assertEquals("test" + (ix + 1), itty.next());
+        }
+
         assertFalse(itty.hasNext());
     }
 }


[08/19] incubator-tinkerpop git commit: Add tests for IteratorUtils for match functions.

Posted by sp...@apache.org.
Add tests for IteratorUtils for match functions.


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

Branch: refs/heads/newapi
Commit: b2c673c2ac36cd2bce405878322d34c37dfe9366
Parents: 8908ff0
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 09:12:02 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 09:12:02 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 55 ++++++++++++++++++++
 1 file changed, 55 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b2c673c2/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index fdd7199..f039c4e 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -8,6 +8,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
@@ -191,6 +192,60 @@ public class IteratorUtilsTest {
         assertIterator(IteratorUtils.list(iterable.iterator()).iterator(), iterable.size());
     }
 
+    @Test
+    public void shouldMatchAllPositively() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertTrue(IteratorUtils.allMatch(iterable.iterator(), s -> s.startsWith("test")));
+    }
+
+    @Test
+    public void shouldMatchAllNegatively() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertFalse(IteratorUtils.allMatch(iterable.iterator(), s -> s.startsWith("test1")));
+    }
+
+    @Test
+    public void shouldMatchAnyPositively() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertTrue(IteratorUtils.anyMatch(iterable.iterator(), s -> s.startsWith("test3")));
+    }
+
+    @Test
+    public void shouldMatchAnyNegatively() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertFalse(IteratorUtils.anyMatch(iterable.iterator(), s -> s.startsWith("dfaa")));
+    }
+
+    @Test
+    public void shouldMatchNonePositively() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertTrue(IteratorUtils.noneMatch(iterable.iterator(), s -> s.startsWith("test4")));
+    }
+
+    @Test
+    public void shouldMatchNoneNegatively() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertFalse(IteratorUtils.noneMatch(iterable.iterator(), s -> s.startsWith("test")));
+    }
+
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {
             assertEquals("test" + (ix + 1), itty.next());


[16/19] incubator-tinkerpop git commit: Remove the TimeUtils class by pushing its methods to the existing TimeUtil class.

Posted by sp...@apache.org.
Remove the TimeUtils class by pushing its methods to the existing TimeUtil class.


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

Branch: refs/heads/newapi
Commit: f52f6cbd67b8da9696d5cd18ea03e06934514c77
Parents: 010fe19
Author: Stephen Mallette <sp...@apache.org>
Authored: Wed Mar 11 10:20:34 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Wed Mar 11 10:20:34 2015 -0400

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/util/TimeUtil.java | 15 ++++++++
 .../tinkerpop/gremlin/util/tools/TimeUtils.java | 40 --------------------
 .../AbstractImportCustomizerProvider.java       |  4 +-
 3 files changed, 17 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f52f6cbd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/TimeUtil.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/TimeUtil.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/TimeUtil.java
index 5131560..1b0a8e3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/TimeUtil.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/TimeUtil.java
@@ -19,9 +19,11 @@
 package org.apache.tinkerpop.gremlin.util;
 
 import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
+ * @author Daniel Kuppitz (http://gremlin.guru)
  */
 public final class TimeUtil {
     public static long secondsSince(final long startNanos) {
@@ -39,4 +41,17 @@ public final class TimeUtil {
     public static long timeSince(final long startNanos, final TimeUnit destUnit) {
         return destUnit.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS);
     }
+
+    public static double clock(final Runnable runnable) {
+        return clock(100, runnable);
+    }
+
+    public static double clock(final int loops, final Runnable runnable) {
+        runnable.run(); // warm-up
+        return IntStream.range(0, loops).mapToDouble(i -> {
+            long t = System.nanoTime();
+            runnable.run();
+            return (System.nanoTime() - t) * 0.000001;
+        }).sum() / loops;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f52f6cbd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/tools/TimeUtils.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/tools/TimeUtils.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/tools/TimeUtils.java
deleted file mode 100644
index a8d4788..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/tools/TimeUtils.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.util.tools;
-
-import java.util.stream.IntStream;
-
-/**
- * @author Daniel Kuppitz (http://gremlin.guru)
- */
-public class TimeUtils {
-
-    public static double clock(final Runnable runnable) {
-        return clock(100, runnable);
-    }
-
-    public static double clock(final int loops, final Runnable runnable) {
-        runnable.run(); // warm-up
-        return IntStream.range(0, loops).mapToDouble(i -> {
-            long t = System.nanoTime();
-            runnable.run();
-            return (System.nanoTime() - t) * 0.000001;
-        }).sum() / loops;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f52f6cbd/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java
index ab983e9..6ee6afd 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/AbstractImportCustomizerProvider.java
@@ -55,7 +55,7 @@ import org.apache.tinkerpop.gremlin.structure.util.batch.BatchGraph;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedElement;
 import org.apache.tinkerpop.gremlin.util.Gremlin;
 import org.apache.tinkerpop.gremlin.util.function.FunctionUtils;
-import org.apache.tinkerpop.gremlin.util.tools.TimeUtils;
+import org.apache.tinkerpop.gremlin.util.TimeUtil;
 import org.codehaus.groovy.control.customizers.CompilationCustomizer;
 import org.codehaus.groovy.control.customizers.ImportCustomizer;
 
@@ -128,7 +128,7 @@ public abstract class AbstractImportCustomizerProvider implements ImportCustomiz
         staticImports.add(Order.class.getCanonicalName() + DOT_STAR);
         staticImports.add(Operator.class.getCanonicalName() + DOT_STAR);
         staticImports.add(Scope.class.getCanonicalName() + DOT_STAR);
-        staticImports.add(TimeUtils.class.getCanonicalName() + DOT_STAR);
+        staticImports.add(TimeUtil.class.getCanonicalName() + DOT_STAR);
         staticImports.add(VertexProperty.Cardinality.class.getCanonicalName() + DOT_STAR);
     }
 


[02/19] incubator-tinkerpop git commit: Add some extra output to the printTraversalForm method.

Posted by sp...@apache.org.
Add some extra output to the printTraversalForm method.

Added the test name and before/after labels to traversal toString'ing.


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

Branch: refs/heads/newapi
Commit: de553fca438cc2e3442a1ce2dea577edd9b190e7
Parents: f3e5647
Author: Stephen Mallette <sp...@apache.org>
Authored: Mon Mar 9 15:08:57 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Mon Mar 9 15:08:57 2015 -0400

----------------------------------------------------------------------
 .../java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java  | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/de553fca/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
index d263ced..f4fd22f 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGremlinTest.java
@@ -230,9 +230,10 @@ public abstract class AbstractGremlinTest {
     public void printTraversalForm(final Traversal traversal) {
         final boolean muted = Boolean.parseBoolean(System.getProperty("muteTestLogs", "false"));
 
-        if (!muted) System.out.println("Testing: " + traversal);
+        if (!muted) System.out.println(String.format("Testing: %s", name.getMethodName()));
+        if (!muted) System.out.println("   pre-strategy:" + traversal);
         traversal.hasNext();
-        if (!muted) System.out.println("         " + traversal);
+        if (!muted) System.out.println("  post-strategy:" + traversal);
     }
 
     public static Consumer<Graph> assertVertexEdgeCounts(final int expectedVertexCount, final int expectedEdgeCount) {


[11/19] incubator-tinkerpop git commit: Add tests for IteratorUtils.map

Posted by sp...@apache.org.
Add tests for IteratorUtils.map


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

Branch: refs/heads/newapi
Commit: 9e11a2973507e2457f0d67408296e621d8bcd990
Parents: fefe95d
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 12:43:05 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 12:43:05 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9e11a297/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index 3456ede..ec36d29 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -295,6 +295,26 @@ public class IteratorUtilsTest {
         assertEquals(1, m2.size());
     }
 
+    @Test
+    public void shouldApplyMapOverIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("1");
+        iterable.add("2");
+        iterable.add("3");
+
+        assertIterator(IteratorUtils.map(iterable.iterator(), s -> "test" + s), 3);
+    }
+
+    @Test
+    public void shouldApplyMapOverIterable() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("1");
+        iterable.add("2");
+        iterable.add("3");
+
+        assertIterator(IteratorUtils.map(iterable, s -> "test" + s).iterator(), 3);
+    }
+
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {
             assertEquals("test" + (ix + 1), itty.next());


[10/19] incubator-tinkerpop git commit: Add test for IteratorUtils.grouBy.

Posted by sp...@apache.org.
Add test for IteratorUtils.grouBy.


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

Branch: refs/heads/newapi
Commit: fefe95d046e99b63a455304007fd5c695b788770
Parents: 56b5e35
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 11:17:42 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 11:17:42 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 24 ++++++++++++++++++++
 1 file changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fefe95d0/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index 0e2c2f0..3456ede 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -271,6 +271,30 @@ public class IteratorUtilsTest {
         assertEquals("test", m.get("3"));
     }
 
+    @Test
+    public void shouldProduceMapFromIteratorUsingGrouping() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        final Map<String,List<String>> m1 = IteratorUtils.groupBy(iterable.iterator(), i -> i.substring(4));
+        assertEquals("test1", m1.get("1").get(0));
+        assertEquals(1, m1.get("1").size());
+        assertEquals("test2", m1.get("2").get(0));
+        assertEquals(1, m1.get("2").size());
+        assertEquals("test3", m1.get("3").get(0));
+        assertEquals(1, m1.get("3").size());
+        assertEquals(3, m1.size());
+
+        final Map<String,List<String>> m2 = IteratorUtils.groupBy(iterable.iterator(), i -> i.substring(0,4));
+        assertEquals("test1", m2.get("test").get(0));
+        assertEquals("test2", m2.get("test").get(1));
+        assertEquals("test3", m2.get("test").get(2));
+        assertEquals(3, m2.get("test").size());
+        assertEquals(1, m2.size());
+    }
+
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {
             assertEquals("test" + (ix + 1), itty.next());


[09/19] incubator-tinkerpop git commit: Add test for IteratorUtils.collectMap.

Posted by sp...@apache.org.
Add test for IteratorUtils.collectMap.


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

Branch: refs/heads/newapi
Commit: 56b5e352cdc57f00d390e4d366921c3ce817fbaa
Parents: b2c673c
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 11:13:53 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 11:13:53 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 29 ++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/56b5e352/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index f039c4e..0e2c2f0 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -169,8 +169,7 @@ public class IteratorUtilsTest {
 
     @Test
     public void shouldCountEmpty() {
-        final List<String> iterable = new ArrayList<>();
-        assertEquals(0, IteratorUtils.count(iterable.iterator()));
+        assertEquals(0, IteratorUtils.count(new ArrayList<>().iterator()));
     }
 
     @Test
@@ -246,6 +245,32 @@ public class IteratorUtilsTest {
         assertFalse(IteratorUtils.noneMatch(iterable.iterator(), s -> s.startsWith("test")));
     }
 
+    @Test
+    public void shouldProduceMapFromIteratorUsingIdentityForValue() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        final Map<String,String> m = IteratorUtils.collectMap(iterable.iterator(), k -> k.substring(4));
+        assertEquals("test1", m.get("1"));
+        assertEquals("test2", m.get("2"));
+        assertEquals("test3", m.get("3"));
+    }
+
+    @Test
+    public void shouldProduceMapFromIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        final Map<String,String> m = IteratorUtils.collectMap(iterable.iterator(), k -> k.substring(4), v -> v.substring(0, 4));
+        assertEquals("test", m.get("1"));
+        assertEquals("test", m.get("2"));
+        assertEquals("test", m.get("3"));
+    }
+
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {
             assertEquals("test" + (ix + 1), itty.next());


[17/19] incubator-tinkerpop git commit: Merge remote-tracking branch 'origin/master' into newapi

Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/master' into newapi

Conflicts:
	tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java


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

Branch: refs/heads/newapi
Commit: c09997800a3706223c71781f6882b4c4c6859e95
Parents: 9d7bab0 f52f6cb
Author: Stephen Mallette <sp...@apache.org>
Authored: Wed Mar 11 12:38:38 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Wed Mar 11 12:38:38 2015 -0400

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/util/TimeUtil.java |  15 +
 .../gremlin/util/iterator/IteratorUtils.java    | 111 ++++-
 .../tinkerpop/gremlin/util/tools/TimeUtils.java |  40 --
 .../AbstractImportCustomizerProvider.java       |   4 +-
 .../handler/HttpGremlinEndpointHandler.java     |   2 +-
 .../server/op/AbstractEvalOpProcessor.java      |   2 +-
 .../util/iterator/IteratorUtilsTest.java        | 440 +++++++++++++++++++
 .../process/TinkerGraphComputerProvider.java    |  35 --
 8 files changed, 546 insertions(+), 103 deletions(-)
----------------------------------------------------------------------



[15/19] incubator-tinkerpop git commit: Minor code reorganization and method renaming in IteratorUtils.

Posted by sp...@apache.org.
Minor code reorganization and method renaming in IteratorUtils.


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

Branch: refs/heads/newapi
Commit: 010fe195cd865cdb4e060ea1285505e374f42e78
Parents: 144c5e7
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 15:30:29 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 15:30:29 2015 -0400

----------------------------------------------------------------------
 .../gremlin/util/iterator/IteratorUtils.java    | 53 +++++++++++---------
 .../handler/HttpGremlinEndpointHandler.java     |  2 +-
 .../server/op/AbstractEvalOpProcessor.java      |  2 +-
 .../util/iterator/IteratorUtilsTest.java        | 28 +++++------
 4 files changed, 45 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/010fe195/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
index d946bf0..c6537c4 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
@@ -51,30 +51,6 @@ public final class IteratorUtils {
 
     ///////////////
 
-    public static Iterator convertToIterator(final Object o) {
-        final Iterator itty;
-        if (o instanceof Iterable)
-            itty = ((Iterable) o).iterator();
-        else if (o instanceof Iterator)
-            itty = (Iterator) o;
-        else if (o instanceof Object[])
-            itty = new ArrayIterator<>((Object[]) o);
-        else if (o instanceof Stream)
-            itty = ((Stream) o).iterator();
-        else if (o instanceof Map)
-            itty = ((Map) o).entrySet().iterator();
-        else if (o instanceof Throwable)
-            itty = IteratorUtils.of(((Throwable) o).getMessage());
-        else
-            itty = IteratorUtils.of(o);
-        return itty;
-    }
-
-    public static List convertToList(final Object o) {
-        final Iterator iterator = IteratorUtils.convertToIterator(o);
-        return list(iterator);
-    }
-
     public static final <S extends Collection<T>, T> S fill(final Iterator<T> iterator, final S collection) {
         while (iterator.hasNext()) {
             collection.add(iterator.next());
@@ -92,6 +68,8 @@ public final class IteratorUtils {
         return fill(iterator, new ArrayList<>());
     }
 
+    ///////////////////
+
     public static <T> boolean allMatch(final Iterator<T> iterator, final Predicate<T> predicate) {
         while (iterator.hasNext()) {
             if (!predicate.test(iterator.next())) {
@@ -122,6 +100,8 @@ public final class IteratorUtils {
         return true;
     }
 
+    ///////////////////
+
     public static <K, S> Map<K, S> collectMap(final Iterator<S> iterator, final Function<S, K> key) {
         return collectMap(iterator, key, Function.identity());
     }
@@ -261,4 +241,29 @@ public final class IteratorUtils {
         }
         return iterator;
     }
+
+    ///////////////////
+
+    public static Iterator asIterator(final Object o) {
+        final Iterator itty;
+        if (o instanceof Iterable)
+            itty = ((Iterable) o).iterator();
+        else if (o instanceof Iterator)
+            itty = (Iterator) o;
+        else if (o instanceof Object[])
+            itty = new ArrayIterator<>((Object[]) o);
+        else if (o instanceof Stream)
+            itty = ((Stream) o).iterator();
+        else if (o instanceof Map)
+            itty = ((Map) o).entrySet().iterator();
+        else if (o instanceof Throwable)
+            itty = of(((Throwable) o).getMessage());
+        else
+            itty = of(o);
+        return itty;
+    }
+
+    public static List asList(final Object o) {
+        return list(asIterator(o));
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/010fe195/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpGremlinEndpointHandler.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpGremlinEndpointHandler.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpGremlinEndpointHandler.java
index 517c6b2..67e81c2 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpGremlinEndpointHandler.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpGremlinEndpointHandler.java
@@ -187,7 +187,7 @@ public class HttpGremlinEndpointHandler extends ChannelInboundHandlerAdapter {
                                     requestArguments.getValue0(), requestArguments.getValue1(), o, Thread.currentThread().getName());
                             final ResponseMessage responseMessage = ResponseMessage.build(UUID.randomUUID())
                                     .code(ResponseStatusCode.SUCCESS)
-                                    .result(IteratorUtils.convertToList(o)).create();
+                                    .result(IteratorUtils.asList(o)).create();
                             return (Object) Unpooled.wrappedBuffer(serializer.serializeResponseAsString(responseMessage).getBytes(UTF8));
                         }));
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/010fe195/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java
index e6bc607..87c7a61 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java
@@ -151,7 +151,7 @@ public abstract class AbstractEvalOpProcessor implements OpProcessor {
         });
 
         final CompletableFuture<Void> iterationFuture = evalFuture.thenAcceptAsync(o -> {
-            final Iterator itty = IteratorUtils.convertToIterator(o);
+            final Iterator itty = IteratorUtils.asIterator(o);
 
             logger.info("Preparing to iterate results from - {} - in thread [{}]", msg, Thread.currentThread().getName());
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/010fe195/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index d8c66ed..20a4767 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -32,7 +32,7 @@ public class IteratorUtilsTest {
         iterable.add("test1");
         iterable.add("test2");
         iterable.add("test3");
-        assertIterator(IteratorUtils.convertToIterator(iterable), iterable.size());
+        assertIterator(IteratorUtils.asIterator(iterable), iterable.size());
     }
 
     @Test
@@ -41,7 +41,7 @@ public class IteratorUtilsTest {
         iterable.add("test1");
         iterable.add("test2");
         iterable.add("test3");
-        assertIterator(IteratorUtils.convertToIterator(iterable.iterator()), iterable.size());
+        assertIterator(IteratorUtils.asIterator(iterable.iterator()), iterable.size());
     }
 
     @Test
@@ -50,13 +50,13 @@ public class IteratorUtilsTest {
         iterable[0] = "test1";
         iterable[1] = "test2";
         iterable[2] = "test3";
-        assertIterator(IteratorUtils.convertToIterator(iterable), iterable.length);
+        assertIterator(IteratorUtils.asIterator(iterable), iterable.length);
     }
 
     @Test
     public void shouldConvertThrowableToIterator() {
         final Exception ex = new Exception("test1");
-        assertIterator(IteratorUtils.convertToIterator(ex), 1);
+        assertIterator(IteratorUtils.asIterator(ex), 1);
     }
 
     @Test
@@ -65,7 +65,7 @@ public class IteratorUtilsTest {
         iterable.add("test1");
         iterable.add("test2");
         iterable.add("test3");
-        assertIterator(IteratorUtils.convertToIterator(iterable.stream()), iterable.size());
+        assertIterator(IteratorUtils.asIterator(iterable.stream()), iterable.size());
     }
 
     @Test
@@ -75,7 +75,7 @@ public class IteratorUtilsTest {
         m.put("key2", "val2");
         m.put("key3", "val3");
 
-        final Iterator itty = IteratorUtils.convertToIterator(m);
+        final Iterator itty = IteratorUtils.asIterator(m);
         for (int ix = 0; ix < m.size(); ix++) {
             final Map.Entry entry = (Map.Entry) itty.next();
             assertEquals("key" + (ix + 1), entry.getKey());
@@ -87,7 +87,7 @@ public class IteratorUtilsTest {
 
     @Test
     public void shouldConvertAnythingElseToIteratorByWrapping() {
-        assertIterator(IteratorUtils.convertToIterator("test1"), 1);
+        assertIterator(IteratorUtils.asIterator("test1"), 1);
     }
 
     @Test
@@ -96,7 +96,7 @@ public class IteratorUtilsTest {
         iterable.add("test1");
         iterable.add("test2");
         iterable.add("test3");
-        assertIterator(IteratorUtils.convertToList(iterable).iterator(), iterable.size());
+        assertIterator(IteratorUtils.asList(iterable).iterator(), iterable.size());
     }
 
     @Test
@@ -105,7 +105,7 @@ public class IteratorUtilsTest {
         iterable.add("test1");
         iterable.add("test2");
         iterable.add("test3");
-        assertIterator(IteratorUtils.convertToList(iterable.iterator()).iterator(), iterable.size());
+        assertIterator(IteratorUtils.asList(iterable.iterator()).iterator(), iterable.size());
     }
 
     @Test
@@ -114,13 +114,13 @@ public class IteratorUtilsTest {
         iterable[0] = "test1";
         iterable[1] = "test2";
         iterable[2] = "test3";
-        assertIterator(IteratorUtils.convertToList(iterable).iterator(), iterable.length);
+        assertIterator(IteratorUtils.asList(iterable).iterator(), iterable.length);
     }
 
     @Test
     public void shouldConvertThrowableToList() {
         final Exception ex = new Exception("test1");
-        assertIterator(IteratorUtils.convertToList(ex).iterator(), 1);
+        assertIterator(IteratorUtils.asList(ex).iterator(), 1);
     }
 
     @Test
@@ -129,7 +129,7 @@ public class IteratorUtilsTest {
         iterable.add("test1");
         iterable.add("test2");
         iterable.add("test3");
-        assertIterator(IteratorUtils.convertToList(iterable.stream()).iterator(), iterable.size());
+        assertIterator(IteratorUtils.asList(iterable.stream()).iterator(), iterable.size());
     }
 
     @Test
@@ -139,7 +139,7 @@ public class IteratorUtilsTest {
         m.put("key2", "val2");
         m.put("key3", "val3");
 
-        final Iterator itty = IteratorUtils.convertToList(m).iterator();
+        final Iterator itty = IteratorUtils.asList(m).iterator();
         for (int ix = 0; ix < m.size(); ix++) {
             final Map.Entry entry = (Map.Entry) itty.next();
             assertEquals("key" + (ix + 1), entry.getKey());
@@ -151,7 +151,7 @@ public class IteratorUtilsTest {
 
     @Test
     public void shouldConvertAnythingElseToListByWrapping() {
-        assertIterator(IteratorUtils.convertToList("test1").iterator(), 1);
+        assertIterator(IteratorUtils.asList("test1").iterator(), 1);
     }
 
     @Test


[06/19] incubator-tinkerpop git commit: Add tests to IteratorUtils for convertToList.

Posted by sp...@apache.org.
Add tests to IteratorUtils for convertToList.


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

Branch: refs/heads/newapi
Commit: 243f01062cc9b0a330f17a8661c1a41d48c08d75
Parents: f3d9993
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 08:49:17 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 08:49:17 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 65 ++++++++++++++++++++
 1 file changed, 65 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/243f0106/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index a9bfe4b..a0b60d9 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -89,6 +89,71 @@ public class IteratorUtilsTest {
         assertIterator(IteratorUtils.convertToIterator("test1"), 1);
     }
 
+    @Test
+    public void shouldConvertIterableToList() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.convertToList(iterable).iterator(), iterable.size());
+    }
+
+    @Test
+    public void shouldConvertIteratorToList() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.convertToList(iterable.iterator()).iterator(), iterable.size());
+    }
+
+    @Test
+    public void shouldConvertArrayToList() {
+        final String[] iterable = new String[3];
+        iterable[0] = "test1";
+        iterable[1] = "test2";
+        iterable[2] = "test3";
+        assertIterator(IteratorUtils.convertToList(iterable).iterator(), iterable.length);
+    }
+
+    @Test
+    public void shouldConvertThrowableToList() {
+        final Exception ex = new Exception("test1");
+        assertIterator(IteratorUtils.convertToList(ex).iterator(), 1);
+    }
+
+    @Test
+    public void shouldConvertStreamToList() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.convertToList(iterable.stream()).iterator(), iterable.size());
+    }
+
+    @Test
+    public void shouldConvertMapToList() {
+        final Map<String,String> m = new HashMap<>();
+        m.put("key1", "val1");
+        m.put("key2", "val2");
+        m.put("key3", "val3");
+
+        final Iterator itty = IteratorUtils.convertToList(m).iterator();
+        for (int ix = 0; ix < m.size(); ix++) {
+            final Map.Entry entry = (Map.Entry) itty.next();
+            assertEquals("key" + (ix + 1), entry.getKey());
+            assertEquals("val" + (ix + 1), entry.getValue());
+        }
+
+        assertFalse(itty.hasNext());
+    }
+
+    @Test
+    public void shouldConvertAnythingElseToListByWrapping() {
+        assertIterator(IteratorUtils.convertToList("test1").iterator(), 1);
+    }
+
+
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {
             assertEquals("test" + (ix + 1), itty.next());


[07/19] incubator-tinkerpop git commit: Add tests for IteratorUtils around count, fill and list conversion.

Posted by sp...@apache.org.
Add tests for IteratorUtils around count, fill and list conversion.


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

Branch: refs/heads/newapi
Commit: 8908ff0f150611d25fff548c3dd4141f4e97a6db
Parents: 243f010
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 09:00:20 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 09:00:20 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 37 ++++++++++++++++++++
 1 file changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8908ff0f/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index a0b60d9..fdd7199 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -153,6 +153,43 @@ public class IteratorUtilsTest {
         assertIterator(IteratorUtils.convertToList("test1").iterator(), 1);
     }
 
+    @Test
+    public void shouldFillFromIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        final List<String> newList = new ArrayList<>();
+        IteratorUtils.fill(iterable.iterator(), newList);
+
+        assertIterator(newList.iterator(), iterable.size());
+    }
+
+    @Test
+    public void shouldCountEmpty() {
+        final List<String> iterable = new ArrayList<>();
+        assertEquals(0, IteratorUtils.count(iterable.iterator()));
+    }
+
+    @Test
+    public void shouldCountAll() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+
+        assertEquals(3, IteratorUtils.count(iterable.iterator()));
+    }
+
+    @Test
+    public void shouldMakeArrayListFromIterator() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.list(iterable.iterator()).iterator(), iterable.size());
+    }
 
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {