1 16 package org.apache.commons.math.stat.descriptive.rank; 17 18 import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; 19 20 37 public class Max extends AbstractStorelessUnivariateStatistic { 38 39 40 static final long serialVersionUID = -5593383832225844641L; 41 42 43 private long n; 44 45 46 private double value; 47 48 51 public Max() { 52 n = 0; 53 value = Double.NaN; 54 } 55 56 59 public void increment(final double d) { 60 if (d > value || Double.isNaN(value)) { 61 value = d; 62 } 63 n++; 64 } 65 66 69 public void clear() { 70 value = Double.NaN; 71 n = 0; 72 } 73 74 77 public double getResult() { 78 return value; 79 } 80 81 84 public long getN() { 85 return n; 86 } 87 88 110 public double evaluate(final double[] values, final int begin, final int length) { 111 double max = Double.NaN; 112 if (test(values, begin, length)) { 113 max = values[begin]; 114 for (int i = begin; i < begin + length; i++) { 115 max = (max > values[i]) ? max : values[i]; 116 } 117 } 118 return max; 119 } 120 } | Popular Tags |