001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.math4.stat.descriptive;
018
019import org.apache.commons.math4.exception.MathIllegalArgumentException;
020
021/**
022 * Extends the definition of {@link UnivariateStatistic} with
023 * {@link #increment} and {@link #incrementAll(double[])} methods for adding
024 * values and updating internal state.
025 * <p>
026 * This interface is designed to be used for calculating statistics that can be
027 * computed in one pass through the data without storing the full array of
028 * sample values.
029 * <p>
030 * Note: unless otherwise stated, the {@link #evaluate(double[])} and
031 * {@link #evaluate(double[], int, int)} methods do <b>NOT</b> alter the internal
032 * state of the respective statistic.
033 */
034public interface StorelessUnivariateStatistic extends UnivariateStatistic {
035
036    /**
037     * Updates the internal state of the statistic to reflect the addition of the new value.
038     * @param d  the new value.
039     */
040    void increment(double d);
041
042    /**
043     * Updates the internal state of the statistic to reflect addition of
044     * all values in the values array.  Does not clear the statistic first --
045     * i.e., the values are added <strong>incrementally</strong> to the dataset.
046     *
047     * @param values  array holding the new values to add
048     * @throws MathIllegalArgumentException if the array is null
049     */
050    void incrementAll(double[] values) throws MathIllegalArgumentException;
051
052    /**
053     * Updates the internal state of the statistic to reflect addition of
054     * the values in the designated portion of the values array.  Does not
055     * clear the statistic first -- i.e., the values are added
056     * <strong>incrementally</strong> to the dataset.
057     *
058     * @param values  array holding the new values to add
059     * @param start  the array index of the first value to add
060     * @param length  the number of elements to add
061     * @throws MathIllegalArgumentException if the array is null or the index
062     */
063    void incrementAll(double[] values, int start, int length) throws MathIllegalArgumentException;
064
065    /**
066     * Returns the current value of the Statistic.
067     * @return value of the statistic, <code>Double.NaN</code> if it
068     * has been cleared or just instantiated.
069     */
070    double getResult();
071
072    /**
073     * Returns the number of values that have been added.
074     * @return the number of values.
075     */
076    long getN();
077
078    /**
079     * Clears the internal state of the Statistic
080     */
081    void clear();
082
083    /**
084     * Returns a copy of the statistic with the same internal state.
085     *
086     * @return a copy of the statistic
087     */
088    @Override
089    StorelessUnivariateStatistic copy();
090
091}