2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.commons.math.stat.descriptive;
19
import org.apache.commons.math.MathRuntimeException;
22
* Abstract base class for all implementations of the
23
* {@link UnivariateStatistic} interface.
25
* Provides a default implementation of <code>evaluate(double[]),</code>
26
* delegating to <code>evaluate(double[], int, int)</code> in the natural way.
29
* Also includes a <code>test</code> method that performs generic parameter
30
* validation for the <code>evaluate</code> methods.</p>
32
* @version $Revision: 780541 $ $Date: 2009-05-31 20:47:02 -0400 (Sun, 31 May 2009) $
34
public abstract class AbstractUnivariateStatistic
35
implements UnivariateStatistic {
40
public double evaluate(final double[] values) {
42
return evaluate(values, 0, values.length);
48
public abstract double evaluate(final double[] values, final int begin, final int length);
53
public abstract UnivariateStatistic copy();
56
* This method is used by <code>evaluate(double[], int, int)</code> methods
57
* to verify that the input parameters designate a subarray of positive length.
60
* <li>returns <code>true</code> iff the parameters designate a subarray of
61
* positive length</li>
62
* <li>throws <code>IllegalArgumentException</code> if the array is null or
63
* or the indices are invalid</li>
64
* <li>returns <code>false</li> if the array is non-null, but
65
* <code>length</code> is 0.
68
* @param values the input array
69
* @param begin index of the first array element to include
70
* @param length the number of elements to include
71
* @return true if the parameters are valid and designate a subarray of positive length
72
* @throws IllegalArgumentException if the indices are invalid or the array is null
74
protected boolean test(
75
final double[] values,
80
throw MathRuntimeException.createIllegalArgumentException("input values array is null");
84
throw MathRuntimeException.createIllegalArgumentException(
85
"start position cannot be negative ({0})", begin);
89
throw MathRuntimeException.createIllegalArgumentException(
90
"length cannot be negative ({0})", length);
93
if (begin + length > values.length) {
94
throw MathRuntimeException.createIllegalArgumentException(
95
"subarray ends after array end");
b'\\ No newline at end of file'