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/02/12 22:56:51 UTC

incubator-tinkerpop git commit: added CountLocalStep and renamed CountStep to CountGlobalStep. Updated various parts of the docs. Added an IMPORTANT: section to those steps that support local versions -- count(local), order(local)... will use the same pa

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master ab87308e7 -> 22aa156d1


added CountLocalStep and renamed CountStep to CountGlobalStep. Updated various parts of the docs. Added an IMPORTANT: section to those steps that support local versions -- count(local), order(local)... will use the same pattern for all future local variations.


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

Branch: refs/heads/master
Commit: 22aa156d15dc13276c896b32cb9a09ed296fbb86
Parents: ab87308
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Feb 12 14:56:47 2015 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Feb 12 14:56:47 2015 -0700

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 docs/src/the-traversal.asciidoc                 | 36 ++++------
 .../graph/traversal/ElementTraversal.java       |  4 ++
 .../process/graph/traversal/GraphTraversal.java | 13 ++--
 .../gremlin/process/graph/traversal/__.java     |  4 ++
 .../traversal/step/map/CountGlobalStep.java     | 76 ++++++++++++++++++++
 .../traversal/step/map/CountLocalStep.java      | 54 ++++++++++++++
 .../graph/traversal/step/map/CountStep.java     | 76 --------------------
 .../traversal/step/map/OrderLocalStep.java      | 12 ++--
 .../strategy/RangeByIsCountStrategy.java        |  4 +-
 .../traversal/step/map/GroovyCountTest.groovy   | 14 +++-
 .../graph/traversal/step/map/CountTest.java     | 31 ++++++++
 12 files changed, 213 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index a56dab0..42aaa1f 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -9,6 +9,7 @@ image::http://www.tinkerpop.com/docs/current/images/gremlin-hindu.png[width=225]
 TinkerPop 3.0.0.M8 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Added `CountLocalStep` / `count(local)` for counting the objects in the current object container.
 * `TraversalComparator` exists which allows for `order().by(outE().count(),decr)`.
 * Apache refactoring: `com.tinkerpop` -> `org.apache.tinkerpop`.
 * `Traversal` is now `Serializable` and with 99% of queries no longer needing lambdas, Gremlin-Java works over the wire.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/docs/src/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-traversal.asciidoc b/docs/src/the-traversal.asciidoc
index fe0910a..b0a1b56 100644
--- a/docs/src/the-traversal.asciidoc
+++ b/docs/src/the-traversal.asciidoc
@@ -217,12 +217,12 @@ The `by()`-step is not an actual step, but instead is a "step-modulator" similar
 ----
 g.V().group().by(bothE().count())                                  <1>
 g.V().group().by(bothE().count()).by('name')                       <2>
-g.V().group().by(bothE().count()).by('name').by(unfold().count())  <3>
+g.V().group().by(bothE().count()).by('name').by(count(local))  <3>
 ----
 
 <1> `by(outE().count())` will group the elements by their edge count (*traversal*).
 <2> `by('name')` will process the grouped elements by their name (*element property projection*).
-<3> `by(unfold().count())` will count the number of elements in each group (*traversal*).
+<3> `by(count(local))` will count the number of elements in each group (*traversal*).
 
 [[coalesce-step]]
 Coalesce Step
@@ -257,6 +257,8 @@ g.V().hasLabel('person').outE('created').count().map {it.get() * 10}.path() <2>
 <1> `count()`-step is a <<a-note-on-barrier-steps,reducing barrier step>> meaning that all of the previous traversers are folded into a new traverser.
 <2> The path of the traverser emanating from `count()` starts at `count()`.
 
+IMPORTANT: `count(local)` counts the current, local object (not the objects in the traversal stream). This works for `Collection`- and `Map`-type objects. For any other object, a count of 1 is returned.
+
 [[choose-step]]
 Choose Step
 ~~~~~~~~~~~
@@ -380,6 +382,7 @@ g.V(1).out('knows').values('name').fold().next().getClass() <2>
 g.V(1).out('knows').values('name').fold(0) {a,b -> a + b.length()} <3>
 g.V().values('age').fold(0) {a,b -> a + b} <4>
 g.V().values('age').fold(0, sum) <5>
+g.V().values('age').sum() <6>
 ----
 
 <1> A parameterless `fold()` will aggregate all the objects into a list and then emit the list.
