1 16 package org.apache.commons.math.stat.descriptive; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.discovery.tools.DiscoverClass; 21 import org.apache.commons.math.util.MathUtils; 22 23 28 public abstract class SummaryStatistics implements StatisticalSummary, Serializable { 29 30 31 static final long serialVersionUID = -6400596334135654825L; 32 33 44 public static SummaryStatistics newInstance(Class cls) throws 45 InstantiationException , IllegalAccessException { 46 return (SummaryStatistics)cls.newInstance(); 47 } 48 49 54 public static SummaryStatistics newInstance() { 55 SummaryStatistics instance = null; 56 try { 57 DiscoverClass dc = new DiscoverClass(); 58 instance = (SummaryStatistics) dc.newInstance( 59 SummaryStatistics.class, 60 "org.apache.commons.math.stat.descriptive.SummaryStatisticsImpl"); 61 } catch(Throwable t) { 62 return new SummaryStatisticsImpl(); 63 } 64 return instance; 65 } 66 67 68 74 public StatisticalSummary getSummary() { 75 return new StatisticalSummaryValues(getMean(), getVariance(), getN(), 76 getMax(), getMin(), getSum()); 77 } 78 79 83 public abstract void addValue(double v); 84 85 90 public abstract double getMean(); 91 92 98 public abstract double getGeometricMean(); 99 100 105 public abstract double getVariance(); 106 107 112 public abstract double getStandardDeviation(); 113 114 118 public abstract double getMax(); 119 120 124 public abstract double getMin(); 125 126 130 public abstract long getN(); 131 132 136 public abstract double getSum(); 137 138 143 public abstract double getSumsq(); 144 145 148 public abstract void clear(); 149 150 156 public boolean equals(Object object) { 157 if (object == this ) { 158 return true; 159 } 160 if (object instanceof SummaryStatistics == false) { 161 return false; 162 } 163 SummaryStatistics stat = (SummaryStatistics) object; 164 return (MathUtils.equals(stat.getGeometricMean(), 165 this.getGeometricMean()) && 166 MathUtils.equals(stat.getMax(), this.getMax()) && 167 MathUtils.equals(stat.getMean(),this.getMean()) && 168 MathUtils.equals(stat.getMin(),this.getMin()) && 169 MathUtils.equals(stat.getN(), this.getN()) && 170 MathUtils.equals(stat.getSum(), this.getSum()) && 171 MathUtils.equals(stat.getSumsq(),this.getSumsq()) && 172 MathUtils.equals(stat.getVariance(),this.getVariance())); 173 } 174 175 180 public int hashCode() { 181 int result = 31 + MathUtils.hash(getGeometricMean()); 182 result = result * 31 + MathUtils.hash(getGeometricMean()); 183 result = result * 31 + MathUtils.hash(getMax()); 184 result = result * 31 + MathUtils.hash(getMean()); 185 result = result * 31 + MathUtils.hash(getMin()); 186 result = result * 31 + MathUtils.hash(getN()); 187 result = result * 31 + MathUtils.hash(getSum()); 188 result = result * 31 + MathUtils.hash(getSumsq()); 189 result = result * 31 + MathUtils.hash(getVariance()); 190 return result; 191 } 192 193 } 194 | Popular Tags |