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.math4.legacy.stat.descriptive;
018
019import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
020import org.apache.commons.math4.legacy.exception.MathIllegalStateException;
021import org.apache.commons.math4.legacy.linear.RealMatrix;
022
023/**
024 * Implementation of
025 * {@link org.apache.commons.math4.legacy.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     * Construct a SynchronizedMultivariateSummaryStatistics instance.
038     * @param k dimension of the data
039     * @param isCovarianceBiasCorrected if true, the unbiased sample
040     * covariance is computed, otherwise the biased population covariance
041     * is computed
042     */
043    public SynchronizedMultivariateSummaryStatistics(int k, boolean isCovarianceBiasCorrected) {
044        super(k, isCovarianceBiasCorrected);
045    }
046
047    /**
048     * {@inheritDoc}
049     */
050    @Override
051    public synchronized void addValue(double[] value) throws DimensionMismatchException {
052      super.addValue(value);
053    }
054
055    /**
056     * {@inheritDoc}
057     */
058    @Override
059    public synchronized int getDimension() {
060        return super.getDimension();
061    }
062
063    /**
064     * {@inheritDoc}
065     */
066    @Override
067    public synchronized long getN() {
068        return super.getN();
069    }
070
071    /**
072     * {@inheritDoc}
073     */
074    @Override
075    public synchronized double[] getSum() {
076        return super.getSum();
077    }
078
079    /**
080     * {@inheritDoc}
081     */
082    @Override
083    public synchronized double[] getSumSq() {
084        return super.getSumSq();
085    }
086
087    /**
088     * {@inheritDoc}
089     */
090    @Override
091    public synchronized double[] getSumLog() {
092        return super.getSumLog();
093    }
094
095    /**
096     * {@inheritDoc}
097     */
098    @Override
099    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}