[
https://issues.apache.org/jira/browse/TINKERPOP-2558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18146991#comment-18146991
]
ASF GitHub Bot commented on TINKERPOP-2558:
-------------------------------------------
GumpacG commented on code in PR #3809:
URL: https://github.com/apache/tinkerpop/pull/3809#discussion_r4622638685
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GeoP.java:
##########
@@ -0,0 +1,405 @@
+/*
+ * 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.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
+import org.apache.tinkerpop.gremlin.structure.geo.Geometry;
+import org.apache.tinkerpop.gremlin.structure.geo.Model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Predefined {@code Predicate} values that filter {@link Geometry} values by
a spatial
+ * relationship, backed by the {@link Geo} predicates.
+ * <p>
+ * For {@code geoWithinDistance}, {@link #getValue()} is a two element list of
the geometry and the
+ * distance, in that order.
+ * <p>
+ * An argument may instead come from a child traversal, which is resolved
against each traverser.
+ * {@code geoWithinDistance} then holds a child traversal for each of its two
arguments, and a
+ * constant given beside a traversal is carried as a constant traversal. An
argument may also be a
+ * {@link GValue}, whose value is resolved when the traversal is built.
+ * <p>
+ * <b>Accuracy in the geographic model.</b> Distances are measured on a sphere
of the WGS84 mean
+ * radius, within about 1% of WGS84. Edges are straight in longitude and
latitude, so the relate
+ * predicates, and distances between shapes other than two points, hold for
edges under about
+ * 100 km that cross neither the antimeridian nor a pole.
+ *
+ * @since 4.0.0
+ */
+public class GeoP extends P<Object> {
+
+ /**
+ * {@code geoWithinDistance}'s arguments as they were given, each either a
value or a
+ * {@link GValue}, so that the pair can be rebuilt when a variable takes a
new value. Null
+ * unless one of the arguments is a variable.
+ */
+ private final List<Object> arguments;
+
+ /**
+ * Constructs a {@code GeoP} from the argument as it was given, which is
validated unless it is
+ * a child traversal.
+ *
+ * @since 4.0.0
+ */
+ public GeoP(final PBiPredicate<Object, Object> biPredicate, final Object
value) {
+ super(biPredicate, value);
+ this.arguments = null;
+ if (!hasTraversal()) {
+ validateConstants(biPredicate, value);
+ }
+ }
+
+ /**
+ * Constructs a {@code GeoP} with a child traversal whose result is
resolved at runtime against
+ * the current traverser.
+ *
+ * @since 4.0.0
+ */
+ public GeoP(final PBiPredicate<Object, Object> biPredicate, final
Traversal.Admin<?, ?> traversalValue) {
+ super(biPredicate, traversalValue);
+ this.arguments = null;
+ }
+
+ /**
+ * Constructs a {@code GeoP} from a variable, whose value is validated
once it is resolved.
+ *
+ * @since 4.0.0
+ */
+ @SuppressWarnings("unchecked")
+ public GeoP(final PBiPredicate<Object, Object> biPredicate, final
GValue<?> value) {
+ super(biPredicate, (GValue<Object>) value);
+ this.arguments = null;
+ validateConstants(biPredicate, getValue());
+ }
+
+ /**
+ * Constructs a {@code GeoP} from arguments kept in the order they were
written, so that a
+ * variable among them stays bound to the argument it was given for.
+ */
+ private GeoP(final PBiPredicate<Object, Object> biPredicate, final
List<Object> arguments,
+ final Map<String, Object> variables) {
+ super(biPredicate,
Collections.<Object>singletonList(resolve(arguments, variables)), variables,
false);
+ this.arguments = Collections.unmodifiableList(new
ArrayList<>(arguments));
+ validateConstants(biPredicate, getValue());
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ return other instanceof GeoP && super.equals(other);
+ }
+
+ @Override
+ public P<Object> negate() {
+ return new NotP<>(this);
+ }
+
+ public GeoP clone() {
+ return (GeoP) super.clone();
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * A new value for one of this predicate's variables is validated as the
same value given to a
+ * constructor would be.
+ */
+ @Override
+ public void updateVariable(final String name, final Object value) {
+ super.updateVariable(name, value);
+ if (!variables.containsKey(name)) return;
+ if (null != arguments) {
+ literals = Collections.singletonList((Object) resolve(arguments,
variables));
+ }
+ if (!hasTraversal()) {
+ validateConstants(biPredicate, getValue());
+ }
+ }
+
+ //////////////// statics
+
+ /**
+ * Determines if a geometry lies entirely inside the given geometry. A
value that lies only on
+ * the given geometry's boundary is not within it.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoWithin(final Geometry value) {
+ return new GeoP(Geo.geoWithin, value);
+ }
+
+ /**
+ * Determines if a geometry lies entirely inside the geometry a variable
holds.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoWithin(final GValue<Geometry> value) {
+ return ofGeometry(Geo.geoWithin, value);
+ }
+
+ /**
+ * Determines if a geometry lies entirely inside the geometry resolved
from a child traversal
+ * at runtime.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoWithin(final Traversal<?, ?> traversalValue) {
+ return new GeoP(Geo.geoWithin, traversalValue.asAdmin());
+ }
+
+ /**
+ * Determines if a geometry entirely contains the given geometry. A
geometry does not contain a
+ * value that lies only on its boundary.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoContains(final Geometry value) {
+ return new GeoP(Geo.geoContains, value);
+ }
+
+ /**
+ * Determines if a geometry entirely contains the geometry a variable
holds.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoContains(final GValue<Geometry> value) {
+ return ofGeometry(Geo.geoContains, value);
+ }
+
+ /**
+ * Determines if a geometry entirely contains the geometry resolved from a
child traversal at
+ * runtime.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoContains(final Traversal<?, ?> traversalValue) {
+ return new GeoP(Geo.geoContains, traversalValue.asAdmin());
+ }
+
+ /**
+ * Determines if the distance between a geometry and the given geometry is
at most
+ * {@code distance}, in coordinate units for {@link Model#CARTESIAN} and
in meters for
+ * {@link Model#GEOGRAPHIC}.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoWithinDistance(final Geometry value, final Number
distance) {
+ return ofPair(value, distance);
+ }
+
+ /**
+ * Determines if the distance between a geometry and the geometry a
variable holds is at most
+ * {@code distance}.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoWithinDistance(final GValue<Geometry> value, final
Number distance) {
+ return ofPair(value, distance);
+ }
+
+ /**
+ * Determines if the distance between a geometry and the given geometry is
at most the distance
+ * a variable holds.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoWithinDistance(final Geometry value, final
GValue<Number> distance) {
+ return ofPair(value, distance);
+ }
+
+ /**
+ * Determines if the distance between a geometry and the geometry a
variable holds is at most
+ * the distance a variable holds.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoWithinDistance(final GValue<Geometry> value, final
GValue<Number> distance) {
+ return ofPair(value, distance);
+ }
+
+ /**
+ * Determines if the distance between a geometry and the geometry resolved
from a child
+ * traversal at runtime is at most {@code distance}.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoWithinDistance(final Traversal<?, ?> traversalValue,
final Number distance) {
+ validateDistance(Geo.geoWithinDistance.getPredicateName(), distance);
+ return new GeoP(Geo.geoWithinDistance,
Arrays.asList(traversalValue.asAdmin(), __.constant(distance)));
+ }
+
+ /**
+ * Determines if the distance between a geometry and the geometry resolved
from a child
+ * traversal at runtime is at most the distance a variable holds.
+ *
+ * @since 4.0.0
+ */
+ public static GeoP geoWithinDistance(final Traversal<?, ?> traversalValue,
final GValue<Number> distance) {
+ if (null == distance || !distance.isVariable()) {
+ return geoWithinDistance(traversalValue, null == distance ? null :
distance.get());
+ }
+ validateDistance(Geo.geoWithinDistance.getPredicateName(),
distance.get());
+ return new GeoP(Geo.geoWithinDistance,
Arrays.asList(traversalValue.asAdmin(), __.constant(distance)));
Review Comment:
As discussed offline, `geoWithinDistance` is deferred to the full predicates
implementation. This issue will be resolved then.
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GeoP.java:
##########
@@ -0,0 +1,405 @@
+/*
+ * 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.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
+import org.apache.tinkerpop.gremlin.structure.geo.Geometry;
+import org.apache.tinkerpop.gremlin.structure.geo.Model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Predefined {@code Predicate} values that filter {@link Geometry} values by
a spatial
+ * relationship, backed by the {@link Geo} predicates.
+ * <p>
+ * For {@code geoWithinDistance}, {@link #getValue()} is a two element list of
the geometry and the
+ * distance, in that order.
+ * <p>
+ * An argument may instead come from a child traversal, which is resolved
against each traverser.
+ * {@code geoWithinDistance} then holds a child traversal for each of its two
arguments, and a
+ * constant given beside a traversal is carried as a constant traversal. An
argument may also be a
+ * {@link GValue}, whose value is resolved when the traversal is built.
+ * <p>
+ * <b>Accuracy in the geographic model.</b> Distances are measured on a sphere
of the WGS84 mean
+ * radius, within about 1% of WGS84. Edges are straight in longitude and
latitude, so the relate
+ * predicates, and distances between shapes other than two points, hold for
edges under about
+ * 100 km that cross neither the antimeridian nor a pole.
+ *
+ * @since 4.0.0
+ */
+public class GeoP extends P<Object> {
Review Comment:
As discussed offline, `geoWithinDistance` is deferred to the full predicates
implementation. This issue will be resolved then.
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GeoP.java:
##########
@@ -0,0 +1,405 @@
+/*
+ * 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.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
+import org.apache.tinkerpop.gremlin.structure.geo.Geometry;
+import org.apache.tinkerpop.gremlin.structure.geo.Model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Predefined {@code Predicate} values that filter {@link Geometry} values by
a spatial
+ * relationship, backed by the {@link Geo} predicates.
+ * <p>
+ * For {@code geoWithinDistance}, {@link #getValue()} is a two element list of
the geometry and the
+ * distance, in that order.
+ * <p>
+ * An argument may instead come from a child traversal, which is resolved
against each traverser.
+ * {@code geoWithinDistance} then holds a child traversal for each of its two
arguments, and a
+ * constant given beside a traversal is carried as a constant traversal. An
argument may also be a
+ * {@link GValue}, whose value is resolved when the traversal is built.
+ * <p>
+ * <b>Accuracy in the geographic model.</b> Distances are measured on a sphere
of the WGS84 mean
+ * radius, within about 1% of WGS84. Edges are straight in longitude and
latitude, so the relate
+ * predicates, and distances between shapes other than two points, hold for
edges under about
+ * 100 km that cross neither the antimeridian nor a pole.
+ *
+ * @since 4.0.0
+ */
+public class GeoP extends P<Object> {
+
+ /**
+ * {@code geoWithinDistance}'s arguments as they were given, each either a
value or a
+ * {@link GValue}, so that the pair can be rebuilt when a variable takes a
new value. Null
+ * unless one of the arguments is a variable.
+ */
+ private final List<Object> arguments;
+
+ /**
+ * Constructs a {@code GeoP} from the argument as it was given, which is
validated unless it is
+ * a child traversal.
+ *
+ * @since 4.0.0
+ */
+ public GeoP(final PBiPredicate<Object, Object> biPredicate, final Object
value) {
+ super(biPredicate, value);
+ this.arguments = null;
+ if (!hasTraversal()) {
+ validateConstants(biPredicate, value);
+ }
+ }
+
+ /**
+ * Constructs a {@code GeoP} with a child traversal whose result is
resolved at runtime against
+ * the current traverser.
+ *
+ * @since 4.0.0
+ */
+ public GeoP(final PBiPredicate<Object, Object> biPredicate, final
Traversal.Admin<?, ?> traversalValue) {
+ super(biPredicate, traversalValue);
+ this.arguments = null;
+ }
+
+ /**
+ * Constructs a {@code GeoP} from a variable, whose value is validated
once it is resolved.
+ *
+ * @since 4.0.0
+ */
+ @SuppressWarnings("unchecked")
+ public GeoP(final PBiPredicate<Object, Object> biPredicate, final
GValue<?> value) {
+ super(biPredicate, (GValue<Object>) value);
+ this.arguments = null;
+ validateConstants(biPredicate, getValue());
+ }
+
+ /**
+ * Constructs a {@code GeoP} from arguments kept in the order they were
written, so that a
+ * variable among them stays bound to the argument it was given for.
+ */
+ private GeoP(final PBiPredicate<Object, Object> biPredicate, final
List<Object> arguments,
+ final Map<String, Object> variables) {
+ super(biPredicate,
Collections.<Object>singletonList(resolve(arguments, variables)), variables,
false);
+ this.arguments = Collections.unmodifiableList(new
ArrayList<>(arguments));
+ validateConstants(biPredicate, getValue());
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ return other instanceof GeoP && super.equals(other);
+ }
+
+ @Override
+ public P<Object> negate() {
+ return new NotP<>(this);
+ }
+
+ public GeoP clone() {
+ return (GeoP) super.clone();
Review Comment:
Fixed, clone() now copies variables, and shouldCloneWithTheSameArguments
covers it.
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/GeoP.java:
##########
@@ -0,0 +1,405 @@
+/*
+ * 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.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.GValue;
+import org.apache.tinkerpop.gremlin.structure.geo.Geometry;
+import org.apache.tinkerpop.gremlin.structure.geo.Model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Predefined {@code Predicate} values that filter {@link Geometry} values by
a spatial
+ * relationship, backed by the {@link Geo} predicates.
+ * <p>
+ * For {@code geoWithinDistance}, {@link #getValue()} is a two element list of
the geometry and the
+ * distance, in that order.
+ * <p>
+ * An argument may instead come from a child traversal, which is resolved
against each traverser.
+ * {@code geoWithinDistance} then holds a child traversal for each of its two
arguments, and a
+ * constant given beside a traversal is carried as a constant traversal. An
argument may also be a
+ * {@link GValue}, whose value is resolved when the traversal is built.
+ * <p>
+ * <b>Accuracy in the geographic model.</b> Distances are measured on a sphere
of the WGS84 mean
+ * radius, within about 1% of WGS84. Edges are straight in longitude and
latitude, so the relate
+ * predicates, and distances between shapes other than two points, hold for
edges under about
+ * 100 km that cross neither the antimeridian nor a pole.
+ *
+ * @since 4.0.0
+ */
+public class GeoP extends P<Object> {
+
+ /**
+ * {@code geoWithinDistance}'s arguments as they were given, each either a
value or a
+ * {@link GValue}, so that the pair can be rebuilt when a variable takes a
new value. Null
+ * unless one of the arguments is a variable.
+ */
+ private final List<Object> arguments;
+
+ /**
+ * Constructs a {@code GeoP} from the argument as it was given, which is
validated unless it is
+ * a child traversal.
+ *
+ * @since 4.0.0
+ */
+ public GeoP(final PBiPredicate<Object, Object> biPredicate, final Object
value) {
+ super(biPredicate, value);
+ this.arguments = null;
+ if (!hasTraversal()) {
+ validateConstants(biPredicate, value);
+ }
+ }
+
+ /**
+ * Constructs a {@code GeoP} with a child traversal whose result is
resolved at runtime against
+ * the current traverser.
+ *
+ * @since 4.0.0
+ */
+ public GeoP(final PBiPredicate<Object, Object> biPredicate, final
Traversal.Admin<?, ?> traversalValue) {
+ super(biPredicate, traversalValue);
+ this.arguments = null;
+ }
+
+ /**
+ * Constructs a {@code GeoP} from a variable, whose value is validated
once it is resolved.
+ *
+ * @since 4.0.0
+ */
+ @SuppressWarnings("unchecked")
+ public GeoP(final PBiPredicate<Object, Object> biPredicate, final
GValue<?> value) {
+ super(biPredicate, (GValue<Object>) value);
+ this.arguments = null;
+ validateConstants(biPredicate, getValue());
+ }
+
+ /**
+ * Constructs a {@code GeoP} from arguments kept in the order they were
written, so that a
+ * variable among them stays bound to the argument it was given for.
+ */
+ private GeoP(final PBiPredicate<Object, Object> biPredicate, final
List<Object> arguments,
+ final Map<String, Object> variables) {
+ super(biPredicate,
Collections.<Object>singletonList(resolve(arguments, variables)), variables,
false);
+ this.arguments = Collections.unmodifiableList(new
ArrayList<>(arguments));
+ validateConstants(biPredicate, getValue());
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ return other instanceof GeoP && super.equals(other);
+ }
+
+ @Override
+ public P<Object> negate() {
+ return new NotP<>(this);
+ }
+
+ public GeoP clone() {
+ return (GeoP) super.clone();
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * A new value for one of this predicate's variables is validated as the
same value given to a
+ * constructor would be.
+ */
+ @Override
+ public void updateVariable(final String name, final Object value) {
+ super.updateVariable(name, value);
Review Comment:
Fixed, updateVariable validates the new value before keeping it.
> GEO Spatial APIs
> ----------------
>
> Key: TINKERPOP-2558
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2558
> Project: TinkerPop
> Issue Type: Improvement
> Components: process
> Affects Versions: 3.5.0
> Reporter: Jitesh
> Priority: Major
>
> Provide support for Geo based APIs (predicates, objects, etc)
>
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)