Author: brentworden
Date: Tue Oct 30 22:41:18 2007
New Revision: 590566

URL: http://svn.apache.org/viewvc?rev=590566&view=rev
Log:
MATH-170.  added SynchronizedDescriptiveStatistics class.

Added:
    
commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatistics.java
    
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatisticsTest.java

Added: 
commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatistics.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatistics.java?rev=590566&view=auto
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatistics.java
 (added)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatistics.java
 Tue Oct 30 22:41:18 2007
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.stat.descriptive;
+
+/**
+ * Implementation of
+ * [EMAIL PROTECTED] 
org.apache.commons.math.stat.descriptive.DescriptiveStatistics} that
+ * is safe to use in a mulithreaded environment.  Multiple threads can safely
+ * operate on a single instance without causing runtime exceptions due to race
+ * conditions.  In effect, this implementation makes modification and access
+ * methods atomic operations for a signle instance.  That is to say, as one
+ * thread is computing a statistic from the instance, no other thread can 
modify
+ * the instance nor compute another statistic. 
+ *
+ * @version $Revision: 480440 $ $Date: 2006-11-29 01:14:12 -0600 (Wed, 29 Nov 
2006) $
+ */
+public class SynchronizedDescriptiveStatistics extends 
DescriptiveStatisticsImpl {
+
+    /** Serialization UID */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Construct an instance with infinite window
+     */
+    public SynchronizedDescriptiveStatistics() {
+        this(INFINITE_WINDOW);
+    }
+
+    /**
+     * Construct an instance with finite window
+     * @param window the finite window size.
+     */
+    public SynchronizedDescriptiveStatistics(int window) {
+        super(window);
+    }
+
+    /**
+     * @see 
org.apache.commons.math.stat.descriptive.DescriptiveStatistics#addValue(double)
+     */
+    public synchronized void addValue(double v) {
+        super.addValue(v);
+    }
+
+    /**
+     * Apply the given statistic to this univariate collection.
+     * @param stat the statistic to apply
+     * @return the computed value of the statistic.
+     */
+    public synchronized double apply(UnivariateStatistic stat) {
+        return super.apply(stat);
+    }
+
+    /**
+     * @see 
org.apache.commons.math.stat.descriptive.DescriptiveStatistics#clear()
+     */
+    public synchronized void clear() {
+        super.clear();
+    }
+
+    /**
+     * @see 
org.apache.commons.math.stat.descriptive.DescriptiveStatistics#getElement(int)
+     */
+    public synchronized double getElement(int index) {
+        return super.getElement(index);
+    }
+
+    /**
+     * @see 
org.apache.commons.math.stat.descriptive.DescriptiveStatistics#getN()
+     */
+    public synchronized long getN() {
+        return super.getN();
+    }
+
+    /** 
+     * Returns the standard deviation of the available values.
+     * @return The standard deviation, Double.NaN if no values have been added 
+     * or 0.0 for a single value set. 
+     */
+    public synchronized double getStandardDeviation() {
+        return super.getStandardDeviation();
+    }
+
+    /**
+     * @see 
org.apache.commons.math.stat.descriptive.DescriptiveStatistics#getValues()
+     */
+    public synchronized double[] getValues() {
+        return super.getValues();
+    }
+
+    /**
+     * Access the window size.
+     * @return the current window size.
+     */
+    public synchronized int getWindowSize() {
+        return super.getWindowSize();
+    }
+
+    /**
+     * @see 
org.apache.commons.math.stat.descriptive.DescriptiveStatistics#setWindowSize(int)
+     */
+    public synchronized void setWindowSize(int windowSize) {
+        super.setWindowSize(windowSize);
+    }
+
+    /**
+     * Generates a text report displaying univariate statistics from values
+     * that have been added.  Each statistic is displayed on a separate
+     * line.
+     * 
+     * @return String with line feeds displaying statistics
+     */
+    public synchronized String toString() {
+        return super.toString();
+    }
+}

Added: 
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatisticsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatisticsTest.java?rev=590566&view=auto
==============================================================================
--- 
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatisticsTest.java
 (added)
+++ 
commons/proper/math/trunk/src/test/org/apache/commons/math/stat/descriptive/SynchronizedDescriptiveStatisticsTest.java
 Tue Oct 30 22:41:18 2007
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.apache.commons.math.stat.descriptive;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test cases for the [EMAIL PROTECTED] SynchronizedDescriptiveStatisticsTest} 
class.
+ * @version $Revision: 566833 $ $Date: 2007-08-16 15:36:33 -0500 (Thu, 16 Aug
+ *          2007) $
+ */
+public final class SynchronizedDescriptiveStatisticsTest extends 
DescriptiveStatisticsTest {
+
+    public SynchronizedDescriptiveStatisticsTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new 
TestSuite(SynchronizedDescriptiveStatisticsTest.class);
+        suite.setName("SynchronizedDescriptiveStatistics Tests");
+        return suite;
+    }
+
+    protected DescriptiveStatistics createDescriptiveStatistics() {
+        return new SynchronizedDescriptiveStatistics();
+    }
+}


Reply via email to