View Javadoc
1   /*
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
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
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.
16   */
17  package org.apache.commons.math4.legacy.stat.descriptive;
18  
19  import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
20  import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
21  import org.apache.commons.math4.legacy.linear.RealMatrix;
22  
23  /**
24   * Implementation of
25   * {@link org.apache.commons.math4.legacy.stat.descriptive.MultivariateSummaryStatistics} that
26   * is safe to use in a multithreaded environment.  Multiple threads can safely
27   * operate on a single instance without causing runtime exceptions due to race
28   * conditions.  In effect, this implementation makes modification and access
29   * methods atomic operations for a single instance.  That is to say, as one
30   * thread is computing a statistic from the instance, no other thread can modify
31   * the instance nor compute another statistic.
32   * @since 1.2
33   */
34  public class SynchronizedMultivariateSummaryStatistics
35      extends MultivariateSummaryStatistics {
36      /**
37       * Construct a SynchronizedMultivariateSummaryStatistics instance.
38       * @param k dimension of the data
39       * @param isCovarianceBiasCorrected if true, the unbiased sample
40       * covariance is computed, otherwise the biased population covariance
41       * is computed
42       */
43      public SynchronizedMultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
44          super(k, isCovarianceBiasCorrected);
45      }
46  
47      /**
48       * {@inheritDoc}
49       */
50      @Override
51      public synchronized void addValue(double[] value) throws DimensionMismatchException {
52        super.addValue(value);
53      }
54  
55      /**
56       * {@inheritDoc}
57       */
58      @Override
59      public synchronized int getDimension() {
60          return super.getDimension();
61      }
62  
63      /**
64       * {@inheritDoc}
65       */
66      @Override
67      public synchronized long getN() {
68          return super.getN();
69      }
70  
71      /**
72       * {@inheritDoc}
73       */
74      @Override
75      public synchronized double[] getSum() {
76          return super.getSum();
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      public synchronized double[] getSumSq() {
84          return super.getSumSq();
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      public synchronized double[] getSumLog() {
92          return super.getSumLog();
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      @Override
99      public synchronized double[] getMean() {
100         return super.getMean();
101     }
102 
103     /**
104      * {@inheritDoc}
105      */
106     @Override
107     public synchronized double[] getStandardDeviation() {
108         return super.getStandardDeviation();
109     }
110 
111     /**
112      * {@inheritDoc}
113      */
114     @Override
115     public synchronized RealMatrix getCovariance() {
116         return super.getCovariance();
117     }
118 
119     /**
120      * {@inheritDoc}
121      */
122     @Override
123     public synchronized double[] getMax() {
124         return super.getMax();
125     }
126 
127     /**
128      * {@inheritDoc}
129      */
130     @Override
131     public synchronized double[] getMin() {
132         return super.getMin();
133     }
134 
135     /**
136      * {@inheritDoc}
137      */
138     @Override
139     public synchronized double[] getGeometricMean() {
140         return super.getGeometricMean();
141     }
142 
143     /**
144      * {@inheritDoc}
145      */
146     @Override
147     public synchronized String toString() {
148         return super.toString();
149     }
150 
151     /**
152      * {@inheritDoc}
153      */
154     @Override
155     public synchronized void clear() {
156         super.clear();
157     }
158 
159     /**
160      * {@inheritDoc}
161      */
162     @Override
163     public synchronized boolean equals(Object object) {
164         return super.equals(object);
165     }
166 
167     /**
168      * {@inheritDoc}
169      */
170     @Override
171     public synchronized int hashCode() {
172         return super.hashCode();
173     }
174 
175     /**
176      * {@inheritDoc}
177      */
178     @Override
179     public synchronized StorelessUnivariateStatistic[] getSumImpl() {
180         return super.getSumImpl();
181     }
182 
183     /**
184      * {@inheritDoc}
185      */
186     @Override
187     public synchronized void setSumImpl(StorelessUnivariateStatistic[] sumImpl)
188     throws DimensionMismatchException, MathIllegalStateException {
189         super.setSumImpl(sumImpl);
190     }
191 
192     /**
193      * {@inheritDoc}
194      */
195     @Override
196     public synchronized StorelessUnivariateStatistic[] getSumsqImpl() {
197         return super.getSumsqImpl();
198     }
199 
200     /**
201      * {@inheritDoc}
202      */
203     @Override
204     public synchronized void setSumsqImpl(StorelessUnivariateStatistic[] sumsqImpl)
205     throws DimensionMismatchException, MathIllegalStateException {
206         super.setSumsqImpl(sumsqImpl);
207     }
208 
209     /**
210      * {@inheritDoc}
211      */
212     @Override
213     public synchronized StorelessUnivariateStatistic[] getMinImpl() {
214         return super.getMinImpl();
215     }
216 
217     /**
218      * {@inheritDoc}
219      */
220     @Override
221     public synchronized void setMinImpl(StorelessUnivariateStatistic[] minImpl)
222     throws DimensionMismatchException, MathIllegalStateException {
223         super.setMinImpl(minImpl);
224     }
225 
226     /**
227      * {@inheritDoc}
228      */
229     @Override
230     public synchronized StorelessUnivariateStatistic[] getMaxImpl() {
231         return super.getMaxImpl();
232     }
233 
234     /**
235      * {@inheritDoc}
236      */
237     @Override
238     public synchronized void setMaxImpl(StorelessUnivariateStatistic[] maxImpl)
239     throws DimensionMismatchException, MathIllegalStateException{
240         super.setMaxImpl(maxImpl);
241     }
242 
243     /**
244      * {@inheritDoc}
245      */
246     @Override
247     public synchronized StorelessUnivariateStatistic[] getSumLogImpl() {
248         return super.getSumLogImpl();
249     }
250 
251     /**
252      * {@inheritDoc}
253      */
254     @Override
255     public synchronized void setSumLogImpl(StorelessUnivariateStatistic[] sumLogImpl)
256     throws DimensionMismatchException, MathIllegalStateException {
257         super.setSumLogImpl(sumLogImpl);
258     }
259 
260     /**
261      * {@inheritDoc}
262      */
263     @Override
264     public synchronized StorelessUnivariateStatistic[] getGeoMeanImpl() {
265         return super.getGeoMeanImpl();
266     }
267 
268     /**
269      * {@inheritDoc}
270      */
271     @Override
272     public synchronized void setGeoMeanImpl(StorelessUnivariateStatistic[] geoMeanImpl)
273     throws DimensionMismatchException, MathIllegalStateException {
274         super.setGeoMeanImpl(geoMeanImpl);
275     }
276 
277     /**
278      * {@inheritDoc}
279      */
280     @Override
281     public synchronized StorelessUnivariateStatistic[] getMeanImpl() {
282         return super.getMeanImpl();
283     }
284 
285     /**
286      * {@inheritDoc}
287      */
288     @Override
289     public synchronized void setMeanImpl(StorelessUnivariateStatistic[] meanImpl)
290     throws DimensionMismatchException, MathIllegalStateException {
291         super.setMeanImpl(meanImpl);
292     }
293 }