Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
21 changes: 16 additions & 5 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
using Microsoft.Azure.Cosmos.Json;
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.Azure.Cosmos.Query.Core.Pipeline.Distinct;
using UInt128 = Cosmos.UInt128;

#if INTERNAL
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
Expand Down Expand Up @@ -42,10 +43,15 @@ protected CosmosArray()

public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input) => cosmosElementVisitor.Visit(this, input);

public override bool Equals(CosmosElement cosmosElement) => cosmosElement is CosmosArray cosmosArray && this.Equals(cosmosArray);
public override bool Equals(CosmosElement? cosmosElement) => cosmosElement is CosmosArray cosmosArray && this.Equals(cosmosArray);

public bool Equals(CosmosArray cosmosArray)
public bool Equals(CosmosArray? cosmosArray)
{
if (cosmosArray is null)
{
return false;
}

if (this.Count != cosmosArray.Count)
{
return false;
Expand Down Expand Up @@ -77,10 +83,15 @@ public override int GetHashCode()
return (int)hash;
}

public int CompareTo(CosmosArray cosmosArray)
public int CompareTo(CosmosArray? cosmosArray)
{
UInt128 hash1 = DistinctHash.GetHash(this);
UInt128 hash2 = DistinctHash.GetHash(cosmosArray);
if (cosmosArray is null)
{
return 1;
}

Cosmos.UInt128 hash1 = DistinctHash.GetHash(this);
Cosmos.UInt128 hash2 = DistinctHash.GetHash(cosmosArray);
return UInt128BinaryComparer.Singleton.Compare(hash1, hash2);
}

Expand Down
22 changes: 19 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosBinary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ protected CosmosBinary()

public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input) => cosmosElementVisitor.Visit(this, input);

public override bool Equals(CosmosElement cosmosElement) => cosmosElement is CosmosBinary cosmosBinary && this.Equals(cosmosBinary);
public override bool Equals(CosmosElement? cosmosElement) => cosmosElement is CosmosBinary cosmosBinary && this.Equals(cosmosBinary);

public bool Equals(CosmosBinary cosmosBinary) => this.Value.Span.SequenceEqual(cosmosBinary.Value.Span);
public bool Equals(CosmosBinary? cosmosBinary)
{
if (cosmosBinary is null)
{
return false;
}

return this.Value.Span.SequenceEqual(cosmosBinary.Value.Span);
}

public override int GetHashCode()
{
Expand All @@ -45,7 +53,15 @@ public override int GetHashCode()
return (int)hash;
}

public int CompareTo(CosmosBinary cosmosBinary) => this.Value.Span.SequenceCompareTo(cosmosBinary.Value.Span);
public int CompareTo(CosmosBinary? cosmosBinary)
{
if (cosmosBinary is null)
{
return 1;
}

return this.Value.Span.SequenceCompareTo(cosmosBinary.Value.Span);
}

public static CosmosBinary Create(
IJsonNavigator jsonNavigator,
Expand Down
14 changes: 12 additions & 2 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosBoolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ public override bool Equals(CosmosElement cosmosElement)
return cosmosElement is CosmosBoolean cosmosBoolean && this.Equals(cosmosBoolean);
}

public bool Equals(CosmosBoolean cosmosBoolean)
public bool Equals(CosmosBoolean? cosmosBoolean)
{
if (cosmosBoolean is null)
{
return false;
}

return this.Value == cosmosBoolean.Value;
}

Expand All @@ -62,8 +67,13 @@ public override int GetHashCode()
return this.Value ? TrueHash : FalseHash;
}

public int CompareTo(CosmosBoolean cosmosBoolean)
public int CompareTo(CosmosBoolean? cosmosBoolean)
{
if (cosmosBoolean is null)
{
return 1;
}

return this.Value.CompareTo(cosmosBoolean.Value);
}

Expand Down
6 changes: 3 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public override string ToString()
return Utf8StringHelpers.ToString(jsonWriter.GetResult());
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is CosmosElement cosmosElement && this.Equals(cosmosElement);
}

