Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Set.cs
1using System;
2using System.Collections.Generic;
7
9{
13 public abstract class Set : Element, ISet
14 {
18 public Set()
19 {
20 }
21
27 public abstract bool Contains(IElement Element);
28
35 public override IElement Encapsulate(ICollection<IElement> Elements, ScriptNode Node)
36 {
37 return Operators.Sets.SetDefinition.Encapsulate(Elements);
38 }
39
45 public override abstract bool Equals(object obj);
46
51 public override abstract int GetHashCode();
52
56 public override object AssociatedObjectValue
57 {
58 get { return this; }
59 }
60
64 public override ISet AssociatedSet
65 {
66 get { return SetOfSets.Instance; }
67 }
68
72 public override ICollection<IElement> ChildElements
73 {
74 get
75 {
76 throw new ScriptException("Enumeration of set elements requires its finite members to be defined.");
77 }
78 }
79
83 public override bool IsScalar
84 {
85 get { return false; }
86 }
87
91 public virtual int? Size
92 {
93 get { return null; }
94 }
95
101 public static ISet ToSet(IElement E)
102 {
103 if (!(E is ISet Result))
104 {
105 if (E is IVector Vector)
106 Result = new FiniteSet(Vector.VectorElements);
107 else
108 {
109 object Obj = E.AssociatedObjectValue;
110 Result = Obj as ISet;
111 if (Result is null)
112 {
113 if (Obj is IEnumerable<IElement> Elements)
114 Result = new FiniteSet(Elements);
115 else if (Obj is IEnumerable<object> Objects)
116 {
117 LinkedList<IElement> List = new LinkedList<IElement>();
118
119 foreach (object x in Objects)
120 List.AddLast(Expression.Encapsulate(x));
121
122 Result = new FiniteSet(List);
123 }
124 else
125 return null;
126 }
127 }
128 }
129
130 return Result;
131 }
132
133
134 }
135}
Base class for all types of elements.
Definition: Element.cs:13
Base class for all types of sets.
Definition: Set.cs:14
static ISet ToSet(IElement E)
Converts (if necessary) the element E into a set.
Definition: Set.cs:101
override object AssociatedObjectValue
Associated object value.
Definition: Set.cs:57
abstract override bool Equals(object obj)
Compares the element to another.
abstract override int GetHashCode()
Calculates a hash code of the element.
Set()
Base class for all types of sets.
Definition: Set.cs:18
abstract bool Contains(IElement Element)
Checks if the set contains an element.
override ISet AssociatedSet
Associated Set.
Definition: Set.cs:65
override IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
Definition: Set.cs:35
override bool IsScalar
If the element represents a scalar value.
Definition: Set.cs:84
virtual ? int Size
Size of set, if finite and known, otherwise null is returned.
Definition: Set.cs:92
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
Definition: Set.cs:73
Base class for script exceptions.
Class managing a script expression.
Definition: Expression.cs:39
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:4955
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Represents a finite set.
Definition: FiniteSet.cs:13
Set containing all sets.
Definition: SetOfSets.cs:11
static readonly SetOfSets Instance
Instance of the set of all sets.
Definition: SetOfSets.cs:24
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
Basic interface for vectors.
Definition: IVector.cs:9
Basic interface for all types of sets.
Definition: ISet.cs:10