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/05/18 22:46:31 UTC
[2/2] incubator-tinkerpop git commit: moved Contains, Order, Operator,
P, Compare to process/traversal package.
moved Contains, Order, Operator, P, Compare to process/traversal package.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/cf93500e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/cf93500e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/cf93500e
Branch: refs/heads/master
Commit: cf93500eccc9c34c539d24e80246ba346dd08de0
Parents: 9d003c4
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon May 18 14:46:37 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon May 18 14:46:37 2015 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../gremlin/process/traversal/Compare.java | 113 +++++++++++
.../gremlin/process/traversal/Contains.java | 64 +++++++
.../gremlin/process/traversal/Operator.java | 125 +++++++++++++
.../gremlin/process/traversal/Order.java | 114 +++++++++++
.../tinkerpop/gremlin/process/traversal/P.java | 186 ++++++++++++++++++
.../traversal/dsl/graph/GraphTraversal.java | 4 +-
.../gremlin/process/traversal/dsl/graph/__.java | 2 +-
.../process/traversal/step/filter/HasStep.java | 2 +-
.../process/traversal/step/filter/IsStep.java | 4 +-
.../traversal/step/filter/WhereStep.java | 4 +-
.../traversal/step/map/OrderGlobalStep.java | 2 +-
.../traversal/step/util/HasContainer.java | 6 +-
.../strategy/decoration/ElementIdStrategy.java | 2 +-
.../strategy/decoration/PartitionStrategy.java | 3 +-
.../strategy/decoration/SubgraphStrategy.java | 2 +-
.../optimization/RangeByIsCountStrategy.java | 8 +-
.../gremlin/process/traversal/util/AndP.java | 69 +++++++
.../process/traversal/util/ConjunctionP.java | 98 ++++++++++
.../gremlin/process/traversal/util/OrP.java | 65 +++++++
.../process/traversal/util/TraversalP.java | 95 ++++++++++
.../tinkerpop/gremlin/structure/Compare.java | 113 -----------
.../tinkerpop/gremlin/structure/Contains.java | 64 -------
.../tinkerpop/gremlin/structure/Operator.java | 125 -------------
.../tinkerpop/gremlin/structure/Order.java | 114 -----------
.../apache/tinkerpop/gremlin/structure/P.java | 187 -------------------
.../gremlin/structure/io/gryo/GryoMapper.java | 2 +-
.../tinkerpop/gremlin/structure/util/AndP.java | 70 -------
.../gremlin/structure/util/ConjunctionP.java | 99 ----------
.../tinkerpop/gremlin/structure/util/OrP.java | 66 -------
.../gremlin/structure/util/TraversalP.java | 96 ----------
.../gremlin/process/traversal/CompareTest.java | 121 ++++++++++++
.../step/filter/ConjunctionStepTest.java | 4 +-
.../PartitionStrategyTraverseTest.java | 2 +-
.../RangeByIsCountStrategyTest.java | 2 +-
.../process/util/TraversalHelperTest.java | 2 -
.../gremlin/structure/CompareTest.java | 121 ------------
.../traversal/step/map/GroovyMatchTest.groovy | 2 +-
.../engine/GremlinExecutorPerformanceTest.java | 2 +-
.../AbstractImportCustomizerProvider.java | 10 +-
.../traversal/step/branch/LocalTest.java | 4 +-
.../process/traversal/step/filter/AndTest.java | 3 +-
.../process/traversal/step/filter/HasTest.java | 2 +-
.../process/traversal/step/filter/IsTest.java | 2 +-
.../process/traversal/step/filter/OrTest.java | 3 +-
.../traversal/step/filter/WhereTest.java | 2 +-
.../process/traversal/step/map/FoldTest.java | 3 +-
.../process/traversal/step/map/MatchTest.java | 3 +-
.../process/traversal/step/map/OrderTest.java | 2 +-
.../process/traversal/step/map/SelectTest.java | 2 +-
.../process/traversal/step/map/VertexTest.java | 4 +-
.../traversal/step/sideEffect/SackTest.java | 3 +-
.../decoration/SubgraphStrategyProcessTest.java | 2 +-
.../gremlin/structure/VertexPropertyTest.java | 1 +
.../tinkerpop/gremlin/structure/io/IoTest.java | 2 +-
.../step/sideEffect/TinkerGraphStep.java | 2 +-
.../tinkergraph/structure/TinkerGraphTest.java | 3 +-
57 files changed, 1098 insertions(+), 1116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 3c54823..b46878e 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::http://www.tinkerpop.com/docs/current/images/gremlin-hindu.png[width=225]
TinkerPop 3.0.0.M9 (NOT OFFICIALLY RELEASED YET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+* Moved `Compare`, `Contains`, `Order`, `Operator`, and `P` to `process/traversal` from `structure/` as they are process-based objects.
* `HasContainer` now uses `P` predicate as helper methods and tests are more thorough on `P`.
* Changed Gremlin Server integration/performance tests to be runnable from within the `gremlin-server` directory or from the project root.
* Moved the string methods of `TraversalHelper` to `StringFactory`.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Compare.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Compare.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Compare.java
new file mode 100644
index 0000000..c4b68fa
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Compare.java
@@ -0,0 +1,113 @@
+/*
+ * 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.traversal;
+
+import java.util.function.BiPredicate;
+
+/**
+ * {@link Compare} is a {@link java.util.function.BiPredicate} that determines whether the first argument is {@code ==}, {@code !=},
+ * {@code >}, {@code >=}, {@code <}, {@code <=} to the second argument.
+ *
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public enum Compare implements BiPredicate<Object, Object> {
+
+ eq {
+ @Override
+ public boolean test(final Object first, final Object second) {
+ return null == first ? null == second : (first instanceof Number && second instanceof Number
+ && !first.getClass().equals(second.getClass())
+ ? ((Number) first).doubleValue() == ((Number) second).doubleValue()
+ : first.equals(second));
+ }
+
+ @Override
+ public Compare negate() {
+ return neq;
+ }
+ }, neq {
+ @Override
+ public boolean test(final Object first, final Object second) {
+ return !eq.test(first, second);
+ }
+
+ @Override
+ public Compare negate() {
+ return eq;
+ }
+ }, gt {
+ @Override
+ public boolean test(final Object first, final Object second) {
+ return null != first && null != second && (
+ first instanceof Number && second instanceof Number && !first.getClass().equals(second.getClass())
+ ? ((Number) first).doubleValue() > ((Number) second).doubleValue()
+ : ((Comparable) first).compareTo(second) > 0);
+ }
+
+ @Override
+ public Compare negate() {
+ return lte;
+ }
+ }, gte {
+ @Override
+ public boolean test(final Object first, final Object second) {
+ return null == first ? null == second : (null != second && !lt.test(first, second));
+ }
+
+ @Override
+ public Compare negate() {
+ return lt;
+ }
+ }, lt {
+ @Override
+ public boolean test(final Object first, final Object second) {
+ return null != first && null != second && (
+ first instanceof Number && second instanceof Number && !first.getClass().equals(second.getClass())
+ ? ((Number) first).doubleValue() < ((Number) second).doubleValue()
+ : ((Comparable) first).compareTo(second) < 0);
+ }
+
+ @Override
+ public Compare negate() {
+ return gte;
+ }
+ }, lte {
+ @Override
+ public boolean test(final Object first, final Object second) {
+ return null == first ? null == second : (null != second && !gt.test(first, second));
+ }
+
+ @Override
+ public Compare negate() {
+ return gt;
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ */
+ /*@Override
+ public abstract boolean test(final Object first, final Object second);*/
+
+ /**
+ * Produce the opposite representation of the current {@code Compare} enum.
+ */
+ @Override
+ public abstract Compare negate();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java
new file mode 100644
index 0000000..5e4e804
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Contains.java
@@ -0,0 +1,64 @@
+/*
+ * 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.traversal;
+
+import java.util.Collection;
+import java.util.function.BiPredicate;
+
+/**
+ * {@link Contains} is a {@link java.util.function.BiPredicate} that evaluates whether the first object is contained within (or not
+ * within) the second collection object. For example:
+ * <p/>
+ * <pre>
+ * gremlin Contains.within [gremlin, blueprints, furnace] == true
+ * gremlin Contains.without [gremlin, rexster] == false
+ * rexster Contains.without [gremlin, blueprints, furnace] == true
+ * </pre>
+ *
+ * @author Pierre De Wilde
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public enum Contains implements BiPredicate<Object, Collection> {
+
+ within {
+ @Override
+ public boolean test(final Object first, final Collection second) {
+ return second.contains(first);
+ }
+ }, without {
+ @Override
+ public boolean test(final Object first, final Collection second) {
+ return !second.contains(first);
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public abstract boolean test(final Object first, final Collection second);
+
+ /**
+ * Produce the opposite representation of the current {@code Contains} enum.
+ */
+ @Override
+ public Contains negate() {
+ return this.equals(within) ? without : within;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Operator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Operator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Operator.java
new file mode 100644
index 0000000..93ebb36
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Operator.java
@@ -0,0 +1,125 @@
+/*
+ * 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.traversal;
+
+import java.util.function.BinaryOperator;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public enum Operator implements BinaryOperator<Number> {
+
+
+ sum {
+ public Number apply(final Number a, final Number b) {
+ final Class<? extends Number> numberClass = a.getClass();
+ if (numberClass.equals(Integer.class)) {
+ return a.intValue() + b.intValue();
+ } else if (numberClass.equals(Long.class)) {
+ return a.longValue() + b.longValue();
+ } else if (numberClass.equals(Float.class)) {
+ return a.floatValue() + b.floatValue();
+ } else if (numberClass.equals(Double.class)) {
+ return a.doubleValue() + b.doubleValue();
+ } else {
+ throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
+ }
+ }
+ },
+ minus {
+ public Number apply(final Number a, final Number b) {
+ final Class<? extends Number> numberClass = a.getClass();
+ if (numberClass.equals(Integer.class)) {
+ return a.intValue() - b.intValue();
+ } else if (numberClass.equals(Long.class)) {
+ return a.longValue() - b.longValue();
+ } else if (numberClass.equals(Float.class)) {
+ return a.floatValue() - b.floatValue();
+ } else if (numberClass.equals(Double.class)) {
+ return a.doubleValue() - b.doubleValue();
+ } else {
+ throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
+ }
+ }
+ },
+ mult {
+ public Number apply(final Number a, final Number b) {
+ final Class<? extends Number> numberClass = a.getClass();
+ if (numberClass.equals(Integer.class)) {
+ return a.intValue() * b.intValue();
+ } else if (numberClass.equals(Long.class)) {
+ return a.longValue() * b.longValue();
+ } else if (numberClass.equals(Float.class)) {
+ return a.floatValue() * b.floatValue();
+ } else if (numberClass.equals(Double.class)) {
+ return a.doubleValue() * b.doubleValue();
+ } else {
+ throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
+ }
+ }
+ },
+ div {
+ public Number apply(final Number a, final Number b) {
+ final Class<? extends Number> numberClass = a.getClass();
+ if (numberClass.equals(Integer.class)) {
+ return a.intValue() / b.intValue();
+ } else if (numberClass.equals(Long.class)) {
+ return a.longValue() / b.longValue();
+ } else if (numberClass.equals(Float.class)) {
+ return a.floatValue() / b.floatValue();
+ } else if (numberClass.equals(Double.class)) {
+ return a.doubleValue() / b.doubleValue();
+ } else {
+ throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
+ }
+ }
+ },
+ min {
+ public Number apply(final Number a, final Number b) {
+ final Class<? extends Number> numberClass = a.getClass();
+ if (numberClass.equals(Integer.class)) {
+ return Math.min(a.intValue(), b.intValue());
+ } else if (numberClass.equals(Long.class)) {
+ return Math.min(a.longValue(), b.longValue());
+ } else if (numberClass.equals(Float.class)) {
+ return Math.min(a.floatValue(), b.floatValue());
+ } else if (numberClass.equals(Double.class)) {
+ return Math.min(a.doubleValue(), b.doubleValue());
+ } else {
+ throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
+ }
+ }
+ },
+ max {
+ public Number apply(final Number a, final Number b) {
+ final Class<? extends Number> numberClass = a.getClass();
+ if (numberClass.equals(Integer.class)) {
+ return Math.max(a.intValue(), b.intValue());
+ } else if (numberClass.equals(Long.class)) {
+ return Math.max(a.longValue(), b.longValue());
+ } else if (numberClass.equals(Float.class)) {
+ return Math.max(a.floatValue(), b.floatValue());
+ } else if (numberClass.equals(Double.class)) {
+ return Math.max(a.doubleValue(), b.doubleValue());
+ } else {
+ throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/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
new file mode 100644
index 0000000..e04863b
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Order.java
@@ -0,0 +1,114 @@
+/*
+ * 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.traversal;
+
+import java.util.Comparator;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public enum Order implements Comparator<Object> {
+
+ incr {
+ @Override
+ public int compare(final Object first, final Object second) {
+ return Comparator.<Comparable>naturalOrder().compare((Comparable) first, (Comparable) second);
+ }
+
+ @Override
+ public Order reversed() {
+ return decr;
+ }
+ }, decr {
+ @Override
+ public int compare(final Object first, final Object second) {
+ return Comparator.<Comparable>reverseOrder().compare((Comparable) first, (Comparable) second);
+ }
+
+ @Override
+ public Order reversed() {
+ return incr;
+ }
+ }, keyIncr {
+ @Override
+ public int compare(final Object first, final Object second) {
+ return Comparator.<Comparable>naturalOrder().compare(((Map.Entry<Comparable, ?>) first).getKey(), ((Map.Entry<Comparable, ?>) second).getKey());
+ }
+
+ @Override
+ public Order reversed() {
+ return keyDecr;
+ }
+ }, valueIncr {
+ @Override
+ public int compare(final Object first, final Object second) {
+ return Comparator.<Comparable>naturalOrder().compare(((Map.Entry<?, Comparable>) first).getValue(), ((Map.Entry<?, Comparable>) second).getValue());
+ }
+
+ @Override
+ public Order reversed() {
+ return valueDecr;
+ }
+ }, keyDecr {
+ @Override
+ public int compare(final Object first, final Object second) {
+ return Comparator.<Comparable>reverseOrder().compare(((Map.Entry<Comparable, ?>) first).getKey(), ((Map.Entry<Comparable, ?>) second).getKey());
+ }
+
+ @Override
+ public Order reversed() {
+ return keyIncr;
+ }
+ }, valueDecr {
+ @Override
+ public int compare(final Object first, final Object second) {
+ return Comparator.<Comparable>reverseOrder().compare(((Map.Entry<?, Comparable>) first).getValue(), ((Map.Entry<?, Comparable>) second).getValue());
+ }
+
+ @Override
+ public Order reversed() {
+ return valueIncr;
+ }
+ }, shuffle {
+ @Override
+ public int compare(final Object first, final Object second) {
+ return RANDOM.nextBoolean() ? -1 : 1;
+ }
+
+ @Override
+ public Order reversed() {
+ return shuffle;
+ }
+ };
+
+ private static final Random RANDOM = new Random();
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract int compare(final Object first, final Object second);
+
+ /**
+ * Produce the opposite representation of the current {@code Order} enum.
+ */
+ @Override
+ public abstract Order reversed();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java
new file mode 100644
index 0000000..ecd37e7
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/P.java
@@ -0,0 +1,186 @@
+/*
+ *
+ * * 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.traversal;
+
+import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalP;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.function.BiPredicate;
+import java.util.function.Predicate;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class P<V> implements Predicate<V>, Serializable, Cloneable {
+
+ protected BiPredicate<V, V> biPredicate;
+ protected V value;
+
+ public P(final BiPredicate<V, V> biPredicate, final V value) {
+ this.value = value;
+ this.biPredicate = biPredicate;
+ }
+
+ public BiPredicate<V, V> getBiPredicate() {
+ return this.biPredicate;
+ }
+
+ public V getValue() {
+ return this.value;
+ }
+
+ public void setValue(final V value) {
+ this.value = value;
+ }
+
+ @Override
+ public boolean test(final V testValue) {
+ return this.biPredicate.test(testValue, this.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.biPredicate.hashCode() + this.value.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ return other instanceof P &&
+ ((P) other).getClass().equals(this.getClass()) &&
+ ((P) other).getBiPredicate().equals(this.biPredicate) &&
+ ((((P) other).getValue() == null && this.value == null) || ((P) other).getValue().equals(this.value));
+ }
+
+ @Override
+ public String toString() {
+ return null == this.value ? this.biPredicate.toString() : this.biPredicate.toString() + "(" + this.value + ")";
+ }
+
+ @Override
+ public P<V> negate() {
+ return new P<>(this.biPredicate.negate(), this.value);
+ }
+
+ public P<V> and(final Traversal<?, ?> traversal) {
+ return this.and((Predicate) P.traversal(traversal));
+ }
+
+ public P<V> or(final Traversal<?, ?> traversal) {
+ return this.or((Predicate) P.traversal(traversal));
+ }
+
+ @Override
+ public P<V> and(final Predicate<? super V> predicate) {
+ if (!(predicate instanceof P))
+ throw new IllegalArgumentException("Only P predicates can be and'd together");
+ return new AndP<>(this, (P<V>) predicate);
+ }
+
+ @Override
+ public P<V> or(final Predicate<? super V> predicate) {
+ if (!(predicate instanceof P))
+ throw new IllegalArgumentException("Only P predicates can be or'd together");
+ return new OrP<>(this, (P<V>) predicate);
+ }
+
+ public P<V> clone() {
+ try {
+ return (P<V>) super.clone();
+ } catch (final CloneNotSupportedException e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ }
+
+ //////////////// statics
+
+ public static <V> P<V> eq(final V value) {
+ return new P(Compare.eq, value);
+ }
+
+ public static <V> P<V> neq(final V value) {
+ return new P(Compare.neq, value);
+ }
+
+ public static <V> P<V> lt(final V value) {
+ return new P(Compare.lt, value);
+ }
+
+ public static <V> P<V> lte(final V value) {
+ return new P(Compare.lte, value);
+ }
+
+ public static <V> P<V> gt(final V value) {
+ return new P(Compare.gt, value);
+ }
+
+ public static <V> P<V> gte(final V value) {
+ return new P(Compare.gte, value);
+ }
+
+ public static <V> P<V> inside(final V first, final V second) {
+ return new AndP<>(new P(Compare.gt, first), new P(Compare.lt, second));
+ }
+
+ public static <V> P<V> outside(final V first, final V second) {
+ return new AndP<>(new P(Compare.lt, first), new P(Compare.gt, second));
+ }
+
+ public static <V> P<V> between(final V first, final V second) {
+ return new AndP<>(new P(Compare.gte, first), new P(Compare.lt, second));
+ }
+
+ public static <V> P<V> within(final V... values) {
+ return P.within(Arrays.asList(values));
+ }
+
+ public static <V> P<V> within(final Collection<V> value) {
+ return new P(Contains.within, value);
+ }
+
+ public static <V> P<V> without(final V... values) {
+ return P.without(Arrays.asList(values));
+ }
+
+ public static <V> P<V> without(final Collection<V> value) {
+ return new P(Contains.without, value);
+ }
+
+ public static <S, E> P<E> traversal(final Traversal<S, E> traversal) {
+ return new TraversalP<>(traversal.asAdmin(), false);
+ }
+
+ public static <S, E> P<E> not(final Traversal<S, E> traversal) {
+ return new TraversalP<>(traversal.asAdmin(), true);
+ }
+
+ public static P test(final BiPredicate biPredicate, final Object value) {
+ return new P(biPredicate, value);
+ }
+
+ public static <V> P<V> not(final P<V> predicate) {
+ return predicate.negate();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/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 c00680a..ddf9262 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
@@ -120,8 +120,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.Order;
-import org.apache.tinkerpop.gremlin.structure.P;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.PropertyType;
import org.apache.tinkerpop.gremlin.structure.T;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
index 0eb8652..71d513a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
@@ -25,7 +25,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.P;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/HasStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/HasStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/HasStep.java
index c92a7d6..89f1e73 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/HasStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/HasStep.java
@@ -26,7 +26,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
-import org.apache.tinkerpop.gremlin.structure.util.TraversalP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalP;
import java.util.ArrayList;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/IsStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/IsStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/IsStep.java
index 2084044..21b0b9e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/IsStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/IsStep.java
@@ -22,9 +22,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
-import org.apache.tinkerpop.gremlin.structure.P;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
-import org.apache.tinkerpop.gremlin.structure.util.TraversalP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalP;
import java.util.Collections;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
index 19e24a3..4c4bfd9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
@@ -25,9 +25,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
-import org.apache.tinkerpop.gremlin.structure.P;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
-import org.apache.tinkerpop.gremlin.structure.util.TraversalP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalP;
import java.util.Collection;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderGlobalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderGlobalStep.java
index 54d8035..d9d7235 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderGlobalStep.java
@@ -26,7 +26,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.CollectingBarrie
import org.apache.tinkerpop.gremlin.process.traversal.step.util.TraversalComparator;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
-import org.apache.tinkerpop.gremlin.structure.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.util.function.ChainedComparator;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
index cee6697..49ed3b5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/HasContainer.java
@@ -19,13 +19,13 @@
package org.apache.tinkerpop.gremlin.process.traversal.step.util;
import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.P;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.structure.util.AndP;
-import org.apache.tinkerpop.gremlin.structure.util.OrP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import java.io.Serializable;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
index 223713e..7b18b83 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
@@ -33,7 +33,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.P;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.structure.PropertyType;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
index 5c1b1b7..69155e6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
@@ -27,8 +27,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GraphStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import org.apache.tinkerpop.gremlin.structure.Contains;
-import org.apache.tinkerpop.gremlin.structure.P;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
import java.util.*;
import java.util.stream.Stream;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
index 38e84e7..15c1262 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
@@ -37,7 +37,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversal
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.P;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java
index 5b59d25..157acb3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java
@@ -26,10 +26,10 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalSte
import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import org.apache.tinkerpop.gremlin.structure.Compare;
-import org.apache.tinkerpop.gremlin.structure.Contains;
-import org.apache.tinkerpop.gremlin.structure.P;
-import org.apache.tinkerpop.gremlin.structure.util.AndP;
+import org.apache.tinkerpop.gremlin.process.traversal.Compare;
+import org.apache.tinkerpop.gremlin.process.traversal.Contains;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
import java.util.Collection;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/AndP.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/AndP.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/AndP.java
new file mode 100644
index 0000000..f87caff
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/AndP.java
@@ -0,0 +1,69 @@
+/*
+ *
+ * * 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.traversal.util;
+
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+
+import java.util.function.Predicate;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class AndP<V> extends ConjunctionP<V> {
+
+ public AndP(final P<V> predicate, final P<V>... predicates) {
+ super(predicate, predicates);
+ }
+
+ protected AndP(final ConjunctionP<V> other) {
+ super(other);
+ }
+
+ @Override
+ public boolean test(final V v) {
+ for (final P<V> predicate : this.predicates) {
+ if (!predicate.test(v))
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public P<V> and(final Predicate<? super V> predicate) {
+ if (!(predicate instanceof P))
+ throw new IllegalArgumentException("Only P predicates can be and'd together");
+ this.predicates.add((P<V>) predicate); // TODO: clone and add?
+ return this;
+ }
+
+ @Override
+ public P<V> negate() {
+ super.negate();
+ final P[] arg2 = new P[this.predicates.size()-1];
+ return new OrP(this.predicates.get(0), this.predicates.subList(1, this.predicates.size()).toArray(arg2));
+ }
+
+ @Override
+ public String toString() {
+ return "and(" + this.predicates + ")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/ConjunctionP.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/ConjunctionP.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/ConjunctionP.java
new file mode 100644
index 0000000..cab50ed
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/ConjunctionP.java
@@ -0,0 +1,98 @@
+/*
+ *
+ * * 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.traversal.util;
+
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Predicate;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public abstract class ConjunctionP<V> extends P<V> {
+
+ protected List<P<V>> predicates;
+
+ public ConjunctionP(final P<V> predicate, final P<V>... predicates) {
+ super(null, null);
+ this.predicates = new ArrayList<>();
+ this.predicates.add(predicate);
+ for (final P<V> p : predicates) {
+ this.predicates.add(p);
+ }
+ }
+
+ protected ConjunctionP(final ConjunctionP<V> other) {
+ super(null, null);
+ this.predicates = other.predicates;
+ }
+
+ public List<P<V>> getPredicates() {
+ return Collections.unmodifiableList(this.predicates);
+ }
+
+ @Override
+ public P<V> negate() {
+ final List<P<V>> negated = new ArrayList<>();
+ for (final P<V> predicate : this.predicates) {
+ negated.add(predicate.negate());
+ }
+ this.predicates = negated;
+ return this;
+ }
+
+ protected P<V> negate(final ConjunctionP<V> p) {
+ final List<P<V>> negated = new ArrayList<>();
+ for (final P<V> predicate : this.predicates) {
+ negated.add(predicate.negate());
+ }
+ p.predicates = negated;
+ return p;
+ }
+
+ @Override
+ public ConjunctionP<V> clone() {
+ final ConjunctionP<V> clone = (ConjunctionP<V>) super.clone();
+ clone.predicates = new ArrayList<>();
+ for (final P<V> p : this.predicates) {
+ clone.predicates.add(p.clone());
+ }
+ return clone;
+ }
+
+ @Override
+ public P<V> and(final Predicate<? super V> predicate) {
+ if (!(predicate instanceof P))
+ throw new IllegalArgumentException("Only P predicates can be and'd together");
+ return new AndP<V>(this, (P<V>) predicate);
+ }
+
+ @Override
+ public P<V> or(final Predicate<? super V> predicate) {
+ if (!(predicate instanceof P))
+ throw new IllegalArgumentException("Only P predicates can be or'd together");
+ return new OrP<V>(this, (P<V>) predicate);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/OrP.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/OrP.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/OrP.java
new file mode 100644
index 0000000..f6132d2
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/OrP.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * * 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.traversal.util;
+
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+
+import java.util.function.Predicate;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class OrP<V> extends ConjunctionP<V> {
+
+ public OrP(final P<V> predicate, final P<V>... predicates) {
+ super(predicate, predicates);
+ }
+
+ @Override
+ public boolean test(final V v) {
+ for (final P<V> predicate : this.predicates) {
+ if (predicate.test(v))
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public P<V> or(final Predicate<? super V> predicate) {
+ if (!(predicate instanceof P))
+ throw new IllegalArgumentException("Only P predicates can be or'd together");
+ this.predicates.add((P<V>) predicate); // TODO: clone and add?
+ return this;
+ }
+
+ @Override
+ public P<V> negate() {
+ super.negate();
+ final P[] arg2 = new P[this.predicates.size()-1];
+ return new AndP(this.predicates.get(0), this.predicates.subList(1, this.predicates.size()).toArray(arg2));
+ }
+
+ @Override
+ public String toString() {
+ return "or(" + this.predicates + ")";
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalP.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalP.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalP.java
new file mode 100644
index 0000000..b006272
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalP.java
@@ -0,0 +1,95 @@
+/*
+ *
+ * * 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.traversal.util;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+
+import java.util.function.BiPredicate;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class TraversalP<S, E> extends P<E> {
+
+ private Traversal.Admin<S, E> traversal;
+ private final boolean negate;
+
+ public TraversalP(final Traversal.Admin<S, E> traversal, final E end, final boolean negate) {
+ super(null, end);
+ this.traversal = traversal;
+ this.negate = negate;
+ this.biPredicate = (BiPredicate) new TraversalBiPredicate(this);
+ }
+
+ public TraversalP(final Traversal.Admin<S, E> traversal, final boolean negate) {
+ this(traversal, null, negate);
+ }
+
+ public Traversal.Admin<S, E> getTraversal() {
+ return this.traversal;
+ }
+
+ @Override
+ public TraversalP<S, E> negate() {
+ return new TraversalP<>(this.traversal.clone(), this.value, !this.negate);
+ }
+
+ @Override
+ public TraversalP<S, E> clone() {
+ final TraversalP<S, E> clone = (TraversalP<S, E>) super.clone();
+ clone.traversal = this.traversal.clone();
+ clone.biPredicate = (BiPredicate) new TraversalBiPredicate<>(clone);
+ return clone;
+ }
+
+ private static class TraversalBiPredicate<S, E> implements BiPredicate<S, E> {
+
+ private final TraversalP<S, E> traversalP;
+
+ public TraversalBiPredicate(final TraversalP<S, E> traversalP) {
+ this.traversalP = traversalP;
+ }
+
+ @Override
+ public boolean test(final S start, final E end) {
+ if (null == start)
+ throw new IllegalArgumentException("The traversal must be provided a start: " + traversalP.traversal);
+ final boolean result;
+ if (start instanceof Traverser)
+ result = null == end ?
+ TraversalUtil.test(((Traverser<S>) start).asAdmin(), traversalP.traversal) :
+ TraversalUtil.test(((Traverser<S>) start).asAdmin(), traversalP.traversal, end);
+ else
+ result = null == end ?
+ TraversalUtil.test(start, traversalP.traversal) :
+ TraversalUtil.test(start, traversalP.traversal, end);
+ return traversalP.negate ? !result : result;
+ }
+
+ @Override
+ public String toString() {
+ return this.traversalP.negate ? "!" + this.traversalP.traversal.toString() : this.traversalP.traversal.toString();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Compare.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Compare.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Compare.java
deleted file mode 100644
index 93468c4..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Compare.java
+++ /dev/null
@@ -1,113 +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.structure;
-
-import java.util.function.BiPredicate;
-
-/**
- * {@link Compare} is a {@link java.util.function.BiPredicate} that determines whether the first argument is {@code ==}, {@code !=},
- * {@code >}, {@code >=}, {@code <}, {@code <=} to the second argument.
- *
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public enum Compare implements BiPredicate<Object, Object> {
-
- eq {
- @Override
- public boolean test(final Object first, final Object second) {
- return null == first ? null == second : (first instanceof Number && second instanceof Number
- && !first.getClass().equals(second.getClass())
- ? ((Number) first).doubleValue() == ((Number) second).doubleValue()
- : first.equals(second));
- }
-
- @Override
- public Compare negate() {
- return neq;
- }
- }, neq {
- @Override
- public boolean test(final Object first, final Object second) {
- return !eq.test(first, second);
- }
-
- @Override
- public Compare negate() {
- return eq;
- }
- }, gt {
- @Override
- public boolean test(final Object first, final Object second) {
- return null != first && null != second && (
- first instanceof Number && second instanceof Number && !first.getClass().equals(second.getClass())
- ? ((Number) first).doubleValue() > ((Number) second).doubleValue()
- : ((Comparable) first).compareTo(second) > 0);
- }
-
- @Override
- public Compare negate() {
- return lte;
- }
- }, gte {
- @Override
- public boolean test(final Object first, final Object second) {
- return null == first ? null == second : (null != second && !lt.test(first, second));
- }
-
- @Override
- public Compare negate() {
- return lt;
- }
- }, lt {
- @Override
- public boolean test(final Object first, final Object second) {
- return null != first && null != second && (
- first instanceof Number && second instanceof Number && !first.getClass().equals(second.getClass())
- ? ((Number) first).doubleValue() < ((Number) second).doubleValue()
- : ((Comparable) first).compareTo(second) < 0);
- }
-
- @Override
- public Compare negate() {
- return gte;
- }
- }, lte {
- @Override
- public boolean test(final Object first, final Object second) {
- return null == first ? null == second : (null != second && !gt.test(first, second));
- }
-
- @Override
- public Compare negate() {
- return gt;
- }
- };
-
- /**
- * {@inheritDoc}
- */
- /*@Override
- public abstract boolean test(final Object first, final Object second);*/
-
- /**
- * Produce the opposite representation of the current {@code Compare} enum.
- */
- @Override
- public abstract Compare negate();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Contains.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Contains.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Contains.java
deleted file mode 100644
index 43c31ff..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Contains.java
+++ /dev/null
@@ -1,64 +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.structure;
-
-import java.util.Collection;
-import java.util.function.BiPredicate;
-
-/**
- * {@link Contains} is a {@link java.util.function.BiPredicate} that evaluates whether the first object is contained within (or not
- * within) the second collection object. For example:
- * <p/>
- * <pre>
- * gremlin Contains.within [gremlin, blueprints, furnace] == true
- * gremlin Contains.without [gremlin, rexster] == false
- * rexster Contains.without [gremlin, blueprints, furnace] == true
- * </pre>
- *
- * @author Pierre De Wilde
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public enum Contains implements BiPredicate<Object, Collection> {
-
- within {
- @Override
- public boolean test(final Object first, final Collection second) {
- return second.contains(first);
- }
- }, without {
- @Override
- public boolean test(final Object first, final Collection second) {
- return !second.contains(first);
- }
- };
-
- /**
- * {@inheritDoc}
- */
- @Override
- public abstract boolean test(final Object first, final Collection second);
-
- /**
- * Produce the opposite representation of the current {@code Contains} enum.
- */
- @Override
- public Contains negate() {
- return this.equals(within) ? without : within;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Operator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Operator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Operator.java
deleted file mode 100644
index 4fc8c64..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Operator.java
+++ /dev/null
@@ -1,125 +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.structure;
-
-import java.util.function.BinaryOperator;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public enum Operator implements BinaryOperator<Number> {
-
-
- sum {
- public Number apply(final Number a, final Number b) {
- final Class<? extends Number> numberClass = a.getClass();
- if (numberClass.equals(Integer.class)) {
- return a.intValue() + b.intValue();
- } else if (numberClass.equals(Long.class)) {
- return a.longValue() + b.longValue();
- } else if (numberClass.equals(Float.class)) {
- return a.floatValue() + b.floatValue();
- } else if (numberClass.equals(Double.class)) {
- return a.doubleValue() + b.doubleValue();
- } else {
- throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
- }
- }
- },
- minus {
- public Number apply(final Number a, final Number b) {
- final Class<? extends Number> numberClass = a.getClass();
- if (numberClass.equals(Integer.class)) {
- return a.intValue() - b.intValue();
- } else if (numberClass.equals(Long.class)) {
- return a.longValue() - b.longValue();
- } else if (numberClass.equals(Float.class)) {
- return a.floatValue() - b.floatValue();
- } else if (numberClass.equals(Double.class)) {
- return a.doubleValue() - b.doubleValue();
- } else {
- throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
- }
- }
- },
- mult {
- public Number apply(final Number a, final Number b) {
- final Class<? extends Number> numberClass = a.getClass();
- if (numberClass.equals(Integer.class)) {
- return a.intValue() * b.intValue();
- } else if (numberClass.equals(Long.class)) {
- return a.longValue() * b.longValue();
- } else if (numberClass.equals(Float.class)) {
- return a.floatValue() * b.floatValue();
- } else if (numberClass.equals(Double.class)) {
- return a.doubleValue() * b.doubleValue();
- } else {
- throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
- }
- }
- },
- div {
- public Number apply(final Number a, final Number b) {
- final Class<? extends Number> numberClass = a.getClass();
- if (numberClass.equals(Integer.class)) {
- return a.intValue() / b.intValue();
- } else if (numberClass.equals(Long.class)) {
- return a.longValue() / b.longValue();
- } else if (numberClass.equals(Float.class)) {
- return a.floatValue() / b.floatValue();
- } else if (numberClass.equals(Double.class)) {
- return a.doubleValue() / b.doubleValue();
- } else {
- throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
- }
- }
- },
- min {
- public Number apply(final Number a, final Number b) {
- final Class<? extends Number> numberClass = a.getClass();
- if (numberClass.equals(Integer.class)) {
- return Math.min(a.intValue(), b.intValue());
- } else if (numberClass.equals(Long.class)) {
- return Math.min(a.longValue(), b.longValue());
- } else if (numberClass.equals(Float.class)) {
- return Math.min(a.floatValue(), b.floatValue());
- } else if (numberClass.equals(Double.class)) {
- return Math.min(a.doubleValue(), b.doubleValue());
- } else {
- throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
- }
- }
- },
- max {
- public Number apply(final Number a, final Number b) {
- final Class<? extends Number> numberClass = a.getClass();
- if (numberClass.equals(Integer.class)) {
- return Math.max(a.intValue(), b.intValue());
- } else if (numberClass.equals(Long.class)) {
- return Math.max(a.longValue(), b.longValue());
- } else if (numberClass.equals(Float.class)) {
- return Math.max(a.floatValue(), b.floatValue());
- } else if (numberClass.equals(Double.class)) {
- return Math.max(a.doubleValue(), b.doubleValue());
- } else {
- throw new IllegalArgumentException("This operator only supports int, long, float, or double: " + numberClass);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Order.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Order.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Order.java
deleted file mode 100644
index c2825e8..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Order.java
+++ /dev/null
@@ -1,114 +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.structure;
-
-import java.util.Comparator;
-import java.util.Map;
-import java.util.Random;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public enum Order implements Comparator<Object> {
-
- incr {
- @Override
- public int compare(final Object first, final Object second) {
- return Comparator.<Comparable>naturalOrder().compare((Comparable) first, (Comparable) second);
- }
-
- @Override
- public Order reversed() {
- return decr;
- }
- }, decr {
- @Override
- public int compare(final Object first, final Object second) {
- return Comparator.<Comparable>reverseOrder().compare((Comparable) first, (Comparable) second);
- }
-
- @Override
- public Order reversed() {
- return incr;
- }
- }, keyIncr {
- @Override
- public int compare(final Object first, final Object second) {
- return Comparator.<Comparable>naturalOrder().compare(((Map.Entry<Comparable, ?>) first).getKey(), ((Map.Entry<Comparable, ?>) second).getKey());
- }
-
- @Override
- public Order reversed() {
- return keyDecr;
- }
- }, valueIncr {
- @Override
- public int compare(final Object first, final Object second) {
- return Comparator.<Comparable>naturalOrder().compare(((Map.Entry<?, Comparable>) first).getValue(), ((Map.Entry<?, Comparable>) second).getValue());
- }
-
- @Override
- public Order reversed() {
- return valueDecr;
- }
- }, keyDecr {
- @Override
- public int compare(final Object first, final Object second) {
- return Comparator.<Comparable>reverseOrder().compare(((Map.Entry<Comparable, ?>) first).getKey(), ((Map.Entry<Comparable, ?>) second).getKey());
- }
-
- @Override
- public Order reversed() {
- return keyIncr;
- }
- }, valueDecr {
- @Override
- public int compare(final Object first, final Object second) {
- return Comparator.<Comparable>reverseOrder().compare(((Map.Entry<?, Comparable>) first).getValue(), ((Map.Entry<?, Comparable>) second).getValue());
- }
-
- @Override
- public Order reversed() {
- return valueIncr;
- }
- }, shuffle {
- @Override
- public int compare(final Object first, final Object second) {
- return RANDOM.nextBoolean() ? -1 : 1;
- }
-
- @Override
- public Order reversed() {
- return shuffle;
- }
- };
-
- private static final Random RANDOM = new Random();
-
- /**
- * {@inheritDoc}
- */
- public abstract int compare(final Object first, final Object second);
-
- /**
- * Produce the opposite representation of the current {@code Order} enum.
- */
- @Override
- public abstract Order reversed();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/P.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/P.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/P.java
deleted file mode 100644
index ad9e4dc..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/P.java
+++ /dev/null
@@ -1,187 +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.structure;
-
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.structure.util.AndP;
-import org.apache.tinkerpop.gremlin.structure.util.OrP;
-import org.apache.tinkerpop.gremlin.structure.util.TraversalP;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.function.BiPredicate;
-import java.util.function.Predicate;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class P<V> implements Predicate<V>, Serializable, Cloneable {
-
- protected BiPredicate<V, V> biPredicate;
- protected V value;
-
- public P(final BiPredicate<V, V> biPredicate, final V value) {
- this.value = value;
- this.biPredicate = biPredicate;
- }
-
- public BiPredicate<V, V> getBiPredicate() {
- return this.biPredicate;
- }
-
- public V getValue() {
- return this.value;
- }
-
- public void setValue(final V value) {
- this.value = value;
- }
-
- @Override
- public boolean test(final V testValue) {
- return this.biPredicate.test(testValue, this.value);
- }
-
- @Override
- public int hashCode() {
- return this.biPredicate.hashCode() + this.value.hashCode();
- }
-
- @Override
- public boolean equals(final Object other) {
- return other instanceof P &&
- ((P) other).getClass().equals(this.getClass()) &&
- ((P) other).getBiPredicate().equals(this.biPredicate) &&
- ((((P) other).getValue() == null && this.value == null) || ((P) other).getValue().equals(this.value));
- }
-
- @Override
- public String toString() {
- return null == this.value ? this.biPredicate.toString() : this.biPredicate.toString() + "(" + this.value + ")";
- }
-
- @Override
- public P<V> negate() {
- return new P<>(this.biPredicate.negate(), this.value);
- }
-
- public P<V> and(final Traversal<?, ?> traversal) {
- return this.and((Predicate) P.traversal(traversal));
- }
-
- public P<V> or(final Traversal<?, ?> traversal) {
- return this.or((Predicate) P.traversal(traversal));
- }
-
- @Override
- public P<V> and(final Predicate<? super V> predicate) {
- if (!(predicate instanceof P))
- throw new IllegalArgumentException("Only P predicates can be and'd together");
- return new AndP<>(this, (P<V>) predicate);
- }
-
- @Override
- public P<V> or(final Predicate<? super V> predicate) {
- if (!(predicate instanceof P))
- throw new IllegalArgumentException("Only P predicates can be or'd together");
- return new OrP<>(this, (P<V>) predicate);
- }
-
- public P<V> clone() {
- try {
- return (P<V>) super.clone();
- } catch (final CloneNotSupportedException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- //////////////// statics
-
- public static <V> P<V> eq(final V value) {
- return new P(Compare.eq, value);
- }
-
- public static <V> P<V> neq(final V value) {
- return new P(Compare.neq, value);
- }
-
- public static <V> P<V> lt(final V value) {
- return new P(Compare.lt, value);
- }
-
- public static <V> P<V> lte(final V value) {
- return new P(Compare.lte, value);
- }
-
- public static <V> P<V> gt(final V value) {
- return new P(Compare.gt, value);
- }
-
- public static <V> P<V> gte(final V value) {
- return new P(Compare.gte, value);
- }
-
- public static <V> P<V> inside(final V first, final V second) {
- return new AndP<>(new P(Compare.gt, first), new P(Compare.lt, second));
- }
-
- public static <V> P<V> outside(final V first, final V second) {
- return new AndP<>(new P(Compare.lt, first), new P(Compare.gt, second));
- }
-
- public static <V> P<V> between(final V first, final V second) {
- return new AndP<>(new P(Compare.gte, first), new P(Compare.lt, second));
- }
-
- public static <V> P<V> within(final V... values) {
- return P.within(Arrays.asList(values));
- }
-
- public static <V> P<V> within(final Collection<V> value) {
- return new P(Contains.within, value);
- }
-
- public static <V> P<V> without(final V... values) {
- return P.without(Arrays.asList(values));
- }
-
- public static <V> P<V> without(final Collection<V> value) {
- return new P(Contains.without, value);
- }
-
- public static <S, E> P<E> traversal(final Traversal<S, E> traversal) {
- return new TraversalP<>(traversal.asAdmin(), false);
- }
-
- public static <S, E> P<E> not(final Traversal<S, E> traversal) {
- return new TraversalP<>(traversal.asAdmin(), true);
- }
-
- public static P test(final BiPredicate biPredicate, final Object value) {
- return new P(biPredicate, value);
- }
-
- public static <V> P<V> not(final P<V> predicate) {
- return predicate.negate();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
index 0ba7911..bb36fbb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
@@ -31,7 +31,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSe
import org.apache.tinkerpop.gremlin.process.traversal.util.DependantMutableMetrics;
import org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics;
import org.apache.tinkerpop.gremlin.process.traversal.util.StandardTraversalMetrics;
-import org.apache.tinkerpop.gremlin.structure.Contains;
+import org.apache.tinkerpop.gremlin.process.traversal.Contains;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/cf93500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/AndP.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/AndP.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/AndP.java
deleted file mode 100644
index 316a898..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/AndP.java
+++ /dev/null
@@ -1,70 +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.structure.util;
-
-import org.apache.tinkerpop.gremlin.structure.P;
-
-import java.util.List;
-import java.util.function.Predicate;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class AndP<V> extends ConjunctionP<V> {
-
- public AndP(final P<V> predicate, final P<V>... predicates) {
- super(predicate, predicates);
- }
-
- protected AndP(final ConjunctionP<V> other) {
- super(other);
- }
-
- @Override
- public boolean test(final V v) {
- for (final P<V> predicate : this.predicates) {
- if (!predicate.test(v))
- return false;
- }
- return true;
- }
-
- @Override
- public P<V> and(final Predicate<? super V> predicate) {
- if (!(predicate instanceof P))
- throw new IllegalArgumentException("Only P predicates can be and'd together");
- this.predicates.add((P<V>) predicate); // TODO: clone and add?
- return this;
- }
-
- @Override
- public P<V> negate() {
- super.negate();
- final P[] arg2 = new P[this.predicates.size()-1];
- return new OrP(this.predicates.get(0), this.predicates.subList(1, this.predicates.size()).toArray(arg2));
- }
-
- @Override
- public String toString() {
- return "and(" + this.predicates + ")";
- }
-}