1 //------------------------------------------------------------------------------
2 // <copyright file="XmlAggregates.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
9 using System.Diagnostics;
10 using System.ComponentModel;
12 namespace System.Xml.Xsl.Runtime {
15 /// Computes aggregates over a sequence of Int32 values.
17 [EditorBrowsable(EditorBrowsableState.Never)]
18 public struct Int32Aggregator {
22 public void Create() {
26 public void Sum(int value) {
36 public void Average(int value) {
45 public void Minimum(int value) {
46 if (this.cnt == 0 || value < this.result)
52 public void Maximum(int value) {
53 if (this.cnt == 0 || value > this.result)
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; } }
64 public bool IsEmpty { get { return this.cnt == 0; } }
69 /// Computes aggregates over a sequence of Int64 values.
71 [EditorBrowsable(EditorBrowsableState.Never)]
72 public struct Int64Aggregator {
76 public void Create() {
80 public void Sum(long value) {
90 public void Average(long value) {
99 public void Minimum(long value) {
100 if (this.cnt == 0 || value < this.result)
106 public void Maximum(long value) {
107 if (this.cnt == 0 || value > this.result)
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; } }
118 public bool IsEmpty { get { return this.cnt == 0; } }
123 /// Computes aggregates over a sequence of Decimal values.
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public struct DecimalAggregator {
127 private decimal result;
130 public void Create() {
134 public void Sum(decimal value) {
140 this.result += value;
144 public void Average(decimal value) {
148 this.result += value;
153 public void Minimum(decimal value) {
154 if (this.cnt == 0 || value < this.result)
160 public void Maximum(decimal value) {
161 if (this.cnt == 0 || value > this.result)
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; } }
172 public bool IsEmpty { get { return this.cnt == 0; } }
177 /// Computes aggregates over a sequence of Double values.
179 [EditorBrowsable(EditorBrowsableState.Never)]
180 public struct DoubleAggregator {
181 private double result;
184 public void Create() {
188 public void Sum(double value) {
194 this.result += value;
198 public void Average(double value) {
202 this.result += value;
207 public void Minimum(double value) {
208 if (this.cnt == 0 || value < this.result || double.IsNaN(value))
214 public void Maximum(double value) {
215 if (this.cnt == 0 || value > this.result || double.IsNaN(value))
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; } }
226 public bool IsEmpty { get { return this.cnt == 0; } }