@@ -387,6 +390,7 @@ g.V().values('age').fold(0, sum) <5>
 <3> `fold()` can be provided two arguments --  a seed value and a reduce bi-function ("vadas" is 5 characters + "josh" with 4 characters).
 <4> What is the total age of the people in the graph?
 <5> The same as before, but using a built-in bi-function.
+<6> The same as before, but using the <<sum-step,`sum()`-step>>.
 
 [[group-step]]
 Group Step
@@ -398,7 +402,7 @@ As traversers propagate across a graph as defined by a traversal, sideEffect com
 ----
 g.V().group().by(label) <1>
 g.V().group().by(label).by('name') <2>
-g.V().group().by(label).by('name').by(unfold().count()) <3>
+g.V().group().by(label).by('name').by(count(local)) <3>
 ----
 
 <1> Group the vertices by their label.
@@ -815,18 +819,6 @@ g.V().values('name').order().by(decr)
 g.V().hasLabel('person').order().by('age', incr).values('name')
 ----
 
-Note that `order()` takes a `Comparator` var args and thus, its possible to do secondary sorting. Secondary sorting is presented below along with the handy `Comparator.comparing()` method.
-
-[gremlin-groovy,modern]
-----
-import static java.util.Comparator.*
-g.V().values('name').order().by(comparing {it[1]}) <1>
-g.V().values('name').order().by(comparing {it[1]}).by(comparing {it[2]}) <2>
-----
-
-<1> Order by the second letter.
-<2> Order by second letter and if a tie, the third letter.
-
 One of the most traversed objects in a traversal is an `Element`. An element can have properties associated with it (i.e. key/value pairs). In many situations, it is desirable to sort an element traversal stream according to a comparison of their properties.
 
 [gremlin-groovy,modern]
@@ -836,7 +828,7 @@ g.V().order().by('name',incr).values('name')
 g.V().order().by('name',decr).values('name')
 ----
 
-The `order()`-step allows the user to provide an arbitrary number of comparators for primary, secondary, etc. sorting. These comparators can be lambdas or they can be pre-defined enums (e.g. `Order.incr`). It is always best to use a pre-defined enum instead of a generic lambda as the underlying vendor may be able to optimize the execution when the comparator is inspectable.
+The `order()`-step allows the user to provide an arbitrary number of comparators for primary, secondary, etc. sorting. In the example below, the primary ordering is based on the outgoing created-edge count. The secondary ordering is based on the age of the person.
 
 [gremlin-groovy,modern]
 ----
@@ -848,15 +840,15 @@ g.V().hasLabel('person').order().by(outE('created').count(), incr).
 
 Randomizing the order of the traversers at a particular point in the traversal is possible with `Order.shuffle`.
 
-[gremlin-groovy]
+[gremlin-groovy,modern]
 ----
-inject((1..9).toList())
-inject((1..9).toList()).order(local).by(Order.shuffle)
-inject((1..9).toList()).order(local).by(Order.shuffle)
-inject(1..5).unfold()
-inject(1..5).unfold().order().by(Order.shuffle)
+g.V().hasLabel('person').order().by(shuffle)
+g.V().hasLabel('person').order().by(shuffle)
 ----
 
+IMPORTANT: `order(local)` orders the current, local object (not the objects in the traversal stream). This works for `Collection`- and `Map`-type objects. For any other object, the object is returned unchanged.
+
+
 [[path-step]]
 Path Step
 ~~~~~~~~~

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/ElementTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/ElementTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/ElementTraversal.java
index ae104ed..2b70428 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/ElementTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/ElementTraversal.java
@@ -182,6 +182,10 @@ public abstract interface ElementTraversal<A extends Element> {
         return this.start().count();
     }
 
