1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.math4.legacy.stat.descriptive;
18
19 import org.apache.commons.math4.core.jdkmath.JdkMath;
20 import org.apache.commons.numbers.core.Precision;
21
22
23
24
25
26 public class StatisticalSummaryValues
27 implements StatisticalSummary {
28
29 private final double mean;
30
31
32 private final double variance;
33
34
35 private final long n;
36
37
38 private final double max;
39
40
41 private final double min;
42
43
44 private final double sum;
45
46
47
48
49
50
51
52
53
54
55
56 public StatisticalSummaryValues(double mean, double variance, long n,
57 double max, double min, double sum) {
58 super();
59 this.mean = mean;
60 this.variance = variance;
61 this.n = n;
62 this.max = max;
63 this.min = min;
64 this.sum = sum;
65 }
66
67
68
69
70 @Override
71 public double getMax() {
72 return max;
73 }
74
75
76
77
78 @Override
79 public double getMean() {
80 return mean;
81 }
82
83
84
85
86 @Override
87 public double getMin() {
88 return min;
89 }
90
91
92
93
94 @Override
95 public long getN() {
96 return n;
97 }
98
99
100
101
102 @Override
103 public double getSum() {
104 return sum;
105 }
106
107
108
109
110 @Override
111 public double getStandardDeviation() {
112 return JdkMath.sqrt(variance);
113 }
114
115
116
117
118 @Override
119 public double getVariance() {
120 return variance;
121 }
122
123
124
125
126
127
128
129
130
131 @Override
132 public boolean equals(Object object) {
133 if (object == this ) {
134 return true;
135 }
136 if (!(object instanceof StatisticalSummaryValues)) {
137 return false;
138 }
139 StatisticalSummaryValues stat = (StatisticalSummaryValues) object;
140 return Precision.equalsIncludingNaN(stat.getMax(), getMax()) &&
141 Precision.equalsIncludingNaN(stat.getMean(), getMean()) &&
142 Precision.equalsIncludingNaN(stat.getMin(), getMin()) &&
143 Precision.equalsIncludingNaN(stat.getN(), getN()) &&
144 Precision.equalsIncludingNaN(stat.getSum(), getSum()) &&
145 Precision.equalsIncludingNaN(stat.getVariance(), getVariance());
146 }
147
148
149
150
151
152
153 @Override
154 public int hashCode() {
155 int result = 31 + Double.hashCode(getMax());
156 result = result * 31 + Double.hashCode(getMean());
157 result = result * 31 + Double.hashCode(getMin());
158 result = result * 31 + Double.hashCode(getN());
159 result = result * 31 + Double.hashCode(getSum());
160 result = result * 31 + Double.hashCode(getVariance());
161 return result;
162 }
163
164
165
166
167
168
169
170 @Override
171 public String toString() {
172 StringBuffer outBuffer = new StringBuffer();
173 String endl = "\n";
174 outBuffer.append("StatisticalSummaryValues:").append(endl);
175 outBuffer.append("n: ").append(getN()).append(endl);
176 outBuffer.append("min: ").append(getMin()).append(endl);
177 outBuffer.append("max: ").append(getMax()).append(endl);
178 outBuffer.append("mean: ").append(getMean()).append(endl);
179 outBuffer.append("std dev: ").append(getStandardDeviation())
180 .append(endl);
181 outBuffer.append("variance: ").append(getVariance()).append(endl);
182 outBuffer.append("sum: ").append(getSum()).append(endl);
183 return outBuffer.toString();
184 }
185 }