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.math3.stat.descriptive;
018
019import org.apache.commons.math3.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.</p>
029 *
030 */
031public interface StorelessUnivariateStatistic extends UnivariateStatistic {
032
033    /**
034     * Updates the internal state of the statistic to reflect the addition of the new value.
035     * @param d  the new value.
036     */
037    void increment(double d);
038
039    /**
040     * Updates the internal state of the statistic to reflect addition of
041     * all values in the values array.  Does not clear the statistic first --
042     * i.e., the values are added <strong>incrementally</strong> to the dataset.
043     *
044     * @param values  array holding the new values to add
045     * @throws MathIllegalArgumentException if the array is null
046     */
047    void incrementAll(double[] values) throws MathIllegalArgumentException;
048
049    /**
050     * Updates the internal state of the statistic to reflect addition of
051     * the values in the designated portion of the values array.  Does not
052     * clear the statistic first -- i.e., the values are added
053     * <strong>incrementally</strong> to the dataset.
054     *
055     * @param values  array holding the new values to add
056     * @param start  the array index of the first value to add
057     * @param length  the number of elements to add
058     * @throws MathIllegalArgumentException if the array is null or the index
059     */
060    void incrementAll(double[] values, int start, int length) throws MathIllegalArgumentException;
061
062    /**
063     * Returns the current value of the Statistic.
064     * @return value of the statistic, <code>Double.NaN</code> if it
065     * has been cleared or just instantiated.
066     */
067    double getResult();
068
069    /**
070     * Returns the number of values that have been added.
071     * @return the number of values.
072     */
073    long getN();
074
075    /**
076     * Clears the internal state of the Statistic
077     */
078    void clear();
079
080    /**
081     * Returns a copy of the statistic with the same internal state.
082     *
083     * @return a copy of the statistic
084     */
085    StorelessUnivariateStatistic copy();
086
087}