Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UnionCursor.cs
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Threading.Tasks;
7
9{
15 internal class UnionCursor<T> : ICursor<T>
16 {
17 private readonly Dictionary<Guid, bool> returned = new Dictionary<Guid, bool>();
18 private ICursor<T> currentCursor;
19 private readonly Filter[] childFilters;
20 private readonly ObjectBTreeFile file;
21 private int currentCursorPosition = 0;
22 private readonly int nrCursors;
23
30 public UnionCursor(Filter[] ChildFilters, ObjectBTreeFile File)
31 {
32 this.childFilters = ChildFilters;
33 this.nrCursors = this.childFilters.Length;
34 this.file = File;
35 this.currentCursor = null;
36 }
37
43 public T Current => this.CurrentCursor.Current;
44
45 private ICursor<T> CurrentCursor
46 {
47 get
48 {
49 if (this.currentCursor is null)
50 throw new InvalidOperationException("Enumeration not started or has already ended.");
51 else
52 return this.currentCursor;
53 }
54 }
55
59 public IObjectSerializer CurrentSerializer => this.CurrentCursor.CurrentSerializer;
60
65 public bool CurrentTypeCompatible => this.CurrentCursor.CurrentTypeCompatible;
66
72 public Guid CurrentObjectId => this.CurrentCursor.CurrentObjectId;
73
77 public void Dispose()
78 {
79 this.currentCursor = null;
80 }
81
89 Task<bool> IAsyncEnumerator.MoveNextAsync() => this.MoveNextAsyncLocked();
90
96 object IEnumerator.Current => this.Current;
97
105 public bool MoveNext() => this.MoveNextAsyncLocked().Result;
106
110 public void Reset()
111 {
112 this.currentCursor = null;
113 this.currentCursorPosition = 0;
114 }
115
122 public async Task<bool> MoveNextAsyncLocked()
123 {
124 Guid ObjectId;
125
126 while (true)
127 {
128 if (this.currentCursor is null)
129 {
130 if (this.currentCursorPosition >= this.nrCursors)
131 return false;
132
133 this.currentCursor = await this.file.ConvertFilterToCursorLocked<T>(this.childFilters[this.currentCursorPosition++], null, true);
134 }
135
136 if (!await this.currentCursor.MoveNextAsyncLocked())
137 {
138 this.currentCursor = null;
139 continue;
140 }
141
142 if (!this.currentCursor.CurrentTypeCompatible)
143 continue;
144
145 ObjectId = this.currentCursor.CurrentObjectId;
146 if (this.returned.ContainsKey(ObjectId))
147 continue;
148
149 this.returned[ObjectId] = true;
150 return true;
151 }
152 }
153
160 public Task<bool> MovePreviousAsyncLocked()
161 {
162 return this.MoveNextAsyncLocked(); // Union operator not ordered.
163 }
164
172 public bool SameSortOrder(string[] ConstantFields, string[] SortOrder)
173 {
174 return false;
175 }
176
184 public bool ReverseSortOrder(string[] ConstantFields, string[] SortOrder)
185 {
186 return false;
187 }
188
193 public Task ContinueAfterLocked(T LastItem)
194 {
195 throw new NotSupportedException("Paginated search is not supported for union queries.");
196 }
197
202 public Task ContinueBeforeLocked(T LastItem)
203 {
204 throw new NotSupportedException("Paginated search is not supported for union queries.");
205 }
206 }
207}
Base class for all filter classes.
Definition: Filter.cs:15
Interface for asynchronous enumerators.
Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.