1 16 package org.apache.commons.math.stat.descriptive; 17 18 import org.apache.commons.math.util.MathUtils; 19 import java.io.Serializable ; 20 21 32 public abstract class AbstractStorelessUnivariateStatistic 33 extends AbstractUnivariateStatistic 34 implements StorelessUnivariateStatistic, Serializable { 35 36 37 static final long serialVersionUID = -44915725420072521L; 38 39 55 public double evaluate(final double[] values) { 56 if (values == null) { 57 throw new IllegalArgumentException ("input value array is null"); 58 } 59 return evaluate(values, 0, values.length); 60 } 61 62 79 public double evaluate(final double[] values, final int begin, final int length) { 80 if (test(values, begin, length)) { 81 clear(); 82 incrementAll(values, begin, length); 83 } 84 return getResult(); 85 } 86 87 90 public abstract void clear(); 91 92 95 public abstract double getResult(); 96 97 100 public abstract void increment(final double d); 101 102 112 public void incrementAll(double[] values) { 113 if (values == null) { 114 throw new IllegalArgumentException ("input values array is null"); 115 } 116 incrementAll(values, 0, values.length); 117 } 118 119 131 public void incrementAll(double[] values, int begin, int length) { 132 if (test(values, begin, length)) { 133 int k = begin + length; 134 for (int i = begin; i < k; i++) { 135 increment(values[i]); 136 } 137 } 138 } 139 140 147 public boolean equals(Object object) { 148 if (object == this ) { 149 return true; 150 } 151 if (object instanceof AbstractStorelessUnivariateStatistic == false) { 152 return false; 153 } 154 AbstractStorelessUnivariateStatistic stat = (AbstractStorelessUnivariateStatistic) object; 155 return (MathUtils.equals(stat.getResult(), this.getResult()) && 156 MathUtils.equals(stat.getN(), this.getN())); 157 } 158 159 164 public int hashCode() { 165 return 31* (31 + MathUtils.hash(getResult())) + MathUtils.hash(getN()); 166 } 167 168 } | Popular Tags |