public abstract bool Equals(CosmosElement cosmosElement);
public abstract bool Equals(CosmosElement? cosmosElement);

public abstract override int GetHashCode();

public int CompareTo(CosmosElement other)
public int CompareTo(CosmosElement? other)
{
int thisTypeOrder = this.Accept(CosmosElementToTypeOrder.Singleton);
int otherTypeOrder = other.Accept(CosmosElementToTypeOrder.Singleton);
Expand Down
16 changes: 13 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosGuid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResul
return cosmosElementVisitor.Visit(this, input);
}

public override bool Equals(CosmosElement cosmosElement)
public override bool Equals(CosmosElement? cosmosElement)
{
return cosmosElement is CosmosGuid cosmosGuid && this.Equals(cosmosGuid);
}

public bool Equals(CosmosGuid cosmosGuid)
public bool Equals(CosmosGuid? cosmosGuid)
{
if (cosmosGuid is null)
{
return false;
}

return this.Value == cosmosGuid.Value;
}

Expand All @@ -60,8 +65,13 @@ public override int GetHashCode()
return (int)hash;
}

public int CompareTo(CosmosGuid cosmosGuid)
public int CompareTo(CosmosGuid? cosmosGuid)
{
if (cosmosGuid is null)
{
return 1;
}

return this.Value.CompareTo(cosmosGuid.Value);
}

Expand Down
16 changes: 13 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResul
return cosmosElementVisitor.Visit(this, input);
}

public override bool Equals(CosmosElement cosmosElement)
public override bool Equals(CosmosElement? cosmosElement)
{
return cosmosElement is CosmosNull cosmosNull && this.Equals(cosmosNull);
}

public bool Equals(CosmosNull cosmosNull)
public bool Equals(CosmosNull? cosmosNull)
{
if (cosmosNull is null)
{
return false;
}

return true;
}

Expand Down Expand Up @@ -91,8 +96,13 @@ public static bool TryParse(
return CosmosElement.TryParse<CosmosNull>(json, out cosmosNull);
}

public int CompareTo(CosmosNull other)
public int CompareTo(CosmosNull? other)
{
if (other is null)
{
return 1;
}

return 0;
}

Expand Down
11 changes: 8 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,20 @@ public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResul
return cosmosElementVisitor.Visit(this, input);
}

public override bool Equals(CosmosElement cosmosElement)
public override bool Equals(CosmosElement? cosmosElement)
{
return cosmosElement is CosmosNumber cosmosNumber && this.Equals(cosmosNumber);
}

public abstract bool Equals(CosmosNumber cosmosNumber);
public abstract bool Equals(CosmosNumber? cosmosNumber);

