Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DateTimeVector.cs
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4using System.Text;
10
12{
16 public sealed class DateTimeVector : VectorSpaceElement
17 {
18 private DateTime[] values;
19 private ICollection<IElement> elements;
20 private readonly int dimension;
21
26 public DateTimeVector(params DateTime[] Values)
27 {
28 this.values = Values;
29 this.elements = null;
30 this.dimension = Values.Length;
31 }
32
37 public DateTimeVector(ICollection<IElement> Elements)
38 {
39 this.values = null;
40 this.elements = Elements;
41 this.dimension = Elements.Count;
42 }
43
47 public DateTime[] Values
48 {
49 get
50 {
51 if (this.values is null)
52 {
53 DateTime[] v = new DateTime[this.dimension];
54 int i = 0;
55
56 foreach (IElement Element in this.elements)
57 {
58 if (!(Element.AssociatedObjectValue is DateTime TP))
59 TP = DateTime.MinValue;
60
61 v[i++] = TP;
62 }
63
64 this.values = v;
65 }
66
67 return this.values;
68 }
69 }
70
74 public ICollection<IElement> Elements
75 {
76 get
77 {
78 if (this.elements is null)
79 {
80 int i;
81 IElement[] v = new IElement[this.dimension];
82
83 for (i = 0; i < this.dimension; i++)
84 v[i] = new DateTimeValue(this.values[i]);
85
86 this.elements = v;
87 }
88
89 return this.elements;
90 }
91 }
92
96 public override int Dimension => this.dimension;
97
99 public override string ToString()
100 {
101 StringBuilder sb = null;
102
103 foreach (DateTime d in this.Values)
104 {
105 if (sb is null)
106 sb = new StringBuilder("[");
107 else
108 sb.Append(", ");
109
110 sb.Append(Expression.ToString(d));
111 }
112
113 if (sb is null)
114 return "[]";
115 else
116 {
117 sb.Append(']');
118 return sb.ToString();
119 }
120 }
121
126 {
127 get
128 {
129 if (this.associatedVectorSpace is null)
130 this.associatedVectorSpace = new DateTimeVectors(this.dimension);
131
132 return this.associatedVectorSpace;
133 }
134 }
135
136 private DateTimeVectors associatedVectorSpace = null;
137
141 public override object AssociatedObjectValue => this.Values;
142
149 {
150 return null;
151 }
152
159 {
160 return null;
161 }
162
167 public override IGroupElement Negate()
168 {
169 return null;
170 }
171
177 public override bool Equals(object obj)
178 {
180 if (DateTimeVector is null)
181 return false;
182
183 int i;
184 if (DateTimeVector.dimension != this.dimension)
185 return false;
186
187 DateTime[] Values = this.Values;
188 DateTime[] Values2 = DateTimeVector.Values;
189 for (i = 0; i < this.dimension; i++)
190 {
191 if (Values[i] != Values2[i])
192 return false;
193 }
194
195 return true;
196 }
197
202 public override int GetHashCode()
203 {
204 DateTime[] Values = this.Values;
205 int Result = 0;
206 int i;
207
208 for (i = 0; i < this.dimension; i++)
209 Result ^= Values[i].GetHashCode();
210
211 return Result;
212 }
213
217 public override bool IsScalar
218 {
219 get { return false; }
220 }
221
225 public override ICollection<IElement> ChildElements => this.Elements;
226
233 public override IElement Encapsulate(ICollection<IElement> Elements, ScriptNode Node)
234 {
235 return VectorDefinition.Encapsulate(Elements, true, Node);
236 }
237
242 {
243 get
244 {
245 if (this.zero is null)
246 this.zero = new DateTimeVector(new DateTime[this.dimension]);
247
248 return this.zero;
249 }
250 }
251
252 private DateTimeVector zero = null;
253
259 public override IElement GetElement(int Index)
260 {
261 if (Index < 0 || Index >= this.dimension)
262 throw new ScriptException("Index out of bounds.");
263
264 DateTime[] V = this.Values;
265
266 return new DateTimeValue(V[Index]);
267 }
268
274 public override void SetElement(int Index, IElement Value)
275 {
276 if (Index < 0 || Index >= this.dimension)
277 throw new ScriptException("Index out of bounds.");
278
279 if (!(Value.AssociatedObjectValue is DateTime V))
280 throw new ScriptException("Elements in a boolean vector are required to be boolean values.");
281
282 DateTime[] Values = this.Values;
283 this.elements = null;
284
285 Values[Index] = V;
286 }
287
294 public override bool TryConvertTo(Type DesiredType, out object Value)
295 {
296 if (DesiredType == typeof(DateTime[]))
297 {
298 Value = this.Values;
299 return true;
300 }
301 else if (DesiredType.GetTypeInfo().IsAssignableFrom(typeof(DateTimeVector).GetTypeInfo()))
302 {
303 Value = this;
304 return true;
305 }
306 else
307 return Expression.TryConvert(this.Values, DesiredType, out Value);
308 }
309
310 }
311}
Base class for all types of elements.
Definition: Element.cs:13
abstract object AssociatedObjectValue
Associated object value.
Definition: Element.cs:46
Base class for all types of vector space elements (vectors).
Base class for script exceptions.
Class managing a script expression.
Definition: Expression.cs:39
static bool TryConvert(object Value, Type DesiredType, out object Result)
Tries to convert an object Value to an object of type DesiredType .
Definition: Expression.cs:5268
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Definition: Expression.cs:4496
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
override ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
override int GetHashCode()
Calculates a hash code of the element.
override IVectorSpaceElement MultiplyScalar(IFieldElement Scalar)
Tries to multiply a scalar to the current element.
override bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
override IAbelianGroupElement Add(IAbelianGroupElement Element)
Tries to add an element to the current element.
override IGroupElement Negate()
Negates the element.
DateTimeVector(ICollection< IElement > Elements)
DateTime-valued vector.
DateTime[] Values
Vector element values.
override bool IsScalar
If the element represents a scalar value.
override IAbelianGroupElement Zero
Returns the zero element of the group.
override bool Equals(object obj)
Compares the element to another.
override IVectorSpace AssociatedVectorSpace
Associated Right-VectorSpace.
override IElement Encapsulate(ICollection< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
override void SetElement(int Index, IElement Value)
Sets an element in the vector.
override int Dimension
Dimension of vector.
override object AssociatedObjectValue
Associated object value.
override IElement GetElement(int Index)
Gets an element of the vector.
ICollection< IElement > Elements
Vector elements.
DateTimeVector(params DateTime[] Values)
DateTime-valued vector.
Pseudo-vector space of DateTime-valued vectors.
static IElement Encapsulate(Array Elements, bool CanEncapsulateAsMatrix, ScriptNode Node)
Encapsulates the elements of a vector.
Basic interface for all types of abelian group elements.
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Basic interface for all types of field elements.
Basic interface for all types of group elements.
Definition: IGroupElement.cs:9
Basic interface for all types of module elements.
Basic interface for all types of modules.
Definition: IVectorSpace.cs:10