Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
JoinedElementEnumerator.cs
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 this.e?.Dispose();
50 this.e = null;
51
52 foreach (IEnumerator<ISemanticElement> Enumerator in this.enumerators)
53 Enumerator.Dispose();
54 }
55
60 public bool MoveNext()
61 {
62 if (this.e is null)
63 {
64 this.e = this.enumerators.GetEnumerator();
65
66 if (!this.e.MoveNext())
67 return false;
68
69 this.current = this.e.Current;
70 }
71
72 while (true)
73 {
74 if (this.current.MoveNext())
75 {
76 if (this.removeDuplicates)
77 {
78 if (this.reported.ContainsKey(this.current.Current))
79 continue;
80
81 this.reported[this.current.Current] = true;
82 }
83
84 return true;
85 }
86
87 if (!this.e.MoveNext())
88 return false;
89
90 this.current = this.e.Current;
91 }
92 }
93
97 public void Reset()
98 {
99 this.current = null;
100
101 this.e?.Dispose();
102 this.e = null;
103 }
104 }
105}
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.