-
Notifications
You must be signed in to change notification settings - Fork 533
Expand file tree
/
Copy pathCosmosString.cs
More file actions
137 lines (113 loc) · 4.13 KB
/
CosmosString.cs
File metadata and controls
137 lines (113 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.CosmosElements
{
#nullable enable
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;
#if INTERNAL
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable SA1600 // Elements should be documented
#pragma warning disable SA1601 // Partial elements should be documented
public
#else
internal
#endif
abstract partial class CosmosString : CosmosElement, IEquatable<CosmosString>, IComparable<CosmosString>
{
public static CosmosString Empty = new EagerCosmosString(string.Empty);
private const uint HashSeed = 3163568842;
protected CosmosString()
: base()
{
}
public abstract UtfAnyString Value { get; }
public override void Accept(ICosmosElementVisitor cosmosElementVisitor)
{
cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TResult>(ICosmosElementVisitor<TResult> cosmosElementVisitor)
{
return cosmosElementVisitor.Visit(this);
}
public override TResult Accept<TArg, TResult>(ICosmosElementVisitor<TArg, TResult> cosmosElementVisitor, TArg input)
{
return cosmosElementVisitor.Visit(this, input);
}
public override bool Equals(CosmosElement? cosmosElement)
{
return cosmosElement is CosmosString cosmosString && this.Equals(cosmosString);
}
public bool Equals(CosmosString? cosmosString)
{
if (cosmosString is null)
{
return false;
}
return this.Value == cosmosString.Value;
}
public override int GetHashCode()
{
uint hash = HashSeed;
hash = MurmurHash3.Hash32(this.Value, hash);
return (int)hash;
}
public int CompareTo(CosmosString? cosmosString)
{
if (cosmosString is null)
{
return 1;
}
return string.CompareOrdinal(this.Value, cosmosString.Value);
}
public static CosmosString Create(
IJsonNavigator jsonNavigator,
IJsonNavigatorNode jsonNavigatorNode)
{
return new LazyCosmosString(jsonNavigator, jsonNavigatorNode);
}
public static CosmosString Create(string value)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
return value.Length == 0 ? EagerCosmosString.Empty : new EagerCosmosString(value);
}
public static new CosmosString CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.CreateFromBuffer<CosmosString>(buffer);
}
public static new CosmosString Parse(string json)
{
return CosmosElement.Parse<CosmosString>(json);
}
public static bool TryCreateFromBuffer(
ReadOnlyMemory<byte> buffer,
out CosmosString cosmosString)
{
return CosmosElement.TryCreateFromBuffer<CosmosString>(buffer, out cosmosString);
}
public static bool TryParse(
string json,
out CosmosString cosmosString)
{
return CosmosElement.TryParse<CosmosString>(json, out cosmosString);
}
public static new class Monadic
{
public static TryCatch<CosmosString> CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.Monadic.CreateFromBuffer<CosmosString>(buffer);
}
public static TryCatch<CosmosString> Parse(string json)
{
return CosmosElement.Monadic.Parse<CosmosString>(json);
}
}
}
}