1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.math4.legacy.stat.descriptive;
18
19 import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
20 import org.apache.commons.math4.legacy.exception.NotPositiveException;
21 import org.apache.commons.math4.legacy.exception.NullArgumentException;
22 import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
23 import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
24 import org.apache.commons.math4.legacy.core.MathArrays;
25
26
27
28
29
30
31
32 public abstract class AbstractUnivariateStatistic
33 implements UnivariateStatistic {
34
35
36 private double[] storedData;
37
38
39
40
41 @Override
42 public double evaluate(final double[] values) throws MathIllegalArgumentException {
43 MathArrays.verifyValues(values, 0, 0);
44 return evaluate(values, 0, values.length);
45 }
46
47
48
49
50 @Override
51 public abstract double evaluate(double[] values, int begin, int length)
52 throws MathIllegalArgumentException;
53
54
55
56
57 @Override
58 public abstract UnivariateStatistic copy();
59
60
61
62
63
64
65
66
67
68 public void setData(final double[] values) {
69 storedData = (values == null) ? null : values.clone();
70 }
71
72
73
74
75
76 public double[] getData() {
77 return (storedData == null) ? null : storedData.clone();
78 }
79
80
81
82
83
84 protected double[] getDataRef() {
85 return storedData;
86 }
87
88
89
90
91
92
93
94
95
96
97
98 public void setData(final double[] values, final int begin, final int length)
99 throws MathIllegalArgumentException {
100 if (values == null) {
101 throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
102 }
103
104 if (begin < 0) {
105 throw new NotPositiveException(LocalizedFormats.START_POSITION, begin);
106 }
107
108 if (length < 0) {
109 throw new NotPositiveException(LocalizedFormats.LENGTH, length);
110 }
111
112 if (begin + length > values.length) {
113 throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END,
114 begin + length, values.length, true);
115 }
116 storedData = new double[length];
117 System.arraycopy(values, begin, storedData, 0, length);
118 }
119
120
121
122
123
124
125
126
127
128 public double evaluate() throws MathIllegalArgumentException {
129 return evaluate(storedData);
130 }
131 }