1 16 package org.apache.commons.math.stat.descriptive; 17 18 import java.io.Serializable ; 19 20 33 public abstract class AbstractUnivariateStatistic 34 implements UnivariateStatistic, Serializable { 35 36 37 static final long serialVersionUID = -8007759382851708045L; 38 39 42 public double evaluate(final double[] values) { 43 test(values, 0, 0); 44 return evaluate(values, 0, values.length); 45 } 46 47 50 public abstract double evaluate(final double[] values, final int begin, final int length); 51 52 71 protected boolean test( 72 final double[] values, 73 final int begin, 74 final int length) { 75 76 if (values == null) { 77 throw new IllegalArgumentException ("input value array is null"); 78 } 79 80 if (begin < 0) { 81 throw new IllegalArgumentException ("start position cannot be negative"); 82 } 83 84 if (length < 0) { 85 throw new IllegalArgumentException ("length cannot be negative"); 86 } 87 88 if (begin + length > values.length) { 89 throw new IllegalArgumentException ( 90 "begin + length > values.length"); 91 } 92 93 if (length == 0) { 94 return false; 95 } 96 97 return true; 98 99 } 100 } | Popular Tags |