Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
JoinedElementEnumerator.cs
1using System.Collections;
2using System.Collections.Generic;
3
5{
10 public class JoinedElementEnumerator : IEnumerator<ISemanticElement>
11 {
12 private readonly Dictionary<ISemanticElement, bool> reported;
13 private readonly IEnumerable<IEnumerator<ISemanticElement>> enumerators;
14 private IEnumerator<IEnumerator<ISemanticElement>> e;
15 private IEnumerator<ISemanticElement> current;
16 private readonly bool removeDuplicates;
17
24 public JoinedElementEnumerator(IEnumerable<IEnumerator<ISemanticElement>> Enumerators,
25 bool RemoveDuplicates)
26 {
27 this.enumerators = Enumerators;
28 this.removeDuplicates = RemoveDuplicates;
29
30 if (this.removeDuplicates)
31 this.reported = new Dictionary<ISemanticElement, bool>();
32 }
33
37 public ISemanticElement Current => this.current?.Current;
38
42 object IEnumerator.Current => this.current?.Current;
43
47 public void Dispose()
48 {
49 foreach (IEnumerator<ISemanticElement> Enumerator in this.enumerators)
50 Enumerator.Dispose();
51 }
52
57 public bool MoveNext()
58 {
59 if (this.e is null)
60 {
61 this.e = this.enumerators.GetEnumerator();
62
63 if (!this.e.MoveNext())
64 return false;
65
66 this.current = this.e.Current;
67 }
68
69 while (true)
70 {
71 if (this.current.MoveNext())
72 {
73 if (this.removeDuplicates)
74 {
75 if (this.reported.ContainsKey(this.current.Current))
76 continue;
77
78 this.reported[this.current.Current] = true;
79 }
80
81 return true;
82 }
83
84 if (!this.e.MoveNext())
85 return false;
86
87 this.current = this.e.Current;
88 }
89 }
90
94 public void Reset()
95 {
96 this.current = null;
97 this.e = null;
98 }
99 }
100}
Enumerator of elements from a collection of semantic data sources. The enumerator can remove duplicat...
JoinedElementEnumerator(IEnumerable< IEnumerator< ISemanticElement > > Enumerators, bool RemoveDuplicates)
Enumerator of elements from a collection of semantic data sources. The enumerator can remove duplicat...
void Dispose()
Disposes of the enumerator and sub-enumerators.
Interface for semantic nodes.