Skip to content

QueryExpression rewriter #820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,27 @@ public override string ToString()
{
return $"{Keywords.Has}({TargetCollection})";
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (CollectionNotEmptyExpression) obj;

return TargetCollection.Equals(other.TargetCollection);
}

public override int GetHashCode()
{
return TargetCollection.GetHashCode();
}
}
}
22 changes: 22 additions & 0 deletions src/JsonApiDotNetCore/Queries/Expressions/ComparisonExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,27 @@ public override string ToString()
{
return $"{Operator.ToString().Camelize()}({Left},{Right})";
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (ComparisonExpression) obj;

return Operator == other.Operator && Left.Equals(other.Left) && Right.Equals(other.Right);
}

public override int GetHashCode()
{
return HashCode.Combine(Operator, Left, Right);
}
}
}
22 changes: 22 additions & 0 deletions src/JsonApiDotNetCore/Queries/Expressions/CountExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,27 @@ public override string ToString()
{
return $"{Keywords.Count}({TargetCollection})";
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (CountExpression) obj;

return TargetCollection.Equals(other.TargetCollection);
}

public override int GetHashCode()
{
return TargetCollection.GetHashCode();
}
}
}
30 changes: 30 additions & 0 deletions src/JsonApiDotNetCore/Queries/Expressions/EqualsAnyOfExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,35 @@ public override string ToString()

return builder.ToString();
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (EqualsAnyOfExpression) obj;

return TargetAttribute.Equals(other.TargetAttribute) && Constants.SequenceEqual(other.Constants);
}

public override int GetHashCode()
{
var hashCode = new HashCode();
hashCode.Add(TargetAttribute);

foreach (var constant in Constants)
{
hashCode.Add(constant);
}

return hashCode.ToHashCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,35 @@ public override string ToString()

return builder.ToString();
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (IncludeElementExpression) obj;

return Relationship.Equals(other.Relationship) == Children.SequenceEqual(other.Children);
}

public override int GetHashCode()
{
var hashCode = new HashCode();
hashCode.Add(Relationship);

foreach (var child in Children)
{
hashCode.Add(child);
}

return hashCode.ToHashCode();
}
}
}
29 changes: 29 additions & 0 deletions src/JsonApiDotNetCore/Queries/Expressions/IncludeExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,34 @@ public override string ToString()
var chains = IncludeChainConverter.GetRelationshipChains(this);
return string.Join(",", chains.Select(child => child.ToString()));
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (IncludeExpression) obj;

return Elements.SequenceEqual(other.Elements);
}

public override int GetHashCode()
{
var hashCode = new HashCode();

foreach (var element in Elements)
{
hashCode.Add(element);
}

return hashCode.ToHashCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,27 @@ public override string ToString()
string value = Value.Replace("\'", "\'\'");
return $"'{value}'";
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (LiteralConstantExpression) obj;

return Value == other.Value;
}

public override int GetHashCode()
{
return Value.GetHashCode();
}
}
}
30 changes: 30 additions & 0 deletions src/JsonApiDotNetCore/Queries/Expressions/LogicalExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,35 @@ public override string ToString()

return builder.ToString();
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (LogicalExpression) obj;

return Operator == other.Operator && Terms.SequenceEqual(other.Terms);
}

public override int GetHashCode()
{
var hashCode = new HashCode();
hashCode.Add(Operator);

foreach (var term in Terms)
{
hashCode.Add(term);
}

return hashCode.ToHashCode();
}
}
}
22 changes: 22 additions & 0 deletions src/JsonApiDotNetCore/Queries/Expressions/MatchTextExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,27 @@ public override string ToString()

return builder.ToString();
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (MatchTextExpression) obj;

return TargetAttribute.Equals(other.TargetAttribute) && TextValue.Equals(other.TextValue) && MatchKind == other.MatchKind;
}

public override int GetHashCode()
{
return HashCode.Combine(TargetAttribute, TextValue, MatchKind);
}
}
}
22 changes: 22 additions & 0 deletions src/JsonApiDotNetCore/Queries/Expressions/NotExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,27 @@ public override string ToString()
{
return $"{Keywords.Not}({Child})";
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (NotExpression) obj;

return Child.Equals(other.Child);
}

public override int GetHashCode()
{
return Child.GetHashCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using JsonApiDotNetCore.Queries.Internal.Parsing;

namespace JsonApiDotNetCore.Queries.Expressions
Expand All @@ -16,5 +17,25 @@ public override string ToString()
{
return Keywords.Null;
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

return true;
}

public override int GetHashCode()
{
return new HashCode().ToHashCode();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace JsonApiDotNetCore.Queries.Expressions
{
/// <summary>
Expand All @@ -23,5 +25,27 @@ public override string ToString()
{
return Scope == null ? Value.ToString() : $"{Scope}: {Value}";
}

public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (obj is null || GetType() != obj.GetType())
{
return false;
}

var other = (PaginationElementQueryStringValueExpression) obj;

return Equals(Scope, other.Scope) && Value == other.Value;
}

public override int GetHashCode()
{
return HashCode.Combine(Scope, Value);
}
}
}
Loading