1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.math.stat.descriptive;
17
18 import java.io.Serializable;
19 import org.apache.commons.math.util.MathUtils;
20
21 /**
22 * Value object representing the results of a univariate statistical summary.
23 *
24 * @version $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $
25 */
26 public class StatisticalSummaryValues implements Serializable,
27 StatisticalSummary {
28
29 /** Serialization id */
30 private static final long serialVersionUID = -5108854841843722536L;
31
32 /** The sample mean */
33 private final double mean;
34
35 /** The sample variance */
36 private final double variance;
37
38 /** The number of observations in the sample */
39 private final long n;
40
41 /** The maximum value */
42 private final double max;
43
44 /** The minimum value */
45 private final double min;
46
47 /** The sum of the sample values */
48 private final double sum;
49
50 /**
51 * Constructor
52 *
53 * @param mean the sample mean
54 * @param variance the sample variance
55 * @param n the number of observations in the sample
56 * @param max the maximum value
57 * @param min the minimum value
58 * @param sum the sum of the values
59 */
60 public StatisticalSummaryValues(double mean, double variance, long n,
61 double max, double min, double sum) {
62 super();
63 this.mean = mean;
64 this.variance = variance;
65 this.n = n;
66 this.max = max;
67 this.min = min;
68 this.sum = sum;
69 }
70
71 /**
72 * @return Returns the max.
73 */
74 public double getMax() {
75 return max;
76 }
77
78 /**
79 * @return Returns the mean.
80 */
81 public double getMean() {
82 return mean;
83 }
84
85 /**
86 * @return Returns the min.
87 */
88 public double getMin() {
89 return min;
90 }
91
92 /**
93 * @return Returns the number of values.
94 */
95 public long getN() {
96 return n;
97 }
98
99 /**
100 * @return Returns the sum.
101 */
102 public double getSum() {
103 return sum;
104 }
105
106 /**
107 * @return Returns the standard deviation
108 */
109 public double getStandardDeviation() {
110 return Math.sqrt(variance);
111 }
112
113 /**
114 * @return Returns the variance.
115 */
116 public double getVariance() {
117 return variance;
118 }
119
120 /**
121 * Returns true iff <code>object</code> is a
122 * <code>StatisticalSummaryValues</code> instance and all statistics have
123 * the same values as this.
124 *
125 * @param object the object to test equality against.
126 * @return true if object equals this
127 */
128 public boolean equals(Object object) {
129 if (object == this ) {
130 return true;
131 }
132 if (object instanceof StatisticalSummaryValues == false) {
133 return false;
134 }
135 StatisticalSummaryValues stat = (StatisticalSummaryValues) object;
136 return (MathUtils.equals(stat.getMax(), this.getMax()) &&
137 MathUtils.equals(stat.getMean(),this.getMean()) &&
138 MathUtils.equals(stat.getMin(),this.getMin()) &&
139 MathUtils.equals(stat.getN(), this.getN()) &&
140 MathUtils.equals(stat.getSum(), this.getSum()) &&
141 MathUtils.equals(stat.getVariance(),this.getVariance()));
142 }
143
144 /**
145 * Returns hash code based on values of statistics
146 *
147 * @return hash code
148 */
149 public int hashCode() {
150 int result = 31 + MathUtils.hash(getMax());
151 result = result * 31 + MathUtils.hash(getMean());
152 result = result * 31 + MathUtils.hash(getMin());
153 result = result * 31 + MathUtils.hash(getN());
154 result = result * 31 + MathUtils.hash(getSum());
155 result = result * 31 + MathUtils.hash(getVariance());
156 return result;
157 }
158
159 }