001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.math.stat.descriptive; 018 019 import java.io.Serializable; 020 import org.apache.commons.math.util.MathUtils; 021 022 /** 023 * Value object representing the results of a univariate statistical summary. 024 * 025 * @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $ 026 */ 027 public class StatisticalSummaryValues implements Serializable, 028 StatisticalSummary { 029 030 /** Serialization id */ 031 private static final long serialVersionUID = -5108854841843722536L; 032 033 /** The sample mean */ 034 private final double mean; 035 036 /** The sample variance */ 037 private final double variance; 038 039 /** The number of observations in the sample */ 040 private final long n; 041 042 /** The maximum value */ 043 private final double max; 044 045 /** The minimum value */ 046 private final double min; 047 048 /** The sum of the sample values */ 049 private final double sum; 050 051 /** 052 * Constructor 053 * 054 * @param mean the sample mean 055 * @param variance the sample variance 056 * @param n the number of observations in the sample 057 * @param max the maximum value 058 * @param min the minimum value 059 * @param sum the sum of the values 060 */ 061 public StatisticalSummaryValues(double mean, double variance, long n, 062 double max, double min, double sum) { 063 super(); 064 this.mean = mean; 065 this.variance = variance; 066 this.n = n; 067 this.max = max; 068 this.min = min; 069 this.sum = sum; 070 } 071 072 /** 073 * @return Returns the max. 074 */ 075 public double getMax() { 076 return max; 077 } 078 079 /** 080 * @return Returns the mean. 081 */ 082 public double getMean() { 083 return mean; 084 } 085 086 /** 087 * @return Returns the min. 088 */ 089 public double getMin() { 090 return min; 091 } 092 093 /** 094 * @return Returns the number of values. 095 */ 096 public long getN() { 097 return n; 098 } 099 100 /** 101 * @return Returns the sum. 102 */ 103 public double getSum() { 104 return sum; 105 } 106 107 /** 108 * @return Returns the standard deviation 109 */ 110 public double getStandardDeviation() { 111 return Math.sqrt(variance); 112 } 113 114 /** 115 * @return Returns the variance. 116 */ 117 public double getVariance() { 118 return variance; 119 } 120 121 /** 122 * Returns true iff <code>object</code> is a 123 * <code>StatisticalSummaryValues</code> instance and all statistics have 124 * the same values as this. 125 * 126 * @param object the object to test equality against. 127 * @return true if object equals this 128 */ 129 @Override 130 public boolean equals(Object object) { 131 if (object == this ) { 132 return true; 133 } 134 if (object instanceof StatisticalSummaryValues == false) { 135 return false; 136 } 137 StatisticalSummaryValues stat = (StatisticalSummaryValues) object; 138 return (MathUtils.equals(stat.getMax(), this.getMax()) && 139 MathUtils.equals(stat.getMean(),this.getMean()) && 140 MathUtils.equals(stat.getMin(),this.getMin()) && 141 MathUtils.equals(stat.getN(), this.getN()) && 142 MathUtils.equals(stat.getSum(), this.getSum()) && 143 MathUtils.equals(stat.getVariance(),this.getVariance())); 144 } 145 146 /** 147 * Returns hash code based on values of statistics 148 * 149 * @return hash code 150 */ 151 @Override 152 public int hashCode() { 153 int result = 31 + MathUtils.hash(getMax()); 154 result = result * 31 + MathUtils.hash(getMean()); 155 result = result * 31 + MathUtils.hash(getMin()); 156 result = result * 31 + MathUtils.hash(getN()); 157 result = result * 31 + MathUtils.hash(getSum()); 158 result = result * 31 + MathUtils.hash(getVariance()); 159 return result; 160 } 161 162 }