2using System.Collections;
3using System.Collections.Generic;
4using System.Threading.Tasks;
15 internal class UnionCursor<T> : ICursor<T>
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;
30 public UnionCursor(
Filter[] ChildFilters, ObjectBTreeFile File)
32 this.childFilters = ChildFilters;
33 this.nrCursors = this.childFilters.Length;
35 this.currentCursor =
null;
43 public T Current => this.CurrentCursor.Current;
45 private ICursor<T> CurrentCursor
49 if (this.currentCursor is
null)
50 throw new InvalidOperationException(
"Enumeration not started or has already ended.");
52 return this.currentCursor;
59 public IObjectSerializer CurrentSerializer => this.CurrentCursor.CurrentSerializer;
65 public bool CurrentTypeCompatible => this.CurrentCursor.CurrentTypeCompatible;
72 public Guid CurrentObjectId => this.CurrentCursor.CurrentObjectId;
79 this.currentCursor =
null;
96 object IEnumerator.Current => this.Current;
105 public bool MoveNext() => this.MoveNextAsyncLocked().Result;
112 this.currentCursor =
null;
113 this.currentCursorPosition = 0;
122 public async Task<bool> MoveNextAsyncLocked()
128 if (this.currentCursor is
null)
130 if (this.currentCursorPosition >= this.nrCursors)
133 this.currentCursor = await this.file.ConvertFilterToCursorLocked<T>(this.childFilters[this.currentCursorPosition++],
null,
true);
136 if (!await this.currentCursor.MoveNextAsyncLocked())
138 this.currentCursor =
null;
142 if (!this.currentCursor.CurrentTypeCompatible)
145 ObjectId = this.currentCursor.CurrentObjectId;
146 if (this.returned.ContainsKey(ObjectId))
149 this.returned[ObjectId] =
true;
160 public Task<bool> MovePreviousAsyncLocked()
162 return this.MoveNextAsyncLocked();
172 public bool SameSortOrder(
string[] ConstantFields,
string[] SortOrder)
184 public bool ReverseSortOrder(
string[] ConstantFields,
string[] SortOrder)
193 public Task ContinueAfterLocked(T LastItem)
195 throw new NotSupportedException(
"Paginated search is not supported for union queries.");
202 public Task ContinueBeforeLocked(T LastItem)
204 throw new NotSupportedException(
"Paginated search is not supported for union queries.");
Base class for all filter classes.
Interface for asynchronous enumerators.
Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.
Interface for object serializers.