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.DimensionMismatchException;
020import org.apache.commons.math3.exception.MathIllegalStateException;
021import org.apache.commons.math3.linear.RealMatrix;
022
023/**
024 * Implementation of
025 * {@link org.apache.commons.math3.stat.descriptive.MultivariateSummaryStatistics} that
026 * is safe to use in a multithreaded environment.  Multiple threads can safely
027 * operate on a single instance without causing runtime exceptions due to race
028 * conditions.  In effect, this implementation makes modification and access
029 * methods atomic operations for a single instance.  That is to say, as one
030 * thread is computing a statistic from the instance, no other thread can modify
031 * the instance nor compute another statistic.
032 * @since 1.2
033 */
034public class SynchronizedMultivariateSummaryStatistics
035    extends MultivariateSummaryStatistics {
036
037    /** Serialization UID */
038    private static final long serialVersionUID = 7099834153347155363L;
039
040    /**
041     * Construct a SynchronizedMultivariateSummaryStatistics instance
042     * @param k dimension of the data
043     * @param isCovarianceBiasCorrected if true, the unbiased sample
044     * covariance is computed, otherwise the biased population covariance
045     * is computed
046     */
047    public SynchronizedMultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
048        super(k, isCovarianceBiasCorrected);
049    }
050
051    /**
052     * {@inheritDoc}
053     */
054    @Override
055    public synchronized void addValue(double[] value) throws DimensionMismatchException {
056      super.addValue(value);
057    }
058
059    /**
060     * {@inheritDoc}
061     */
062    @Override
063    public synchronized int getDimension() {
064        return super.getDimension();
065    }
066
067    /**
068     * {@inheritDoc}
069     */
070    @Override
071    public synchronized long getN() {
072        return super.getN();
073    }
074
075    /**
076     * {@inheritDoc}
077     */
078    @Override
079    public synchronized double[] getSum() {
080        return super.getSum();
081    }
082
083    /**
084     * {@inheritDoc}
085     */
086    @Override
087    public synchronized double[] getSumSq() {
088        return super.getSumSq();
089    }
090
091    /**
092     * {@inheritDoc}
093     */
094    @Override
095    public synchronized double[] getSumLog() {
096        return super.getSumLog();
097    }
098
099    /**
100     * {@inheritDoc}
101     */
102    @Override
103    public synchronized double[] getMean() {
104        return super.getMean();
105    }
106
107    /**
108     * {@inheritDoc}
109     */
110    @Override
111    public synchronized double[] getStandardDeviation() {
112        return super.getStandardDeviation();
113    }
114
115    /**
116     * {@inheritDoc}
117     */
118    @Override
119    public synchronized RealMatrix getCovariance() {
120        return super.getCovariance();
121    }
122
123    /**
124     * {@inheritDoc}
125     */
126    @Override
127    public synchronized double[] getMax() {
128        return super.getMax();
129    }
130
131    /**
132     * {@inheritDoc}
133     */
134    @Override
135    public synchronized double[] getMin() {
136        return super.getMin();
137    }
138
139    /**
140     * {@inheritDoc}
141     */
142    @Override
143    public synchronized double[] getGeometricMean() {
144        return super.getGeometricMean();
145    }
146
147    /**
148     * {@inheritDoc}
149     */
150    @Override
151    public synchronized String toString() {
152        return super.toString();
153    }
154
155    /**
156     * {@inheritDoc}
157     */
158    @Override
159    public synchronized void clear() {
160        super.clear();
161    }
162
163    /**
164     * {@inheritDoc}
165     */
166    @Override
167    public synchronized boolean equals(Object object) {
168        return super.equals(object);
169    }
170
171    /**
172     * {@inheritDoc}
173     */
174    @Override
175    public synchronized int hashCode() {
176        return super.hashCode();
177    }
178
179    /**
180     * {@inheritDoc}
181     */
182    @Override
183    public synchronized StorelessUnivariateStatistic[] getSumImpl() {
184        return super.getSumImpl();
185    }
186
187    /**
188     * {@inheritDoc}
189     */
190    @Override
191    public synchronized void setSumImpl(StorelessUnivariateStatistic[] sumImpl)
192    throws DimensionMismatchException, MathIllegalStateException {
193        super.setSumImpl(sumImpl);
194    }
195
196    /**
197     * {@inheritDoc}
198     */
199    @Override
200    public synchronized StorelessUnivariateStatistic[] getSumsqImpl() {
201        return super.getSumsqImpl();
202    }
203
204    /**
205     * {@inheritDoc}
206     */
207    @Override
208    public synchronized void setSumsqImpl(StorelessUnivariateStatistic[] sumsqImpl)
209    throws DimensionMismatchException, MathIllegalStateException {
210        super.setSumsqImpl(sumsqImpl);
211    }
212
213    /**
214     * {@inheritDoc}
215     */
216    @Override
217    public synchronized StorelessUnivariateStatistic[] getMinImpl() {
218        return super.getMinImpl();
219    }
220
221    /**
222     * {@inheritDoc}
223     */
224    @Override
225    public synchronized void setMinImpl(StorelessUnivariateStatistic[] minImpl)
226    throws DimensionMismatchException, MathIllegalStateException {
227        super.setMinImpl(minImpl);
228    }
229
230    /**
231     * {@inheritDoc}
232     */
233    @Override
234    public synchronized StorelessUnivariateStatistic[] getMaxImpl() {
235        return super.getMaxImpl();
236    }
237
238    /**
239     * {@inheritDoc}
240     */
241    @Override
242    public synchronized void setMaxImpl(StorelessUnivariateStatistic[] maxImpl)
243    throws DimensionMismatchException, MathIllegalStateException{
244        super.setMaxImpl(maxImpl);
245    }
246
247    /**
248     * {@inheritDoc}
249     */
250    @Override
251    public synchronized StorelessUnivariateStatistic[] getSumLogImpl() {
252        return super.getSumLogImpl();
253    }
254
255    /**
256     * {@inheritDoc}
257     */
258    @Override
259    public synchronized void setSumLogImpl(StorelessUnivariateStatistic[] sumLogImpl)
260    throws DimensionMismatchException, MathIllegalStateException {
261        super.setSumLogImpl(sumLogImpl);
262    }
263
264    /**
265     * {@inheritDoc}
266     */
267    @Override
268    public synchronized StorelessUnivariateStatistic[] getGeoMeanImpl() {
269        return super.getGeoMeanImpl();
270    }
271
272    /**
273     * {@inheritDoc}
274     */
275    @Override
276    public synchronized void setGeoMeanImpl(StorelessUnivariateStatistic[] geoMeanImpl)
277    throws DimensionMismatchException, MathIllegalStateException {
278        super.setGeoMeanImpl(geoMeanImpl);
279    }
280
281    /**
282     * {@inheritDoc}
283     */
284    @Override
285    public synchronized StorelessUnivariateStatistic[] getMeanImpl() {
286        return super.getMeanImpl();
287    }
288
289    /**
290     * {@inheritDoc}
291     */
292    @Override
293    public synchronized void setMeanImpl(StorelessUnivariateStatistic[] meanImpl)
294    throws DimensionMismatchException, MathIllegalStateException {
295        super.setMeanImpl(meanImpl);
296    }
297}