From commits-return-27137-archive-asf-public=cust-asf.ponee.io@tinkerpop.apache.org Tue Mar 13 23:53:32 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id D1AB618064F for ; Tue, 13 Mar 2018 23:53:29 +0100 (CET) Received: (qmail 61812 invoked by uid 500); 13 Mar 2018 22:53:28 -0000 Mailing-List: contact commits-help@tinkerpop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.apache.org Delivered-To: mailing list commits@tinkerpop.apache.org Received: (qmail 61803 invoked by uid 99); 13 Mar 2018 22:53:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Mar 2018 22:53:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C4CE6ED499; Tue, 13 Mar 2018 22:53:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: florianhockmann@apache.org To: commits@tinkerpop.apache.org Date: Tue, 13 Mar 2018 22:53:28 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [01/10] tinkerpop git commit: TINKERPOP-1919 Merge classes P and TraversalPredicate Repository: tinkerpop Updated Branches: refs/heads/master 5ae66ed94 -> 3e00a6402 refs/heads/tp32 504933975 -> 5cf1cba59 refs/heads/tp33 2d493fb3c -> 9bd4d7fed TINKERPOP-1919 Merge classes P and TraversalPredicate There is no good reason to keep those two classes separate anymore and having P as the type for step parameters is probably easier to understand for users than TraversalPredicate. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/359b08cc Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/359b08cc Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/359b08cc Branch: refs/heads/master Commit: 359b08cc79ed89cab1fbc4e2b0b69b94a4e9cd06 Parents: 5049339 Author: Florian Hockmann Authored: Mon Mar 12 21:16:18 2018 +0100 Committer: Florian Hockmann Committed: Tue Mar 13 22:12:31 2018 +0100 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + gremlin-dotnet/glv/P.template | 62 ++++++++++- gremlin-dotnet/glv/generate.groovy | 2 +- .../Process/Traversal/GraphTraversal.cs | 20 ++-- .../src/Gremlin.Net/Process/Traversal/P.cs | 106 ++++++++++++++----- .../Process/Traversal/TraversalPredicate.cs | 85 --------------- .../src/Gremlin.Net/Process/Traversal/__.cs | 20 ++-- .../Structure/IO/GraphSON/GraphSONWriter.cs | 2 +- .../Structure/IO/GraphSON/PSerializer.cs | 45 ++++++++ .../IO/GraphSON/TraversalPredicateSerializer.cs | 45 -------- .../Gherkin/GherkinTestRunner.cs | 18 +--- .../Gherkin/IgnoreException.cs | 5 - .../Gherkin/TraversalEvaluation/PParameter.cs | 97 +++++++++++++++++ .../TraversalEvaluationTests.cs | 2 +- .../TraversalEvaluation/TraversalParser.cs | 2 +- .../TraversalPredicateParameter.cs | 93 ---------------- .../GraphSON/BytecodeGraphSONSerializerTests.cs | 2 +- .../IO/GraphSON/GraphSONWriterTests.cs | 4 +- 18 files changed, 311 insertions(+), 300 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 58c4dd0..97b90a5 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -43,6 +43,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima * Fixed a bug in Gremlin Console which prevented handling of `gremlin.sh` flags that had an "=" between the flag and its arguments. * Fixed bug where `SparkMessenger` was not applying the `edgeFunction` from `MessageScope`. * Fixed a bug in `ComputerAwareStep` that didn't handle `reset()` properly and thus occasionally produced some extra traversers. +* Removed `TraversalPredicate` class in Gremlin.Net. It is now included in the `P` class instead. [[release-3-2-7]] === TinkerPop 3.2.7 (Release Date: December 17, 2017) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/glv/P.template ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/glv/P.template b/gremlin-dotnet/glv/P.template index f337127..ad037c1 100644 --- a/gremlin-dotnet/glv/P.template +++ b/gremlin-dotnet/glv/P.template @@ -30,20 +30,72 @@ namespace Gremlin.Net.Process.Traversal /// A is a predicate of the form Func<object, bool>. /// That is, given some object, return true or false. /// - public class P + public class P : IPredicate { + /// + /// Initializes a new instance of the class. + /// + /// The name of the predicate. + /// The value of the predicate. + /// An optional other predicate that is used as an argument for this predicate. + public P(string operatorName, dynamic value, P other = null) + { + OperatorName = operatorName; + Value = value; + Other = other; + } + + /// + /// Gets the name of the predicate. + /// + public string OperatorName { get; } + + /// + /// Gets the value of the predicate. + /// + public dynamic Value { get; } + + /// + /// Gets an optional other predicate that is used as an argument for this predicate. + /// + public P Other { get; } + + /// + /// Returns a composed predicate that represents a logical AND of this predicate and another. + /// + /// A predicate that will be logically-ANDed with this predicate. + /// The composed predicate. + public P And(P otherPredicate) + { + return new P("and", this, otherPredicate); + } + + /// + /// Returns a composed predicate that represents a logical OR of this predicate and another. + /// + /// A predicate that will be logically-ORed with this predicate. + /// The composed predicate. + public P Or(P otherPredicate) + { + return new P("or", this, otherPredicate); + } <% pmethods.findAll{ !(it in ["within", "without"]) }.each { method -> %> - public static TraversalPredicate <%= toCSharpMethodName.call(method) %>(params object[] args) + public static P <%= toCSharpMethodName.call(method) %>(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("<%= method %>", value); + return new P("<%= method %>", value); } <% } %><% pmethods.findAll{ it in ["within", "without"] }.each { method -> %> - public static TraversalPredicate <%= toCSharpMethodName.call(method) %>(params object[] args) + public static P <%= toCSharpMethodName.call(method) %>(params object[] args) { - return new TraversalPredicate("<%= method %>", args); + return new P("<%= method %>", args); } <% } %> + /// + public override string ToString() + { + return Other == null ? \$"{OperatorName}({Value})" : \$"{OperatorName}({Value},{Other})"; + } } #pragma warning restore 1591 http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/glv/generate.groovy ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/glv/generate.groovy b/gremlin-dotnet/glv/generate.groovy index 0404307..5057ff8 100644 --- a/gremlin-dotnet/glv/generate.groovy +++ b/gremlin-dotnet/glv/generate.groovy @@ -49,7 +49,7 @@ def toCSharpTypeMap = ["Long": "long", "Traversal": "ITraversal", "Traversal[]": "ITraversal[]", "Predicate": "IPredicate", - "P": "TraversalPredicate", + "P": "P", "TraversalStrategy": "ITraversalStrategy", "TraversalStrategy[]": "ITraversalStrategy[]", "Function": "IFunction", http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs index 7100ea3..c8708df 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs @@ -667,7 +667,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the has step to this . /// - public GraphTraversal Has (string propertyKey, TraversalPredicate predicate) + public GraphTraversal Has (string propertyKey, P predicate) { Bytecode.AddStep("has", propertyKey, predicate); return Wrap(this); @@ -685,7 +685,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the has step to this . /// - public GraphTraversal Has (string label, string propertyKey, TraversalPredicate predicate) + public GraphTraversal Has (string label, string propertyKey, P predicate) { Bytecode.AddStep("has", label, propertyKey, predicate); return Wrap(this); @@ -712,7 +712,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the has step to this . /// - public GraphTraversal Has (T accessor, TraversalPredicate predicate) + public GraphTraversal Has (T accessor, P predicate) { Bytecode.AddStep("has", accessor, predicate); return Wrap(this); @@ -741,7 +741,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the hasId step to this . /// - public GraphTraversal HasId (TraversalPredicate predicate) + public GraphTraversal HasId (P predicate) { Bytecode.AddStep("hasId", predicate); return Wrap(this); @@ -750,7 +750,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the hasKey step to this . /// - public GraphTraversal HasKey (TraversalPredicate predicate) + public GraphTraversal HasKey (P predicate) { Bytecode.AddStep("hasKey", predicate); return Wrap(this); @@ -770,7 +770,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the hasLabel step to this . /// - public GraphTraversal HasLabel (TraversalPredicate predicate) + public GraphTraversal HasLabel (P predicate) { Bytecode.AddStep("hasLabel", predicate); return Wrap(this); @@ -810,7 +810,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the hasValue step to this . /// - public GraphTraversal HasValue (TraversalPredicate predicate) + public GraphTraversal HasValue (P predicate) { Bytecode.AddStep("hasValue", predicate); return Wrap(this); @@ -888,7 +888,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the is step to this . /// - public GraphTraversal Is (TraversalPredicate predicate) + public GraphTraversal Is (P predicate) { Bytecode.AddStep("is", predicate); return Wrap(this); @@ -1660,7 +1660,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the where step to this . /// - public GraphTraversal Where (TraversalPredicate predicate) + public GraphTraversal Where (P predicate) { Bytecode.AddStep("where", predicate); return Wrap(this); @@ -1669,7 +1669,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Adds the where step to this . /// - public GraphTraversal Where (string startKey, TraversalPredicate predicate) + public GraphTraversal Where (string startKey, P predicate) { Bytecode.AddStep("where", startKey, predicate); return Wrap(this); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/P.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/P.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/P.cs index 0a7809f..e3a1e76 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/P.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/P.cs @@ -30,85 +30,137 @@ namespace Gremlin.Net.Process.Traversal /// A is a predicate of the form Func<object, bool>. /// That is, given some object, return true or false. /// - public class P + public class P : IPredicate { + /// + /// Initializes a new instance of the class. + /// + /// The name of the predicate. + /// The value of the predicate. + /// An optional other predicate that is used as an argument for this predicate. + public P(string operatorName, dynamic value, P other = null) + { + OperatorName = operatorName; + Value = value; + Other = other; + } + + /// + /// Gets the name of the predicate. + /// + public string OperatorName { get; } + + /// + /// Gets the value of the predicate. + /// + public dynamic Value { get; } + + /// + /// Gets an optional other predicate that is used as an argument for this predicate. + /// + public P Other { get; } + + /// + /// Returns a composed predicate that represents a logical AND of this predicate and another. + /// + /// A predicate that will be logically-ANDed with this predicate. + /// The composed predicate. + public P And(P otherPredicate) + { + return new P("and", this, otherPredicate); + } - public static TraversalPredicate Between(params object[] args) + /// + /// Returns a composed predicate that represents a logical OR of this predicate and another. + /// + /// A predicate that will be logically-ORed with this predicate. + /// The composed predicate. + public P Or(P otherPredicate) + { + return new P("or", this, otherPredicate); + } + + public static P Between(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("between", value); + return new P("between", value); } - public static TraversalPredicate Eq(params object[] args) + public static P Eq(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("eq", value); + return new P("eq", value); } - public static TraversalPredicate Gt(params object[] args) + public static P Gt(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("gt", value); + return new P("gt", value); } - public static TraversalPredicate Gte(params object[] args) + public static P Gte(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("gte", value); + return new P("gte", value); } - public static TraversalPredicate Inside(params object[] args) + public static P Inside(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("inside", value); + return new P("inside", value); } - public static TraversalPredicate Lt(params object[] args) + public static P Lt(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("lt", value); + return new P("lt", value); } - public static TraversalPredicate Lte(params object[] args) + public static P Lte(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("lte", value); + return new P("lte", value); } - public static TraversalPredicate Neq(params object[] args) + public static P Neq(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("neq", value); + return new P("neq", value); } - public static TraversalPredicate Not(params object[] args) + public static P Not(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("not", value); + return new P("not", value); } - public static TraversalPredicate Outside(params object[] args) + public static P Outside(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("outside", value); + return new P("outside", value); } - public static TraversalPredicate Test(params object[] args) + public static P Test(params object[] args) { var value = args.Length == 1 ? args[0] : args; - return new TraversalPredicate("test", value); + return new P("test", value); } - public static TraversalPredicate Within(params object[] args) + public static P Within(params object[] args) { - return new TraversalPredicate("within", args); + return new P("within", args); } - public static TraversalPredicate Without(params object[] args) + public static P Without(params object[] args) { - return new TraversalPredicate("without", args); + return new P("without", args); } + /// + public override string ToString() + { + return Other == null ? $"{OperatorName}({Value})" : $"{OperatorName}({Value},{Other})"; + } } #pragma warning restore 1591 http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/TraversalPredicate.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/TraversalPredicate.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/TraversalPredicate.cs deleted file mode 100644 index e8b5be8..0000000 --- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/TraversalPredicate.cs +++ /dev/null @@ -1,85 +0,0 @@ -#region License - -/* - * 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. - */ - -#endregion - -namespace Gremlin.Net.Process.Traversal -{ - /// - /// Represents a predicate (boolean-valued function) used in a . - /// - public class TraversalPredicate : IPredicate - { - /// - /// Initializes a new instance of the class. - /// - /// The name of the predicate. - /// The value of the predicate. - /// An optional other predicate that is used as an argument for this predicate. - public TraversalPredicate(string operatorName, dynamic value, TraversalPredicate other = null) - { - OperatorName = operatorName; - Value = value; - Other = other; - } - - /// - /// Gets the name of the predicate. - /// - public string OperatorName { get; } - - /// - /// Gets the value of the predicate. - /// - public dynamic Value { get; } - - /// - /// Gets an optional other predicate that is used as an argument for this predicate. - /// - public TraversalPredicate Other { get; } - - /// - /// Returns a composed predicate that represents a logical AND of this predicate and another. - /// - /// A predicate that will be logically-ANDed with this predicate. - /// The composed predicate. - public TraversalPredicate And(TraversalPredicate otherPredicate) - { - return new TraversalPredicate("and", this, otherPredicate); - } - - /// - /// Returns a composed predicate that represents a logical OR of this predicate and another. - /// - /// A predicate that will be logically-ORed with this predicate. - /// The composed predicate. - public TraversalPredicate Or(TraversalPredicate otherPredicate) - { - return new TraversalPredicate("or", this, otherPredicate); - } - - /// - public override string ToString() - { - return Other == null ? $"{OperatorName}({Value})" : $"{OperatorName}({Value},{Other})"; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs index 9620e7f..46f510a 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/__.cs @@ -485,7 +485,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the has step to that traversal. /// - public static GraphTraversal Has(string propertyKey, TraversalPredicate predicate) + public static GraphTraversal Has(string propertyKey, P predicate) { return new GraphTraversal().Has(propertyKey, predicate); } @@ -501,7 +501,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the has step to that traversal. /// - public static GraphTraversal Has(string label, string propertyKey, TraversalPredicate predicate) + public static GraphTraversal Has(string label, string propertyKey, P predicate) { return new GraphTraversal().Has(label, propertyKey, predicate); } @@ -525,7 +525,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the has step to that traversal. /// - public static GraphTraversal Has(T accessor, TraversalPredicate predicate) + public static GraphTraversal Has(T accessor, P predicate) { return new GraphTraversal().Has(accessor, predicate); } @@ -551,7 +551,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the hasId step to that traversal. /// - public static GraphTraversal HasId(TraversalPredicate predicate) + public static GraphTraversal HasId(P predicate) { return new GraphTraversal().HasId(predicate); } @@ -559,7 +559,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the hasKey step to that traversal. /// - public static GraphTraversal HasKey(TraversalPredicate predicate) + public static GraphTraversal HasKey(P predicate) { return new GraphTraversal().HasKey(predicate); } @@ -577,7 +577,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the hasLabel step to that traversal. /// - public static GraphTraversal HasLabel(TraversalPredicate predicate) + public static GraphTraversal HasLabel(P predicate) { return new GraphTraversal().HasLabel(predicate); } @@ -613,7 +613,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the hasValue step to that traversal. /// - public static GraphTraversal HasValue(TraversalPredicate predicate) + public static GraphTraversal HasValue(P predicate) { return new GraphTraversal().HasValue(predicate); } @@ -683,7 +683,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the is step to that traversal. /// - public static GraphTraversal Is(TraversalPredicate predicate) + public static GraphTraversal Is(P predicate) { return new GraphTraversal().Is(predicate); } @@ -1293,7 +1293,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the where step to that traversal. /// - public static GraphTraversal Where(TraversalPredicate predicate) + public static GraphTraversal Where(P predicate) { return new GraphTraversal().Where(predicate); } @@ -1301,7 +1301,7 @@ namespace Gremlin.Net.Process.Traversal /// /// Spawns a and adds the where step to that traversal. /// - public static GraphTraversal Where(string startKey, TraversalPredicate predicate) + public static GraphTraversal Where(string startKey, P predicate) { return new GraphTraversal().Where(startKey, predicate); } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs index d5b7acc..f23d80d 100644 --- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONWriter.cs @@ -54,7 +54,7 @@ namespace Gremlin.Net.Structure.IO.GraphSON {typeof(DateTimeOffset), new DateSerializer()}, {typeof(Type), new ClassSerializer()}, {typeof(EnumWrapper), new EnumSerializer()}, - {typeof(TraversalPredicate), new TraversalPredicateSerializer()}, + {typeof(P), new PSerializer()}, {typeof(Vertex), new VertexSerializer()}, {typeof(Edge), new EdgeSerializer()}, {typeof(Property), new PropertySerializer()}, http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/PSerializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/PSerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/PSerializer.cs new file mode 100644 index 0000000..46facda --- /dev/null +++ b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/PSerializer.cs @@ -0,0 +1,45 @@ +#region License + +/* + * 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. + */ + +#endregion + +using System.Collections.Generic; +using Gremlin.Net.Process.Traversal; + +namespace Gremlin.Net.Structure.IO.GraphSON +{ + internal class PSerializer : IGraphSONSerializer + { + public Dictionary Dictify(dynamic predicate, GraphSONWriter writer) + { + P p = predicate; + var value = p.Other == null + ? writer.ToDict(p.Value) + : new List {writer.ToDict(p.Value), writer.ToDict(p.Other)}; + var dict = new Dictionary + { + {"predicate", p.OperatorName}, + {"value", value} + }; + return GraphSONUtil.ToTypedValue("P", dict); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalPredicateSerializer.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalPredicateSerializer.cs b/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalPredicateSerializer.cs deleted file mode 100644 index 937cb90..0000000 --- a/gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/TraversalPredicateSerializer.cs +++ /dev/null @@ -1,45 +0,0 @@ -#region License - -/* - * 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. - */ - -#endregion - -using System.Collections.Generic; -using Gremlin.Net.Process.Traversal; - -namespace Gremlin.Net.Structure.IO.GraphSON -{ - internal class TraversalPredicateSerializer : IGraphSONSerializer - { - public Dictionary Dictify(dynamic predicate, GraphSONWriter writer) - { - TraversalPredicate p = predicate; - var value = p.Other == null - ? writer.ToDict(p.Value) - : new List {writer.ToDict(p.Value), writer.ToDict(p.Other)}; - var dict = new Dictionary - { - {"predicate", p.OperatorName}, - {"value", value} - }; - return GraphSONUtil.ToTypedValue("P", dict); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs index d906357..c3819fe 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs @@ -43,23 +43,15 @@ namespace Gremlin.Net.IntegrationTest.Gherkin {"g_V_hasIdXwithinXemptyXX_count", IgnoreReason.PWithinWrapsArgumentsInArray}, {"g_VX1X_out_aggregateXxX_out_whereXnotXwithinXaXXX", IgnoreReason.PWithinWrapsArgumentsInArray}, { - "g_V_hasLabelXpersonX_hasXage_notXlteX10X_andXnotXbetweenX11_20XXXX_andXltX29X_orXeqX35XXXX_name", - IgnoreReason.PNotCreatedCorrectlyByGherkinRunner - }, - { - "g_V_asXaX_outXcreatedX_asXbX_inXcreatedX_asXcX_bothXknowsX_bothXknowsX_asXdX_whereXc__notXeqXaX_orXeqXdXXXX_selectXa_b_c_dX", - IgnoreReason.PNotCreatedCorrectlyByGherkinRunner - }, - { - "g_V_asXaX_outEXcreatedX_asXbX_inV_asXcX_whereXa_gtXbX_orXeqXbXXX_byXageX_byXweightX_byXweightX_selectXa_cX_byXnameX", - IgnoreReason.PNotCreatedCorrectlyByGherkinRunner + "g_V_asXaX_out_asXbX_whereXandXasXaX_outXknowsX_asXbX__orXasXbX_outXcreatedX_hasXname_rippleX__asXbX_inXknowsX_count_isXnotXeqX0XXXXX_selectXa_bX", + IgnoreReason.PNotDeserializationProblem }, { - "g_V_asXaX_outEXcreatedX_asXbX_inV_asXcX_inXcreatedX_asXdX_whereXa_ltXbX_orXgtXcXX_andXneqXdXXX_byXageX_byXweightX_byXinXcreatedX_valuesXageX_minX_selectXa_c_dX", - IgnoreReason.PNotCreatedCorrectlyByGherkinRunner + "g_V_hasLabelXpersonX_hasXage_notXlteX10X_andXnotXbetweenX11_20XXXX_andXltX29X_orXeqX35XXXX_name", + IgnoreReason.PNotDeserializationProblem }, { - "g_V_asXaX_out_asXbX_whereXandXasXaX_outXknowsX_asXbX__orXasXbX_outXcreatedX_hasXname_rippleX__asXbX_inXknowsX_count_isXnotXeqX0XXXXX_selectXa_bX", + "g_V_asXaX_outXcreatedX_asXbX_inXcreatedX_asXcX_bothXknowsX_bothXknowsX_asXdX_whereXc__notXeqXaX_orXeqXdXXXX_selectXa_b_c_dX", IgnoreReason.PNotDeserializationProblem } }; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs index dae2ced..fd226bf 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs @@ -43,10 +43,6 @@ namespace Gremlin.Net.IntegrationTest.Gherkin case IgnoreReason.LambdaNotSupported: reasonSuffix = " because lambdas are not supported in Gremlin.NET (TINKERPOP-1854)"; break; - case IgnoreReason.PNotCreatedCorrectlyByGherkinRunner: - reasonSuffix = - " because the Gherkin runner can't call methods in TraversalPredicate class (TINKERPOP-1919)"; - break; case IgnoreReason.PWithinWrapsArgumentsInArray: reasonSuffix = " because P.Within() arguments are incorrectly wrapped in an array (TINKERPOP-1920)"; break; @@ -61,7 +57,6 @@ namespace Gremlin.Net.IntegrationTest.Gherkin public enum IgnoreReason { LambdaNotSupported, - PNotCreatedCorrectlyByGherkinRunner, PWithinWrapsArgumentsInArray, PNotDeserializationProblem } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/PParameter.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/PParameter.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/PParameter.cs new file mode 100644 index 0000000..b25faef --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/PParameter.cs @@ -0,0 +1,97 @@ +#region License + +/* + * 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. + */ + +#endregion + +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using System.Reflection; +using Gremlin.Net.Process.Traversal; + +namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation +{ + /// + /// Represents a parameter for a traversal predicate (ie: P.gt()) + /// + internal class PParameter : ITokenParameter, IEquatable + { + private IDictionary _contextParameterValues; + public IList Tokens { get; } + + public PParameter(IList tokens) + { + Tokens = tokens; + } + + public bool Equals(PParameter other) + { + return Tokens.SequenceEqual(other.Tokens); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((PParameter) obj); + } + + public override int GetHashCode() + { + return Tokens != null ? Tokens.GetHashCode() : 0; + } + + public object GetValue() + { + var type = typeof(P); + object instance = null; + for (var i = 1; i < Tokens.Count; i++) + { + var token = Tokens[i]; + token.SetContextParameterValues(_contextParameterValues); + var method = type.GetMethod(TraversalParser.GetCsharpName(token.Name), + BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public); + if (method == null) + { + throw new InvalidOperationException($"Predicate (P) method '{token}' not found for testing"); + } + + var parameters = method.IsStatic + ? new object[] {token.Parameters.Select(p => p.GetValue()).ToArray()} + : token.Parameters.Select(p => p.GetValue()).ToArray(); + instance = method.Invoke(instance, parameters); + } + return instance; + } + + public Type GetParameterType() + { + return typeof(P); + } + + public void SetContextParameterValues(IDictionary parameterValues) + { + _contextParameterValues = parameterValues; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs index 94a8c99..4e2bfff 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalEvaluationTests.cs @@ -55,7 +55,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation new[] {new Token("__"), new Token("in", new StringParameter("knows"))}, "__.in(\"knows\")")})}), Tuple.Create("g.V().has(\"age\",P.gt(27))", new[] {new Token("has", new ITokenParameter[] { new StringParameter("age"), - new TraversalPredicateParameter( + new PParameter( new[] { new Token("P"), new Token("gt", LiteralParameter.Create(27)) }) })}), Tuple.Create("g.V().count(Scope.local)", new[] { new Token("count", new TraversalEnumParameter("Scope.local"))}), http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs index 118fcea..11145da 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalParser.cs @@ -406,7 +406,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation } if (text.Substring(i, 2).StartsWith("P.")) { - return new TraversalPredicateParameter(ParseTokens(text, ref i)); + return new PParameter(ParseTokens(text, ref i)); } var parameterText = text.Substring(i, text.IndexOf(')', i) - i); var separatorIndex = parameterText.IndexOf(','); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalPredicateParameter.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalPredicateParameter.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalPredicateParameter.cs deleted file mode 100644 index 57262c1..0000000 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/TraversalPredicateParameter.cs +++ /dev/null @@ -1,93 +0,0 @@ -#region License - -/* - * 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. - */ - -#endregion - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using Gremlin.Net.Process.Traversal; - -namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation -{ - /// - /// Represents a parameter for a traversal predicate (ie: P.gt()) - /// - internal class TraversalPredicateParameter : ITokenParameter, IEquatable - { - private IDictionary _contextParameterValues; - public IList Tokens { get; } - - public TraversalPredicateParameter(IList tokens) - { - Tokens = tokens; - } - - public bool Equals(TraversalPredicateParameter other) - { - return Tokens.SequenceEqual(other.Tokens); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != GetType()) return false; - return Equals((TraversalPredicateParameter) obj); - } - - public override int GetHashCode() - { - return Tokens != null ? Tokens.GetHashCode() : 0; - } - - public object GetValue() - { - var type = typeof(P); - object instance = null; - for (var i = 1; i < Tokens.Count; i++) - { - var token = Tokens[i]; - token.SetContextParameterValues(_contextParameterValues); - var method = type.GetMethod(TraversalParser.GetCsharpName(token.Name), - BindingFlags.Static | BindingFlags.Public); - if (method == null) - { - throw new InvalidOperationException($"Predicate (P) method '{token}' not found for testing"); - } - instance = method.Invoke(instance, - new object[] {token.Parameters.Select(p => p.GetValue()).ToArray()}); - } - return instance; - } - - public Type GetParameterType() - { - return typeof(TraversalPredicate); - } - - public void SetContextParameterValues(IDictionary parameterValues) - { - _contextParameterValues = parameterValues; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/BytecodeGraphSONSerializerTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/BytecodeGraphSONSerializerTests.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/BytecodeGraphSONSerializerTests.cs index 8ed7a3d..568b970 100644 --- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/BytecodeGraphSONSerializerTests.cs +++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/BytecodeGraphSONSerializerTests.cs @@ -118,7 +118,7 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON bytecode.AddSource("withSideEffect", "a", new List {"josh", "peter"}); bytecode.AddStep("V", 1); bytecode.AddStep("values", "name"); - bytecode.AddStep("where", new TraversalPredicate("within", "a")); + bytecode.AddStep("where", new P("within", "a")); var graphsonWriter = CreateGraphSONWriter(); var graphSON = graphsonWriter.WriteObject(bytecode); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/359b08cc/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs index 3d02533..3e2d307 100644 --- a/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs +++ b/gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONWriterTests.cs @@ -222,7 +222,7 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON public void ShouldSerializePredicateWithTwoValues() { var writer = CreateStandardGraphSONWriter(); - var predicate = new TraversalPredicate("within", new List {1, 2}); + var predicate = new P("within", new List {1, 2}); var serializedPredicate = writer.WriteObject(predicate); @@ -235,7 +235,7 @@ namespace Gremlin.Net.UnitTest.Structure.IO.GraphSON public void ShouldSerializePredicateWithSingleValue() { var writer = CreateStandardGraphSONWriter(); - var predicate = new TraversalPredicate("lt", 5); + var predicate = new P("lt", 5); var serializedPredicate = writer.WriteObject(predicate);