Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RangeInfo.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
5
7{
11 public class RangeInfo
12 {
13 private readonly string fieldName;
14 private object min;
15 private object max;
16 private object point;
17 private bool minInclusive;
18 private bool maxInclusive;
19 private bool isRange;
20 private bool isPoint;
21
26 public RangeInfo(string FieldName)
27 {
28 this.fieldName = FieldName;
29 }
30
34 public string FieldName => this.fieldName;
35
39 public object Min => this.min;
40
44 public object Max => this.max;
45
49 public object Point => this.point;
50
54 public bool MinInclusive => this.minInclusive;
55
59 public bool MaxInclusive => this.maxInclusive;
60
64 public bool IsRange => this.isRange;
65
69 public bool IsPoint => this.isPoint;
70
74 public bool IsOpenEndedRange
75 {
76 get { return this.IsRange && (this.min is null || this.max is null); }
77 }
78
82 public bool HasMin
83 {
84 get { return (this.isRange && !(this.min is null)) || (this.isPoint && !(this.point is null)); }
85 }
86
90 public bool HasMax
91 {
92 get { return (this.isRange && !(this.max is null)) || (this.isPoint && !(this.point is null)); }
93 }
94
100 public bool SetPoint(object Value)
101 {
102 int? i;
103
104 if (this.isRange)
105 {
106 if (!(this.min is null))
107 {
108 i = Comparison.Compare(this.min, Value);
109
110 if (!i.HasValue || i.Value > 0 || (i.Value == 0 && !this.minInclusive))
111 return false;
112
113 this.min = null;
114 }
115
116 if (!(this.max is null))
117 {
118 i = Comparison.Compare(this.max, Value);
119
120 if (!i.HasValue || i.Value < 0 || (i.Value == 0 && !this.maxInclusive))
121 return false;
122
123 this.max = null;
124 }
125
126 this.point = Value;
127 this.isRange = false;
128 this.isPoint = true;
129 return true;
130 }
131 else if (this.isPoint)
132 {
133 i = Comparison.Compare(this.point, Value);
134 return (i.HasValue && i.Value == 0);
135 }
136 else
137 {
138 this.isPoint = true;
139 this.point = Value;
140 return true;
141 }
142 }
143
151 public bool SetMin(object Value, bool Inclusive, out bool Smaller)
152 {
153 int? i;
154
155 Smaller = false;
156
157 if (this.isRange)
158 {
159 if (!(this.min is null))
160 {
161 i = Comparison.Compare(this.min, Value);
162
163 if (!i.HasValue)
164 return false;
165
166 if (i.Value < 0)
167 {
168 Smaller = true;
169
170 if (!this.minInclusive && Inclusive)
171 {
172 if (Comparison.Increment(ref this.min))
173 {
174 i = Comparison.Compare(this.min, Value);
175 if (i.HasValue && i.Value == 0)
176 Smaller = false;
177 }
178 }
179
180 this.min = Value;
181 this.minInclusive = Inclusive;
182 }
183 else if (i.Value == 0)
184 {
185 if (!Inclusive && this.minInclusive)
186 {
187 this.minInclusive = false;
188 Smaller = true;
189 }
190 }
191 }
192 else
193 {
194 this.min = Value;
195 this.minInclusive = Inclusive;
196 Smaller = true;
197 }
198
199 if (!(this.max is null))
200 {
201 i = Comparison.Compare(this.max, this.min);
202 if (!i.HasValue || i.Value < 0)
203 return false;
204 else if (i.Value == 0)
205 {
206 if (!(this.minInclusive && this.maxInclusive))
207 return false;
208
209 this.point = Value;
210 this.isPoint = true;
211 this.isRange = false;
212 this.min = null;
213 this.max = null;
214 }
215 }
216
217 return true;
218 }
219 else if (this.isPoint)
220 {
221 i = Comparison.Compare(this.point, Value);
222
223 return !(!i.HasValue || i.Value < 0 || (i.Value == 0 && !Inclusive));
224 }
225 else
226 {
227 this.min = Value;
228 this.minInclusive = Inclusive;
229 this.isRange = true;
230 Smaller = true;
231 return true;
232 }
233 }
234
242 public bool SetMax(object Value, bool Inclusive, out bool Smaller)
243 {
244 int? i;
245
246 Smaller = false;
247
248 if (this.isRange)
249 {
250 if (!(this.max is null))
251 {
252 i = Comparison.Compare(this.max, Value);
253
254 if (!i.HasValue)
255 return false;
256
257 if (i.Value > 0)
258 {
259 Smaller = true;
260
261 if (!this.maxInclusive && Inclusive)
262 {
263 if (Comparison.Decrement(ref this.max))
264 {
265 i = Comparison.Compare(this.max, Value);
266 if (i.HasValue && i.Value == 0)
267 Smaller = false;
268 }
269 }
270
271 this.max = Value;
272 this.maxInclusive = Inclusive;
273 }
274 else if (i.Value == 0)
275 {
276 if (!Inclusive && this.maxInclusive)
277 {
278 this.maxInclusive = false;
279 Smaller = true;
280 }
281 }
282 }
283 else
284 {
285 this.max = Value;
286 this.maxInclusive = Inclusive;
287 Smaller = true;
288 }
289
290 if (!(this.min is null))
291 {
292 i = Comparison.Compare(this.max, this.min);
293 if (!i.HasValue || i.Value < 0)
294 return false;
295 else if (i.Value == 0)
296 {
297 if (!(this.minInclusive && this.maxInclusive))
298 return false;
299
300 this.point = Value;
301 this.isPoint = true;
302 this.isRange = false;
303 this.min = null;
304 this.max = null;
305 }
306 }
307
308 return true;
309 }
310 else if (this.isPoint)
311 {
312 i = Comparison.Compare(this.point, Value);
313
314 return !(!i.HasValue || i.Value > 0 || (i.Value == 0 && !Inclusive));
315 }
316 else
317 {
318 this.max = Value;
319 this.maxInclusive = Inclusive;
320 this.isRange = true;
321 Smaller = true;
322 return true;
323 }
324 }
325
331 {
332 RangeInfo Result = new RangeInfo(this.fieldName);
333 this.CopyTo(Result);
334 return Result;
335 }
336
341 public void CopyTo(RangeInfo Destination)
342 {
343 Destination.min = this.min;
344 Destination.max = this.max;
345 Destination.point = this.point;
346 Destination.minInclusive = this.minInclusive;
347 Destination.maxInclusive = this.maxInclusive;
348 Destination.isRange = this.isRange;
349 Destination.isPoint = this.isPoint;
350 }
351
352 }
353}
Static class that performs comparisons of property values.
Definition: Comparison.cs:13
static bool Decrement(ref object Value)
Decrements Value to the largest value smaller than Value .
Definition: Comparison.cs:711
static ? int Compare(object Value1, object Value2)
Compares two values. The values can be of different, but compatible types.
Definition: Comparison.cs:222
static bool Increment(ref object Value)
Increments Value to the smallest value greater than Value .
Definition: Comparison.cs:253
Contains information about a range in a search operation.
Definition: RangeInfo.cs:12
bool HasMin
If the range has a minimum endpoint.
Definition: RangeInfo.cs:83
RangeInfo(string FieldName)
Contains information about a range in a search operation.
Definition: RangeInfo.cs:26
object Max
Maximum endpoint, if a range.
Definition: RangeInfo.cs:44
bool MinInclusive
If the minimum endpoint is included in the range.
Definition: RangeInfo.cs:54
bool SetMin(object Value, bool Inclusive, out bool Smaller)
Sets minimum endpoint of range.
Definition: RangeInfo.cs:151
bool SetMax(object Value, bool Inclusive, out bool Smaller)
Sets maximum endpoint of range.
Definition: RangeInfo.cs:242
object Min
Minimum endpoint, if a range.
Definition: RangeInfo.cs:39
void CopyTo(RangeInfo Destination)
Copies the range information to another range object.
Definition: RangeInfo.cs:341
object Point
Point value, if not a range.
Definition: RangeInfo.cs:49
bool IsRange
If the object specifies a range (true) or a single point (false).
Definition: RangeInfo.cs:64
bool IsOpenEndedRange
If the range is open-ended.
Definition: RangeInfo.cs:75
RangeInfo Copy()
Creates a copy of the range information.
Definition: RangeInfo.cs:330
bool IsPoint
If the object specifies a point (true) or a range (false).
Definition: RangeInfo.cs:69
bool HasMax
If the range has a maximum endpoint.
Definition: RangeInfo.cs:91
bool SetPoint(object Value)
Range consists of a single point value.
Definition: RangeInfo.cs:100
bool MaxInclusive
If the maximum endpoint is included in the range.
Definition: RangeInfo.cs:59