001: /*
002: * Copyright 2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.math.stat.descriptive;
017:
018: import java.io.Serializable;
019: import org.apache.commons.math.util.MathUtils;
020:
021: /**
022: * Value object representing the results of a univariate statistical summary.
023: *
024: * @version $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $
025: */
026: public class StatisticalSummaryValues implements Serializable,
027: StatisticalSummary {
028:
029: /** Serialization id */
030: private static final long serialVersionUID = -5108854841843722536L;
031:
032: /** The sample mean */
033: private final double mean;
034:
035: /** The sample variance */
036: private final double variance;
037:
038: /** The number of observations in the sample */
039: private final long n;
040:
041: /** The maximum value */
042: private final double max;
043:
044: /** The minimum value */
045: private final double min;
046:
047: /** The sum of the sample values */
048: private final double sum;
049:
050: /**
051: * Constructor
052: *
053: * @param mean the sample mean
054: * @param variance the sample variance
055: * @param n the number of observations in the sample
056: * @param max the maximum value
057: * @param min the minimum value
058: * @param sum the sum of the values
059: */
060: public StatisticalSummaryValues(double mean, double variance,
061: long n, double max, double min, double sum) {
062: super ();
063: this .mean = mean;
064: this .variance = variance;
065: this .n = n;
066: this .max = max;
067: this .min = min;
068: this .sum = sum;
069: }
070:
071: /**
072: * @return Returns the max.
073: */
074: public double getMax() {
075: return max;
076: }
077:
078: /**
079: * @return Returns the mean.
080: */
081: public double getMean() {
082: return mean;
083: }
084:
085: /**
086: * @return Returns the min.
087: */
088: public double getMin() {
089: return min;
090: }
091:
092: /**
093: * @return Returns the number of values.
094: */
095: public long getN() {
096: return n;
097: }
098:
099: /**
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()) && MathUtils
141: .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: }
|