public int CompareTo(CosmosNumber other)
public int CompareTo(CosmosNumber? other)
{
if (other is null)
{
return 1;
}

int thisTypeOrder = this.Accept(CosmosNumberToTypeOrder.Singleton);
int otherTypeOrder = other.Accept(CosmosNumberToTypeOrder.Singleton);

Expand Down
17 changes: 14 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Microsoft.Azure.Cosmos.CosmosElements
using Microsoft.Azure.Cosmos.Json;
using Microsoft.Azure.Cosmos.Query.Core.Monads;
using Microsoft.Azure.Cosmos.Query.Core.Pipeline.Distinct;
using UInt128 = Cosmos.UInt128;

#if INTERNAL
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
Expand Down Expand Up @@ -90,13 +91,18 @@ public bool TryGetValue<TCosmosElement>(string key, out TCosmosElement typedCosm

IEnumerator<KeyValuePair<string, CosmosElement>> IEnumerable<KeyValuePair<string, CosmosElement>>.GetEnumerator() => this.GetEnumerator();

public override bool Equals(CosmosElement cosmosElement)
public override bool Equals(CosmosElement? cosmosElement)
{
return cosmosElement is CosmosObject cosmosObject && this.Equals(cosmosObject);
}

public bool Equals(CosmosObject cosmosObject)
public bool Equals(CosmosObject? cosmosObject)
{
if (cosmosObject is null)
{
return false;
}

if (this.Count != cosmosObject.Count)
{
return false;
Expand Down Expand Up @@ -143,8 +149,13 @@ public override int GetHashCode()
return (int)hash;
}

public int CompareTo(CosmosObject cosmosObject)
public int CompareTo(CosmosObject? cosmosObject)
{
if (cosmosObject is null)
{
return 1;
}

UInt128 hash1 = DistinctHash.GetHash(this);
UInt128 hash2 = DistinctHash.GetHash(cosmosObject);
return UInt128BinaryComparer.Singleton.Compare(hash1, hash2);
Expand Down
17 changes: 14 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Microsoft.Azure.Cosmos.CosmosElements

using System;
using Microsoft.Azure.Cosmos.Core.Utf8;
using Microsoft.Azure.Cosmos.CosmosElements.Numbers;
using Microsoft.Azure.Cosmos.Json;
using Microsoft.Azure.Cosmos.Query.Core.Monads;

Expand Down Expand Up @@ -46,13 +47,18 @@ public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResul
return cosmosElementVisitor.Visit(this, input);
}

public override bool Equals(CosmosElement cosmosElement)
public override bool Equals(CosmosElement? cosmosElement)
{
return cosmosElement is CosmosString cosmosString && this.Equals(cosmosString);
}

public bool Equals(CosmosString cosmosString)
public bool Equals(CosmosString? cosmosString)
{
if (cosmosString is null)
{
return false;
}

return this.Value == cosmosString.Value;
}

Expand All @@ -64,8 +70,13 @@ public override int GetHashCode()
return (int)hash;
}

public int CompareTo(CosmosString cosmosString)
public int CompareTo(CosmosString? cosmosString)
{
if (cosmosString is null)
{
return 1;
}

return string.CompareOrdinal(this.Value, cosmosString.Value);
}

Expand Down
16 changes: 13 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosElements/CosmosUndefined.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,28 @@ public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResul
return cosmosElementVisitor.Visit(this, input);
}

public int CompareTo(CosmosUndefined other)
public int CompareTo(CosmosUndefined? other)
{
if (other is null)
{
return 1;
}

return 0;
}

public override bool Equals(CosmosElement cosmosElement)
public override bool Equals(CosmosElement? cosmosElement)
{
return cosmosElement is CosmosUndefined;
}

public bool Equals(CosmosUndefined other)
public bool Equals(CosmosUndefined? other)
{
if (other is null)
{
return false;
}

return true;
}

Expand Down
16 changes: 13 additions & 3 deletions Microsoft.Azure.Cosmos/src/CosmosElements/Numbers/CosmosFloat32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ public override TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput
return cosmosNumberVisitor.Visit(this, input);
}

public override bool Equals(CosmosNumber cosmosNumber)
public override bool Equals(CosmosNumber? cosmosNumber)
{
return cosmosNumber is CosmosFloat32 cosmosFloat32 && this.Equals(cosmosFloat32);
}

public bool Equals(CosmosFloat32 cosmosFloat32)
public bool Equals(CosmosFloat32? cosmosFloat32)
{
if (cosmosFloat32 is null)
{
return false;
}

return this.GetValue() == cosmosFloat32.GetValue();
}

Expand All @@ -60,8 +65,13 @@ public override int GetHashCode()
return (int)MurmurHash3.Hash32(this.GetValue(), 495253708);
}

public int CompareTo(CosmosFloat32 cosmosFloat32)
public int CompareTo(CosmosFloat32? cosmosFloat32)
{
if (cosmosFloat32 is null)
{
return 1;
}

return this.GetValue().CompareTo(cosmosFloat32.GetValue());
}

Expand Down
Loading
Loading