+    public default GraphTraversal<A, Long> count(final Scope scope) {
+        return this.start().count(scope);
+    }
+
     public default GraphTraversal<A, Double> sum() {
         return this.start().sum();
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversal.java
index 83986b6..d2a0656 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/GraphTraversal.java
@@ -55,7 +55,8 @@ import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.TimeLimi
 import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.WhereStep;
 import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.BackStep;
 import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.CoalesceStep;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.CountStep;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.CountGlobalStep;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.CountLocalStep;
 import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.EdgeOtherVertexStep;
 import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.EdgeVertexStep;
 import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.FoldStep;
@@ -255,7 +256,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
     }
 
     public default GraphTraversal<S, E> order(final Scope scope) {
-        return scope.equals(Scope.local) ? this.asAdmin().addStep(new OrderLocalStep<>(this.asAdmin())) : this.asAdmin().addStep(new OrderGlobalStep<>(this.asAdmin()));
+        return this.asAdmin().addStep(scope.equals(Scope.global) ? new OrderGlobalStep<>(this.asAdmin()) : new OrderLocalStep<>(this.asAdmin()));
     }
 
     public default <E2> GraphTraversal<S, ? extends Property<E2>> properties(final String... propertyKeys) {
@@ -323,7 +324,11 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
     }
 
     public default GraphTraversal<S, Long> count() {
-        return this.asAdmin().addStep(new CountStep<>(this.asAdmin()));
+        return this.count(Scope.global);
+    }
+
+    public default GraphTraversal<S, Long> count(final Scope scope) {
+        return this.asAdmin().addStep(scope.equals(Scope.global) ? new CountGlobalStep<>(this.asAdmin()) : new CountLocalStep<>(this.asAdmin()));
     }
 
     public default GraphTraversal<S, Double> sum() {
@@ -741,7 +746,7 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
         return this;
     }
 
