Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / Runtime / XmlAggregates.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlAggregates.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7 using System;
8 using System.Xml;
9 using System.Diagnostics;
10 using System.ComponentModel;
11
12 namespace System.Xml.Xsl.Runtime {
13
14     /// <summary>
15     /// Computes aggregates over a sequence of Int32 values.
16     /// </summary>
17     [EditorBrowsable(EditorBrowsableState.Never)]
18     public struct Int32Aggregator {
19         private int result;
20         private int cnt;
21
22         public void Create() {
23             this.cnt = 0;
24         }
25
26         public void Sum(int value) {
27             if (this.cnt == 0) {
28                 this.result = value;
29                 this.cnt = 1;
30             }
31             else {
32                 this.result += value;
33             }
34         }
35
36         public void Average(int value) {
37             if (this.cnt == 0)
38                 this.result = value;
39             else
40                 this.result += value;
41
42             this.cnt++;
43         }
44
45         public void Minimum(int value) {
46             if (this.cnt == 0 || value < this.result)
47                 this.result = value;
48
49             this.cnt = 1;
50         }
51
52         public void Maximum(int value) {
53             if (this.cnt == 0 || value > this.result)
54                 this.result = value;
55
56             this.cnt = 1;
57         }
58
59         public int SumResult { get { return this.result; } }
60         public int AverageResult { get { return this.result / this.cnt; } }
61         public int MinimumResult { get { return this.result; } }
62         public int MaximumResult { get { return this.result; } }
63
64         public bool IsEmpty { get { return this.cnt == 0; } }
65     }
66
67
68     /// <summary>
69     /// Computes aggregates over a sequence of Int64 values.
70     /// </summary>
71     [EditorBrowsable(EditorBrowsableState.Never)]
72     public struct Int64Aggregator {
73         private long result;
74         private int cnt;
75
76         public void Create() {
77             this.cnt = 0;
78         }
79
80         public void Sum(long value) {
81             if (this.cnt == 0) {
82                 this.result = value;
83                 this.cnt = 1;
84             }
85             else {
86                 this.result += value;
87             }
88         }
89
90         public void Average(long value) {
91             if (this.cnt == 0)
92                 this.result = value;
93             else
94                 this.result += value;
95
96             this.cnt++;
97         }
98
99         public void Minimum(long value) {
100             if (this.cnt == 0 || value < this.result)
101                 this.result = value;
102
103             this.cnt = 1;
104         }
105
106         public void Maximum(long value) {
107             if (this.cnt == 0 || value > this.result)
108                 this.result = value;
109
110             this.cnt = 1;
111         }
112
113         public long SumResult { get { return this.result; } }
114         public long AverageResult { get { return this.result / (long) this.cnt; } }
115         public long MinimumResult { get { return this.result; } }
116         public long MaximumResult { get { return this.result; } }
117
118         public bool IsEmpty { get { return this.cnt == 0; } }
119     }
120
121
122     /// <summary>
123     /// Computes aggregates over a sequence of Decimal values.
124     /// </summary>
125     [EditorBrowsable(EditorBrowsableState.Never)]
126     public struct DecimalAggregator {
127         private decimal result;
128         private int cnt;
129
130         public void Create() {
131             this.cnt = 0;
132         }
133
134         public void Sum(decimal value) {
135             if (this.cnt == 0) {
136                 this.result = value;
137                 this.cnt = 1;
138             }
139             else {
140                 this.result += value;
141             }
142         }
143
144         public void Average(decimal value) {
145             if (this.cnt == 0)
146                 this.result = value;
147             else
148                 this.result += value;
149
150             this.cnt++;
151         }
152
153         public void Minimum(decimal value) {
154             if (this.cnt == 0 || value < this.result)
155                 this.result = value;
156
157             this.cnt = 1;
158         }
159
160         public void Maximum(decimal value) {
161             if (this.cnt == 0 || value > this.result)
162                 this.result = value;
163
164             this.cnt = 1;
165         }
166
167         public decimal SumResult { get { return this.result; } }
168         public decimal AverageResult { get { return this.result / (decimal) this.cnt; } }
169         public decimal MinimumResult { get { return this.result; } }
170         public decimal MaximumResult { get { return this.result; } }
171
172         public bool IsEmpty { get { return this.cnt == 0; } }
173     }
174
175
176     /// <summary>
177     /// Computes aggregates over a sequence of Double values.
178     /// </summary>
179     [EditorBrowsable(EditorBrowsableState.Never)]
180     public struct DoubleAggregator {
181         private double result;
182         private int cnt;
183
184         public void Create() {
185             this.cnt = 0;
186         }
187
188         public void Sum(double value) {
189             if (this.cnt == 0) {
190                 this.result = value;
191                 this.cnt = 1;
192             }
193             else {
194                 this.result += value;
195             }
196         }
197
198         public void Average(double value) {
199             if (this.cnt == 0)
200                 this.result = value;
201             else
202                 this.result += value;
203
204             this.cnt++;
205         }
206
207         public void Minimum(double value) {
208             if (this.cnt == 0 || value < this.result || double.IsNaN(value))
209                 this.result = value;
210
211             this.cnt = 1;
212         }
213
214         public void Maximum(double value) {
215             if (this.cnt == 0 || value > this.result || double.IsNaN(value))
216                 this.result = value;
217
218             this.cnt = 1;
219         }
220
221         public double SumResult { get { return this.result; } }
222         public double AverageResult { get { return this.result / (double) this.cnt; } }
223         public double MinimumResult { get { return this.result; } }
224         public double MaximumResult { get { return this.result; } }
225
226         public bool IsEmpty { get { return this.cnt == 0; } }
227     }
228 }