Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B6EB2200BB3 for ; Wed, 2 Nov 2016 23:34:49 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B5836160AFB; Wed, 2 Nov 2016 22:34:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D772E160AF0 for ; Wed, 2 Nov 2016 23:34:48 +0100 (CET) Received: (qmail 39608 invoked by uid 500); 2 Nov 2016 22:34:48 -0000 Mailing-List: contact commits-help@tinkerpop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.apache.org Delivered-To: mailing list commits@tinkerpop.apache.org Received: (qmail 39599 invoked by uid 99); 2 Nov 2016 22:34:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Nov 2016 22:34:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E4B61E0BB1; Wed, 2 Nov 2016 22:34:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: okram@apache.org To: commits@tinkerpop.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: tinkerpop git commit: Added Path.head() and Path.isEmpty() with default method implementations. Have optimized implementations in ImmutablePath and MutablePath. Using methods in the LP-class of traverser (the most heavily used traversers). Date: Wed, 2 Nov 2016 22:34:47 +0000 (UTC) archived-at: Wed, 02 Nov 2016 22:34:49 -0000 Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1542 [created] c2e543727 Added Path.head() and Path.isEmpty() with default method implementations. Have optimized implementations in ImmutablePath and MutablePath. Using methods in the LP-class of traverser (the most heavily used traversers). Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/c2e54372 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/c2e54372 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/c2e54372 Branch: refs/heads/TINKERPOP-1542 Commit: c2e5437275061a95105af885504abcb586b2ee2f Parents: 9096274 Author: Marko A. Rodriguez Authored: Wed Nov 2 16:34:43 2016 -0600 Committer: Marko A. Rodriguez Committed: Wed Nov 2 16:34:43 2016 -0600 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + .../gremlin/process/traversal/Path.java | 19 +++++++++++++++++++ .../traversal/step/util/ImmutablePath.java | 10 ++++++++++ .../process/traversal/step/util/MutablePath.java | 15 ++++++++++++++- .../traverser/B_LP_O_S_SE_SL_Traverser.java | 14 ++++++++------ .../traverser/LP_O_OB_S_SE_SL_Traverser.java | 8 +++++--- 6 files changed, 57 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c2e54372/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 57d7119..10e3cf5 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima TinkerPop 3.2.4 (Release Date: NOT OFFICIALLY RELEASED YET) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* Added `Path.head()` and `Path.isEmpty()` with default method implementations. * Improved ability to release resources in `GraphProvider` instances in the test suite. * Added a `force` option for killing sessions without waiting for transaction close or timeout of a currently running job or multiple jobs. * Deprecated `Session.kill()` and `Session.manualKill()`. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c2e54372/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java index c4bc347..b2916d9 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Path.java @@ -49,6 +49,25 @@ public interface Path extends Cloneable, Iterable { } /** + * Determine if the path is empty or not. + * + * @return whether the path is empty or not. + */ + public default boolean isEmpty() { + return this.size() == 0; + } + + /** + * Get the head of the path. + * + * @param the type of the head of the path + * @return the head of the path + */ + public default A head() { + return (A) this.objects().get(this.size() - 1); + } + + /** * Add a new step to the path with an object and any number of associated labels. * * @param object the new head of the path http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c2e54372/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java index 18f0870..28aac3c 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java @@ -61,6 +61,11 @@ public class ImmutablePath implements Path, Serializable, Cloneable { } @Override + public boolean isEmpty() { + return this.isTail(); + } + + @Override public int size() { int counter = 0; ImmutablePath currentPath = this; @@ -72,6 +77,11 @@ public class ImmutablePath implements Path, Serializable, Cloneable { } @Override + public A head() { + return (A) this.currentObject; + } + + @Override public Path extend(final Object object, final Set labels) { return new ImmutablePath(this, object, labels); } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c2e54372/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java index c87e627..69be820 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java @@ -65,6 +65,15 @@ public class MutablePath implements Path, Serializable { return clone; } + @Override + public boolean isEmpty() { + return this.objects.isEmpty(); + } + + @Override + public A head() { + return (A) this.objects.get(this.objects.size() - 1); + } @Override public int size() { @@ -133,7 +142,11 @@ public class MutablePath implements Path, Serializable { @Override public boolean hasLabel(final String label) { - return this.labels.stream().filter(l -> l.contains(label)).findAny().isPresent(); + for (final Set set : this.labels) { + if (set.contains(label)) + return true; + } + return false; } @Override http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c2e54372/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java index 8c66992..fc16366 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java @@ -41,7 +41,8 @@ public class B_LP_O_S_SE_SL_Traverser extends B_O_S_SE_SL_Traverser { public B_LP_O_S_SE_SL_Traverser(final T t, final Step step, final long initialBulk) { super(t, step, initialBulk); this.path = ImmutablePath.make(); - if (!step.getLabels().isEmpty()) this.path = this.path.extend(t, step.getLabels()); + final Set labels = step.getLabels(); + if (!labels.isEmpty()) this.path = this.path.extend(t, labels); } ///////////////// @@ -66,7 +67,8 @@ public class B_LP_O_S_SE_SL_Traverser extends B_O_S_SE_SL_Traverser { public Traverser.Admin split(final R r, final Step step) { final B_LP_O_S_SE_SL_Traverser clone = (B_LP_O_S_SE_SL_Traverser) super.split(r, step); clone.path = clone.path.clone(); - if (!step.getLabels().isEmpty()) clone.path = clone.path.extend(r, step.getLabels()); + final Set labels = step.getLabels(); + if (!labels.isEmpty()) clone.path = clone.path.extend(r, labels); return clone; } @@ -80,7 +82,7 @@ public class B_LP_O_S_SE_SL_Traverser extends B_O_S_SE_SL_Traverser { @Override public void addLabels(final Set labels) { if (!labels.isEmpty()) - this.path = this.path.size() == 0 || !this.path.get(this.path.size() - 1).equals(this.t) ? + this.path = this.path.isEmpty() || !this.t.equals(this.path.head()) ? this.path.extend(this.t, labels) : this.path.extend(labels); } @@ -89,9 +91,9 @@ public class B_LP_O_S_SE_SL_Traverser extends B_O_S_SE_SL_Traverser { public void keepLabels(final Set labels) { final Set retractLabels = new HashSet<>(); for (final Set stepLabels : this.path.labels()) { - for (final String l : stepLabels) { - if (!labels.contains(l)) - retractLabels.add(l); + for (final String label : stepLabels) { + if (!labels.contains(label)) + retractLabels.add(label); } } this.path = this.path.retract(retractLabels); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c2e54372/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java index c9cc67c..58f420c 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java @@ -41,7 +41,8 @@ public class LP_O_OB_S_SE_SL_Traverser extends O_OB_S_SE_SL_Traverser { public LP_O_OB_S_SE_SL_Traverser(final T t, final Step step) { super(t, step); this.path = ImmutablePath.make(); - if (!step.getLabels().isEmpty()) this.path = this.path.extend(t, step.getLabels()); + final Set labels = step.getLabels(); + if (!labels.isEmpty()) this.path = this.path.extend(t, labels); } ///////////////// @@ -66,7 +67,8 @@ public class LP_O_OB_S_SE_SL_Traverser extends O_OB_S_SE_SL_Traverser { public Traverser.Admin split(final R r, final Step step) { final LP_O_OB_S_SE_SL_Traverser clone = (LP_O_OB_S_SE_SL_Traverser) super.split(r, step); clone.path = clone.path.clone(); - if (!step.getLabels().isEmpty()) clone.path = clone.path.extend(r, step.getLabels()); + final Set labels = step.getLabels(); + if (!labels.isEmpty()) clone.path = clone.path.extend(r, labels); return clone; } @@ -80,7 +82,7 @@ public class LP_O_OB_S_SE_SL_Traverser extends O_OB_S_SE_SL_Traverser { @Override public void addLabels(final Set labels) { if (!labels.isEmpty()) - this.path = this.path.size() == 0 || !this.path.get(this.path.size() - 1).equals(this.t) ? + this.path = this.path.isEmpty() || !this.t.equals(this.path.head()) ? this.path.extend(this.t, labels) : this.path.extend(labels); }