org.apache.commons.math3.stat.descriptive

## Class AbstractUnivariateStatistic

- java.lang.Object
- - org.apache.commons.math3.stat.descriptive.AbstractUnivariateStatistic

- All Implemented Interfaces:
    UnivariateStatistic, MathArrays.Function
  Direct Known Subclasses:
    AbstractStorelessUnivariateStatistic, Percentile, SemiVariance

      public abstract class AbstractUnivariateStatistic
      extends Object
      implements UnivariateStatistic

  Abstract base class for all implementations of the `UnivariateStatistic` interface.

  Provides a default implementation of `evaluate(double[]),` delegating to `evaluate(double[], int, int)` in the natural way.

  Also includes a `test` method that performs generic parameter validation for the `evaluate` methods.

  Version:
    $Id: AbstractUnivariateStatistic.java 1416643 2012-12-03 19:37:14Z tn $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private double[]` | `storedData` Stored data.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractUnivariateStatistic()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract UnivariateStatistic` | `copy()` Returns a copy of the statistic with the same internal state.
    `double` | `evaluate()` Returns the result of evaluating the statistic over the stored data.
    `double` | `evaluate(double[] values)` Returns the result of evaluating the statistic over the input array.
    `abstract double` | `evaluate(double[] values, int begin, int length)` Returns the result of evaluating the statistic over the specified entries in the input array.
    `double[]` | `getData()` Get a copy of the stored data array.
    `protected double[]` | `getDataRef()` Get a reference to the stored data array.
    `void` | `setData(double[] values)` Set the data array.
    `void` | `setData(double[] values, int begin, int length)` Set the data array.
    `protected boolean` | `test(double[] values, double[] weights, int begin, int length)` This method is used by `evaluate(double[], double[], int, int)` methods to verify that the begin and length parameters designate a subarray of positive length and the weights are all non-negative, non-NaN, finite, and not all zero.
    `protected boolean` | `test(double[] values, double[] weights, int begin, int length, boolean allowEmpty)` This method is used by `evaluate(double[], double[], int, int)` methods to verify that the begin and length parameters designate a subarray of positive length and the weights are all non-negative, non-NaN, finite, and not all zero.
    `protected boolean` | `test(double[] values, int begin, int length)` This method is used by `evaluate(double[], int, int)` methods to verify that the input parameters designate a subarray of positive length.
    `protected boolean` | `test(double[] values, int begin, int length, boolean allowEmpty)` This method is used by `evaluate(double[], int, int)` methods to verify that the input parameters designate a subarray of positive length.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### storedData

          private double[] storedData

      Stored data.

  - ### Constructor Detail

    - #### AbstractUnivariateStatistic

          public AbstractUnivariateStatistic()

  - ### Method Detail

    - #### setData

          public void setData(double[] values)

      Set the data array.

      The stored value is a copy of the parameter array, not the array itself.

      Parameters:
        `values` - data array to store (may be null to remove stored data)
      See Also:
        `evaluate()`

    - #### getData

          public double[] getData()

      Get a copy of the stored data array.
      Returns:
        copy of the stored data array (may be null)

    - #### getDataRef

          protected double[] getDataRef()

      Get a reference to the stored data array.
      Returns:
        reference to the stored data array (may be null)

    - #### setData

          public void setData(double[] values,
                     int begin,
                     int length)
                       throws MathIllegalArgumentException

      Set the data array. The input array is copied, not referenced.
      Parameters:
        `values` - data array to store
        `begin` - the index of the first element to include
        `length` - the number of elements to include
      Throws:
        `MathIllegalArgumentException` - if values is null or the indices are not valid
      See Also:
        `evaluate()`

    - #### evaluate

          public double evaluate()
                          throws MathIllegalArgumentException

      Returns the result of evaluating the statistic over the stored data.

      The stored array is the one which was set by previous calls to `setData(double[])`.

      Returns:
        the value of the statistic applied to the stored data
      Throws:
        `MathIllegalArgumentException` - if the stored data array is null

    - #### evaluate

          public double evaluate(double[] values)
                          throws MathIllegalArgumentException

      Returns the result of evaluating the statistic over the input array.
      Specified by:
        `evaluate` in interface `UnivariateStatistic`
      Specified by:
        `evaluate` in interface `MathArrays.Function`
      Parameters:
        `values` - input array
      Returns:
        the value of the statistic applied to the input array
      Throws:
        `MathIllegalArgumentException` - if values is null

    - #### evaluate

          public abstract double evaluate(double[] values,
                        int begin,
                        int length)
                                   throws MathIllegalArgumentException

      Returns the result of evaluating the statistic over the specified entries in the input array.
      Specified by:
        `evaluate` in interface `UnivariateStatistic`
      Specified by:
        `evaluate` in interface `MathArrays.Function`
      Parameters:
        `values` - the input array
        `begin` - the index of the first element to include
        `length` - the number of elements to include
      Returns:
        the value of the statistic applied to the included array entries
      Throws:
        `MathIllegalArgumentException` - if values is null or the indices are invalid

    - #### copy

          public abstract UnivariateStatistic copy()

      Returns a copy of the statistic with the same internal state.
      Specified by:
        `copy` in interface `UnivariateStatistic`
      Returns:
        a copy of the statistic

    - #### test

          protected boolean test(double[] values,
                     int begin,
                     int length)
                          throws MathIllegalArgumentException

      This method is used by `evaluate(double[], int, int)` methods to verify that the input parameters designate a subarray of positive length.

      - returns `true` iff the parameters designate a subarray of positive length
      - throws `MathIllegalArgumentException` if the array is null or or the indices are invalid
      - returns `false`
      if the array is non-null, but `length` is 0.
      Parameters:
        `values` - the input array
        `begin` - index of the first array element to include
        `length` - the number of elements to include
      Returns:
        true if the parameters are valid and designate a subarray of positive length
      Throws:
        `MathIllegalArgumentException` - if the indices are invalid or the array is null

    - #### test

          protected boolean test(double[] values,
                     int begin,
                     int length,
                     boolean allowEmpty)
                          throws MathIllegalArgumentException

      This method is used by `evaluate(double[], int, int)` methods to verify that the input parameters designate a subarray of positive length.

      - returns `true` iff the parameters designate a subarray of non-negative length
      - throws `IllegalArgumentException` if the array is null or or the indices are invalid
      - returns `false`
      if the array is non-null, but `length` is 0 unless `allowEmpty` is `true`
      Parameters:
        `values` - the input array
        `begin` - index of the first array element to include
        `length` - the number of elements to include
        `allowEmpty` - if `true` then zero length arrays are allowed
      Returns:
        true if the parameters are valid
      Throws:
        `MathIllegalArgumentException` - if the indices are invalid or the array is null
      Since:
        3.0

    - #### test

          protected boolean test(double[] values,
                     double[] weights,
                     int begin,
                     int length)
                          throws MathIllegalArgumentException

      This method is used by `evaluate(double[], double[], int, int)` methods to verify that the begin and length parameters designate a subarray of positive length and the weights are all non-negative, non-NaN, finite, and not all zero.

      - returns `true` iff the parameters designate a subarray of positive length and the weights array contains legitimate values.
      - throws `IllegalArgumentException` if any of the following are true:
        - the values array is null
        - the weights array is null
        - the weights array does not have the same length as the values array
        - the weights array contains one or more infinite values
        - the weights array contains one or more NaN values
        - the weights array contains negative values
        - the start and length arguments do not determine a valid array
      - returns `false`
      if the array is non-null, but `length` is 0.
      Parameters:
        `values` - the input array
        `weights` - the weights array
        `begin` - index of the first array element to include
        `length` - the number of elements to include
      Returns:
        true if the parameters are valid and designate a subarray of positive length
      Throws:
        `MathIllegalArgumentException` - if the indices are invalid or the array is null
      Since:
        2.1

    - #### test

          protected boolean test(double[] values,
                     double[] weights,
                     int begin,
                     int length,
                     boolean allowEmpty)
                          throws MathIllegalArgumentException

      This method is used by `evaluate(double[], double[], int, int)` methods to verify that the begin and length parameters designate a subarray of positive length and the weights are all non-negative, non-NaN, finite, and not all zero.

      - returns `true` iff the parameters designate a subarray of non-negative length and the weights array contains legitimate values.
      - throws `MathIllegalArgumentException` if any of the following are true:
        - the values array is null
        - the weights array is null
        - the weights array does not have the same length as the values array
        - the weights array contains one or more infinite values
        - the weights array contains one or more NaN values
        - the weights array contains negative values
        - the start and length arguments do not determine a valid array
      - returns `false`
      if the array is non-null, but `length` is 0 unless `allowEmpty` is `true`.
      Parameters:
        `values` - the input array.
        `weights` - the weights array.
        `begin` - index of the first array element to include.
        `length` - the number of elements to include.
        `allowEmpty` - if `true` than allow zero length arrays to pass.
      Returns:
        `true` if the parameters are valid.
      Throws:
        `NullArgumentException` - if either of the arrays are null
        `MathIllegalArgumentException` - if the array indices are not valid, the weights array contains NaN, infinite or negative elements, or there are no positive weights.
      Since:
        3.0

Copyright (c) 2003-2013 Apache Software Foundation