-
Notifications
You must be signed in to change notification settings - Fork 533
Expand file tree
/
Copy pathCosmosNumber.cs
More file actions
214 lines (173 loc) · 6.62 KB
/
CosmosNumber.cs
File metadata and controls
214 lines (173 loc) · 6.62 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.CosmosElements
{
#nullable enable
using System;
using Microsoft.Azure.Cosmos.CosmosElements.Numbers;
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
public
#else
internal
#endif
abstract class CosmosNumber : CosmosElement, IEquatable<CosmosNumber>, IComparable<CosmosNumber>
{
protected CosmosNumber()
: base()
{
}
public abstract Number64 Value { get; }
public abstract void Accept(ICosmosNumberVisitor cosmosNumberVisitor);
public abstract TResult Accept<TResult>(ICosmosNumberVisitor<TResult> cosmosNumberVisitor);
public abstract TOutput Accept<TArg, TOutput>(ICosmosNumberVisitor<TArg, TOutput> cosmosNumberVisitor, TArg input);
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 CosmosNumber cosmosNumber && this.Equals(cosmosNumber);
}
public abstract bool Equals(CosmosNumber? cosmosNumber);
public int CompareTo(CosmosNumber? other)
{
if (other is null)
{
return 1;
}
int thisTypeOrder = this.Accept(CosmosNumberToTypeOrder.Singleton);
int otherTypeOrder = other.Accept(CosmosNumberToTypeOrder.Singleton);
if (thisTypeOrder != otherTypeOrder)
{
return thisTypeOrder.CompareTo(otherTypeOrder);
}
// The types are the same so dispatch to each compare operator
return this.Accept(CosmosNumberWithinTypeComparer.Singleton, other);
}
public static new CosmosNumber CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.CreateFromBuffer<CosmosNumber>(buffer);
}
public static new CosmosNumber Parse(string json)
{
return CosmosElement.Parse<CosmosNumber>(json);
}
public static bool TryCreateFromBuffer(
ReadOnlyMemory<byte> buffer,
out CosmosNumber cosmosNumber)
{
return CosmosElement.TryCreateFromBuffer<CosmosNumber>(buffer, out cosmosNumber);
}
public static bool TryParse(
string json,
out CosmosNumber cosmosNumber)
{
return CosmosElement.TryParse<CosmosNumber>(json, out cosmosNumber);
}
public static new class Monadic
{
public static TryCatch<CosmosNumber> CreateFromBuffer(ReadOnlyMemory<byte> buffer)
{
return CosmosElement.Monadic.CreateFromBuffer<CosmosNumber>(buffer);
}
public static TryCatch<CosmosNumber> Parse(string json)
{
return CosmosElement.Monadic.Parse<CosmosNumber>(json);
}
}
private sealed class CosmosNumberToTypeOrder : ICosmosNumberVisitor<int>
{
public static readonly CosmosNumberToTypeOrder Singleton = new CosmosNumberToTypeOrder();
private CosmosNumberToTypeOrder()
{
}
public int Visit(CosmosNumber64 cosmosNumber64)
{
return 0;
}
public int Visit(CosmosInt8 cosmosInt8)
{
return 1;
}
public int Visit(CosmosInt16 cosmosInt16)
{
return 2;
}
public int Visit(CosmosInt32 cosmosInt32)
{
return 3;
}
public int Visit(CosmosInt64 cosmosInt64)
{
return 4;
}
public int Visit(CosmosUInt32 cosmosUInt32)
{
return 5;
}
public int Visit(CosmosFloat32 cosmosFloat32)
{
return 6;
}
public int Visit(CosmosFloat64 cosmosFloat64)
{
return 7;
}
}
private sealed class CosmosNumberWithinTypeComparer : ICosmosNumberVisitor<CosmosNumber, int>
{
public static readonly CosmosNumberWithinTypeComparer Singleton = new CosmosNumberWithinTypeComparer();
private CosmosNumberWithinTypeComparer()
{
}
public int Visit(CosmosNumber64 cosmosNumber64, CosmosNumber input)
{
return cosmosNumber64.CompareTo((CosmosNumber64)input);
}
public int Visit(CosmosInt8 cosmosInt8, CosmosNumber input)
{
return cosmosInt8.CompareTo((CosmosInt8)input);
}
public int Visit(CosmosInt16 cosmosInt16, CosmosNumber input)
{
return cosmosInt16.CompareTo((CosmosInt16)input);
}
public int Visit(CosmosInt32 cosmosInt32, CosmosNumber input)
{
return cosmosInt32.CompareTo((CosmosInt32)input);
}
public int Visit(CosmosInt64 cosmosInt64, CosmosNumber input)
{
return cosmosInt64.CompareTo((CosmosInt64)input);
}
public int Visit(CosmosUInt32 cosmosUInt32, CosmosNumber input)
{
return cosmosUInt32.CompareTo((CosmosUInt32)input);
}
public int Visit(CosmosFloat32 cosmosFloat32, CosmosNumber input)
{
return cosmosFloat32.CompareTo((CosmosFloat32)input);
}
public int Visit(CosmosFloat64 cosmosFloat64, CosmosNumber input)
{
return cosmosFloat64.CompareTo((CosmosFloat64)input);
}
}
}
#if INTERNAL
#pragma warning restore SA1600 // Elements should be documented
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
#endif
}