tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [49/50] incubator-tinkerpop git commit: added more docs to Order Step around Columm.keys and Column.values. Added a GraphTraversal.by() safeguard to ensure no ambiguous method call issues.
Date Thu, 03 Dec 2015 16:43:45 GMT
added more docs to Order Step around Columm.keys and Column.values. Added a GraphTraversal.by()
safeguard to ensure no ambiguous method call issues.


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

Branch: refs/heads/TINKERPOP3-982
Commit: 8d04c825c74933155a6b651edb413e37b30bd970
Parents: 0bda36c
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Thu Dec 3 09:42:27 2015 -0700
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Thu Dec 3 09:42:27 2015 -0700

----------------------------------------------------------------------
 docs/src/reference/the-traversal.asciidoc       | 17 +++++++++++++-
 .../gremlin/process/traversal/Order.java        | 24 ++++++++++----------
 .../traversal/dsl/graph/GraphTraversal.java     |  8 ++++---
 .../process/traversal/step/map/OrderTest.java   |  2 +-
 4 files changed, 34 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8d04c825/docs/src/reference/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-traversal.asciidoc b/docs/src/reference/the-traversal.asciidoc
index 6170ad3..5accec3 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -1197,9 +1197,24 @@ 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
+It is possible to use `order(local)` to order the current local object and not the entire
traversal stream. This works for
 `Collection`- and `Map`-type objects. For any other object, the object is returned unchanged.
 
+[gremlin-groovy,modern]
+----
+g.V().values('age').fold().order(local).by(decr) <1>
+g.V().values('age').order(local).by(decr) <2>
+g.V().groupCount().by(inE().count()).order(local).by(values, decr) <3>
+g.V().groupCount().by(inE().count()).order(local).by(keys, incr) <4>
+----
+
+<1> The ages are gathered into a list and then that list is sorted in decreasing order.
+<2> The ages are not gathered and thus `order(local)` is "ordering" single integers
and thus, does nothing.
+<3> The `groupCount()` map is ordered by its values in decreasing order.
+<4> The `groupCount()` map is ordered by its keys in increasing order.
+
+NOTE: The `values` and `keys` enums are from `Column` which is used to select "columns" from
a `Map`, `Map.Entry`, or `Path`.
+
 [[path-step]]
 Path Step
 ~~~~~~~~~

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8d04c825/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Order.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Order.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Order.java
index 4e3801a..72fe715 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Order.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Order.java
@@ -48,10 +48,10 @@ public enum Order implements Comparator<Object> {
             return incr;
         }
     },
-    /**
+    /*
      * @deprecated Use {@link org.apache.tinkerpop.gremlin.structure.Column#keys};
-     */
-    @Deprecated
+       @Deprecated
+    */
     keyIncr {
         @Override
         public int compare(final Object first, final Object second) {
@@ -63,10 +63,10 @@ public enum Order implements Comparator<Object> {
             return keyDecr;
         }
     },
-    /**
+    /*
      * @deprecated Use {@link org.apache.tinkerpop.gremlin.structure.Column#values};
-     */
-    @Deprecated
+     *
+    @Deprecated */
     valueIncr {
         @Override
         public int compare(final Object first, final Object second) {
@@ -78,10 +78,10 @@ public enum Order implements Comparator<Object> {
             return valueDecr;
         }
     },
-    /**
+    /*
      * @deprecated Use {@link org.apache.tinkerpop.gremlin.structure.Column#keys};
-     */
-    @Deprecated
+     *
+    @Deprecated */
     keyDecr {
         @Override
         public int compare(final Object first, final Object second) {
@@ -93,10 +93,10 @@ public enum Order implements Comparator<Object> {
             return keyIncr;
         }
     },
-    /**
+    /*
      * @deprecated Use {@link org.apache.tinkerpop.gremlin.structure.Column#values};
-     */
-    @Deprecated
+     *
+    @Deprecated */
     valueDecr {
         @Override
         public int compare(final Object first, final Object second) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8d04c825/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 3673bce..5dd963c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -1164,7 +1164,7 @@ public interface GraphTraversal<S, E> extends Traversal<S,
E> {
     }
 
 
-    ////
+    //// PROJECTION BY-MODULATORS
 
     public default GraphTraversal<S, E> by(final Traversal<?, ?> byTraversal)
{
         ((TraversalParent) this.asAdmin().getEndStep()).addLocalChild(byTraversal.asAdmin());
@@ -1187,7 +1187,7 @@ public interface GraphTraversal<S, E> extends Traversal<S,
E> {
         return this.by(new ElementValueTraversal<>(elementPropertyKey));
     }
 
-    ////
+    //// COMPARATOR BY-MODULATORS
 
     public default GraphTraversal<S, E> by(final Comparator<E> comparator) {
         ((ComparatorHolder<E>) this.asAdmin().getEndStep()).addComparator(comparator);
@@ -1204,7 +1204,9 @@ public interface GraphTraversal<S, E> extends Traversal<S,
E> {
 
     public default <V> GraphTraversal<S, E> by(final Function<Element, V>
elementFunctionProjection,
                                                final Comparator<V> elementFunctionValueComparator)
{
-        return this.by((Comparator) new ElementFunctionComparator<>(elementFunctionProjection,
elementFunctionValueComparator));
+        return ((Function) elementFunctionProjection) instanceof Column ?
+                this.by((Column) ((Function) elementFunctionProjection), elementFunctionValueComparator)
:
+                this.by((Comparator) new ElementFunctionComparator<>(elementFunctionProjection,
elementFunctionValueComparator));
     }
 
     public default <V> GraphTraversal<S, E> by(final String elementPropertyProjection,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/8d04c825/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
index 4475b7c..b69c625 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
@@ -364,7 +364,7 @@ public abstract class OrderTest extends AbstractGremlinProcessTest {
                 map.put(3, (int) v.get().value("age") * 3);
                 map.put(4, (int) v.get().value("age"));
                 return map;
-            }).order(Scope.local).by(Column.values, Order.decr).by(Column.keys,Order.incr);
+            }).order(Scope.local).by(Column.values, Order.decr).by(Column.keys, Order.incr);
         }
 
         @Override


Mime
View raw message