1 16 package org.apache.commons.math.stat.descriptive.summary; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; 21 22 35 public class Product extends AbstractStorelessUnivariateStatistic implements Serializable { 36 37 38 static final long serialVersionUID = 2824226005990582538L; 39 40 41 private long n; 42 43 46 private double value; 47 48 51 public Product() { 52 n = 0; 53 value = Double.NaN; 54 } 55 56 59 public void increment(final double d) { 60 if (n == 0) { 61 value = d; 62 } else { 63 value *= d; 64 } 65 n++; 66 } 67 68 71 public double getResult() { 72 return value; 73 } 74 75 78 public long getN() { 79 return n; 80 } 81 82 85 public void clear() { 86 value = Double.NaN; 87 n = 0; 88 } 89 90 104 public double evaluate(final double[] values, final int begin, final int length) { 105 double product = Double.NaN; 106 if (test(values, begin, length)) { 107 product = 1.0; 108 for (int i = begin; i < begin + length; i++) { 109 product *= values[i]; 110 } 111 } 112 return product; 113 } 114 115 } | Popular Tags |