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 2016/11/02 22:34:47 UTC
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).
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 <ok...@gmail.com>
Authored: Wed Nov 2 16:34:43 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
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<Object> {
}
/**
+ * 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 <A> the type of the head of the path
+ * @return the head of the path
+ */
+ public default <A> 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> A head() {
+ return (A) this.currentObject;
+ }
+
+ @Override
public Path extend(final Object object, final Set<String> 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> 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<String> 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<T> extends B_O_S_SE_SL_Traverser<T> {
public B_LP_O_S_SE_SL_Traverser(final T t, final Step<T, ?> 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<String> 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<T> extends B_O_S_SE_SL_Traverser<T> {
public <R> Traverser.Admin<R> split(final R r, final Step<T, R> step) {
final B_LP_O_S_SE_SL_Traverser<R> clone = (B_LP_O_S_SE_SL_Traverser<R>) super.split(r, step);
clone.path = clone.path.clone();
- if (!step.getLabels().isEmpty()) clone.path = clone.path.extend(r, step.getLabels());
+ final Set<String> 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<T> extends B_O_S_SE_SL_Traverser<T> {
@Override
public void addLabels(final Set<String> 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<T> extends B_O_S_SE_SL_Traverser<T> {
public void keepLabels(final Set<String> labels) {
final Set<String> retractLabels = new HashSet<>();
for (final Set<String> 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<T> extends O_OB_S_SE_SL_Traverser<T> {
public LP_O_OB_S_SE_SL_Traverser(final T t, final Step<T, ?> step) {
super(t, step);
this.path = ImmutablePath.make();
- if (!step.getLabels().isEmpty()) this.path = this.path.extend(t, step.getLabels());
+ final Set<String> 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<T> extends O_OB_S_SE_SL_Traverser<T> {
public <R> Traverser.Admin<R> split(final R r, final Step<T, R> step) {
final LP_O_OB_S_SE_SL_Traverser<R> clone = (LP_O_OB_S_SE_SL_Traverser<R>) super.split(r, step);
clone.path = clone.path.clone();
- if (!step.getLabels().isEmpty()) clone.path = clone.path.extend(r, step.getLabels());
+ final Set<String> 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<T> extends O_OB_S_SE_SL_Traverser<T> {
@Override
public void addLabels(final Set<String> 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);
}