-    public default <V> GraphTraversal<S, E> by(final Traversal<?,?> traversal, final Comparator<V> endComparator) {
+    public default <V> GraphTraversal<S, E> by(final Traversal<?, ?> traversal, final Comparator<V> endComparator) {
         ((ComparatorHolder<E>) this.asAdmin().getEndStep()).addComparator(new TraversalComparator(traversal.asAdmin(), endComparator));
         return this;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/__.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/__.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/__.java
index a83a382..9c3bc51 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/__.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/__.java
@@ -212,6 +212,10 @@ public class __ {
         return __.<A>start().count();
     }
 
+    public static <A> GraphTraversal<A, Long> count(final Scope scope) {
+        return __.<A>start().count(scope);
+    }
+
     public static <A> GraphTraversal<A, Double> sum() {
         return __.<A>start().sum();
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountGlobalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountGlobalStep.java
new file mode 100644
index 0000000..0179ec9
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountGlobalStep.java
@@ -0,0 +1,76 @@
+/*
+ * 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.process.graph.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.Traversal;
+import org.apache.tinkerpop.gremlin.process.Traverser;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.util.ReducingBarrierStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Reducing;
+import org.apache.tinkerpop.gremlin.process.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
+
+import java.io.Serializable;
+import java.util.EnumSet;
+import java.util.Set;
+import java.util.function.BiFunction;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class CountGlobalStep<S> extends ReducingBarrierStep<S, Long> implements Reducing<Long, Traverser<S>> {
+
+    private static final Set<TraverserRequirement> REQUIREMENTS = EnumSet.of(TraverserRequirement.BULK);
+
+    public CountGlobalStep(final Traversal.Admin traversal) {
+        super(traversal);
+        this.setSeedSupplier(new ConstantSupplier<>(0L));
+        this.setBiFunction(CountBiFunction.<S>instance());
+    }
+
+
+    @Override
+    public Set<TraverserRequirement> getRequirements() {
+        return REQUIREMENTS;
+    }
+
+    @Override
+    public Reducer<Long, Traverser<S>> getReducer() {
+        return new Reducer<>(this.getSeedSupplier(), this.getBiFunction(), true);
+    }
+
+    /////
+
+    private static class CountBiFunction<S> implements BiFunction<Long, Traverser<S>, Long>, Serializable {
+
+        private static final CountBiFunction INSTANCE = new CountBiFunction();
+
+        private CountBiFunction() {
+
+        }
+
+        @Override
+        public Long apply(final Long mutatingSeed, final Traverser<S> traverser) {
+            return mutatingSeed + traverser.bulk();
+        }
+
+        public final static <S> CountBiFunction<S> instance() {
+            return INSTANCE;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountLocalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountLocalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountLocalStep.java
new file mode 100644
index 0000000..7f89abb
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountLocalStep.java
@@ -0,0 +1,54 @@
+/*
+ * 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.process.graph.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.Traversal;
+import org.apache.tinkerpop.gremlin.process.Traverser;
+import org.apache.tinkerpop.gremlin.process.traverser.TraverserRequirement;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class CountLocalStep<S> extends MapStep<S, Long> {
+
+    public CountLocalStep(final Traversal.Admin traversal) {
+        super(traversal);
+    }
+
+    @Override
+    protected Long map(final Traverser.Admin<S> traverser) {
+        final S start = traverser.get();
+        if (start instanceof Collection)
+            return (long) ((Collection) start).size();
+        else if (start instanceof Map)
+            return (long) ((Map) start).size();
+        else
+            return 1L;
+    }
+
+    @Override
+    public Set<TraverserRequirement> getRequirements() {
+        return Collections.singleton(TraverserRequirement.OBJECT);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountStep.java
deleted file mode 100644
index 5f90833..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountStep.java
+++ /dev/null
@@ -1,76 +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.process.graph.traversal.step.map;
-
-import org.apache.tinkerpop.gremlin.process.Traversal;
-import org.apache.tinkerpop.gremlin.process.Traverser;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.util.ReducingBarrierStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.Reducing;
-import org.apache.tinkerpop.gremlin.process.traverser.TraverserRequirement;
-import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
-
-import java.io.Serializable;
-import java.util.EnumSet;
-import java.util.Set;
-import java.util.function.BiFunction;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class CountStep<S> extends ReducingBarrierStep<S, Long> implements Reducing<Long, Traverser<S>> {
-
-    private static final Set<TraverserRequirement> REQUIREMENTS = EnumSet.of(TraverserRequirement.BULK);
-
-    public CountStep(final Traversal.Admin traversal) {
-        super(traversal);
-        this.setSeedSupplier(new ConstantSupplier<>(0L));
-        this.setBiFunction(CountBiFunction.<S>instance());
-    }
-
-
-    @Override
-    public Set<TraverserRequirement> getRequirements() {
-        return REQUIREMENTS;
-    }
-
-    @Override
-    public Reducer<Long, Traverser<S>> getReducer() {
-        return new Reducer<>(this.getSeedSupplier(), this.getBiFunction(), true);
-    }
-
-    /////
-
-    private static class CountBiFunction<S> implements BiFunction<Long, Traverser<S>, Long>, Serializable {
-
-        private static final CountBiFunction INSTANCE = new CountBiFunction();
-
-        private CountBiFunction() {
-
-        }
-
-        @Override
-        public Long apply(final Long mutatingSeed, final Traverser<S> traverser) {
-            return mutatingSeed + traverser.bulk();
-        }
-
-        public final static <S> CountBiFunction<S> instance() {
-            return INSTANCE;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/OrderLocalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/OrderLocalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/OrderLocalStep.java
index 0ee4a90..115a055 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/OrderLocalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/OrderLocalStep.java
@@ -48,13 +48,13 @@ public final class OrderLocalStep<S, M> extends MapStep<S, S> implements Reversi
 
     @Override
     protected S map(final Traverser.Admin<S> traverser) {
-        final Object object = traverser.get();
-        if (object instanceof Collection)
-            return (S) OrderLocalStep.sortCollection((List) object, this.chainedComparator);
-        else if (object instanceof Map)
-            return (S) OrderLocalStep.sortMap((Map) object, this.chainedComparator);
+        final S start = traverser.get();
+        if (start instanceof Collection)
+            return (S) OrderLocalStep.sortCollection((List) start, this.chainedComparator);
+        else if (start instanceof Map)
+            return (S) OrderLocalStep.sortMap((Map) start, this.chainedComparator);
         else
-            throw new IllegalArgumentException("The provided object can not be ordered: " + object);
+            return start;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategy.java
index 71cef1d..ce19296 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategy.java
@@ -24,7 +24,7 @@ import org.apache.tinkerpop.gremlin.process.TraversalEngine;
 import org.apache.tinkerpop.gremlin.process.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.IsStep;
 import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.RangeStep;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.CountStep;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.CountGlobalStep;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 import org.apache.tinkerpop.gremlin.structure.Compare;
 import org.apache.tinkerpop.gremlin.structure.Contains;
@@ -57,7 +57,7 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy impl
         Step prev = null;
         for (int i = 0; i < size; i++) {
             final Step curr = traversal.getSteps().get(i);
-            if (curr instanceof CountStep && i < size - 1) {
+            if (curr instanceof CountGlobalStep && i < size - 1) {
                 final Step next = traversal.getSteps().get(i + 1);
                 if (next instanceof IsStep && !(prev instanceof RangeStep)) { // if a RangeStep was provided, assume that the user knows what he's doing
                     final IsStep isStep = (IsStep) next;

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/GroovyCountTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/GroovyCountTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/GroovyCountTest.groovy
index b03c800..7502e9d 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/GroovyCountTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/GroovyCountTest.groovy
@@ -18,10 +18,10 @@
  */
 package org.apache.tinkerpop.gremlin.process.graph.traversal.step.map
 
+import org.apache.tinkerpop.gremlin.process.ComputerTestHelper
+import org.apache.tinkerpop.gremlin.process.Scope
 import org.apache.tinkerpop.gremlin.process.Traversal
 import org.apache.tinkerpop.gremlin.process.graph.traversal.__
-import org.apache.tinkerpop.gremlin.process.ComputerTestHelper
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.CountTest
 import org.apache.tinkerpop.gremlin.structure.Vertex
 
 /**
@@ -59,6 +59,11 @@ public abstract class GroovyCountTest {
         public Traversal<Vertex, Long> get_g_V_hasXnoX_count() {
             g.V.has('no').count
         }
+
+        @Override
+        public Traversal<Vertex, Long> get_g_V_fold_countXlocalX() {
+            return g.V.fold.count(Scope.local);
+        }
     }
 
     public static class ComputerTest extends CountTest {
@@ -91,5 +96,10 @@ public abstract class GroovyCountTest {
         public Traversal<Vertex, Long> get_g_V_hasXnoX_count() {
             ComputerTestHelper.compute("g.V.has('no').count", g)
         }
+
+        @Override
+        public Traversal<Vertex, Long> get_g_V_fold_countXlocalX() {
+            g.V.fold.count(Scope.local);   // TODO: fold
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/22aa156d/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountTest.java
index 343f64b..fa5bc01 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/step/map/CountTest.java
@@ -20,6 +20,7 @@ package org.apache.tinkerpop.gremlin.process.graph.traversal.step.map;
 
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.Scope;
 import org.apache.tinkerpop.gremlin.process.Traversal;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.junit.Test;
@@ -47,6 +48,8 @@ public abstract class CountTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Long> get_g_V_hasXnoX_count();
 
+    public abstract Traversal<Vertex, Long> get_g_V_fold_countXlocalX();
+
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_count() {
@@ -94,6 +97,15 @@ public abstract class CountTest extends AbstractGremlinProcessTest {
 
     @Test
     @LoadGraphWith(MODERN)
+    public void g_V_hasXnoX_count() {
+        final Traversal<Vertex, Long> traversal = get_g_V_hasXnoX_count();
+        printTraversalForm(traversal);
+        assertEquals(new Long(0), traversal.next());
+        assertFalse(traversal.hasNext());
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
     public void g_V_filterXfalseX_count() {
         final Traversal<Vertex, Long> traversal = get_g_V_hasXnoX_count();
         printTraversalForm(traversal);
@@ -101,6 +113,15 @@ public abstract class CountTest extends AbstractGremlinProcessTest {
         assertFalse(traversal.hasNext());
     }
 
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_fold_countXlocalX() {
+        final Traversal<Vertex, Long> traversal = get_g_V_fold_countXlocalX();
+        printTraversalForm(traversal);
+        assertEquals(new Long(6), traversal.next());
+        assertFalse(traversal.hasNext());
+    }
+
     public static class StandardTest extends CountTest {
 
         @Override
@@ -132,6 +153,11 @@ public abstract class CountTest extends AbstractGremlinProcessTest {
         public Traversal<Vertex, Long> get_g_V_hasXnoX_count() {
             return g.V().has("no").count();
         }
+
+        @Override
+        public Traversal<Vertex, Long> get_g_V_fold_countXlocalX() {
+            return g.V().fold().count(Scope.local);
+        }
     }
 
     public static class ComputerTest extends CountTest {
@@ -169,5 +195,10 @@ public abstract class CountTest extends AbstractGremlinProcessTest {
         public Traversal<Vertex, Long> get_g_V_hasXnoX_count() {
             return g.V().has("no").count().submit(g.compute());
         }
+
+        @Override
+        public Traversal<Vertex, Long> get_g_V_fold_countXlocalX() {
+            return g.V().fold().count(Scope.local); // todo -- fold
+        }
     }
 }