commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1044981 - in /commons/proper/math: branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/ branches/MATH_2_X/src/site/xdoc/ branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/ trunk/src/main/java/org/apache/commons/math/sta...
Date Mon, 13 Dec 2010 00:43:58 GMT
Author: psteitz
Date: Mon Dec 13 00:43:57 2010
New Revision: 1044981

URL: http://svn.apache.org/viewvc?rev=1044981&view=rev
Log:
Added a getUniqueCount() method to Frequency to return the number of unique
values included in the frequency table.

Reported and patched by Patrick Meyer
JIRA: MATH-414

Modified:
    commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/Frequency.java
    commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml
    commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/FrequencyTest.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/Frequency.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/FrequencyTest.java

Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/Frequency.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/Frequency.java?rev=1044981&r1=1044980&r2=1044981&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/Frequency.java
(original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/Frequency.java
Mon Dec 13 00:43:57 2010
@@ -287,6 +287,16 @@ public class Frequency implements Serial
     public long getCount(char v) {
         return getCount(Character.valueOf(v));
     }
+    
+    /**
+     * Returns the number of values in the frequency table.
+     * 
+     * @return the number of unique values that have been added to the frequency table.
+     * @see #valuesIterator() 
+     */
+    public int getUniqueCount(){
+        return freqTable.keySet().size();
+    }
 
     //-------------------------------------------------------------
 

Modified: commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml?rev=1044981&r1=1044980&r2=1044981&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/branches/MATH_2_X/src/site/xdoc/changes.xml Mon Dec 13 00:43:57 2010
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="2.2" date="TBD" description="TBD">
+      <action dev="psteitz" type="update" issue="MATH-448" due-to="Patrick Meyer">
+        Added a getUniqueCount() method to Frequency to return the number of unique
+        values included in the frequency table.
+      </action>
       <action dev="psteitz" type="fix" issue="MATH-414">
         Modified NormalDistributionImpl.cumulativeProbability to return 0 or 1,
         respectively for values more than 40 standard deviations from the mean.

Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/FrequencyTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/FrequencyTest.java?rev=1044981&r1=1044980&r2=1044981&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/FrequencyTest.java
(original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/FrequencyTest.java
Mon Dec 13 00:43:57 2010
@@ -273,5 +273,15 @@ public final class FrequencyTest extends
         f.addValue(twoI);
         assertEquals(f, TestUtils.serializeAndRecover(f));
     }
+    
+    public void testGetUniqueCount() {
+        assertEquals(0, f.getUniqueCount());
+        f.addValue(oneL);
+        assertEquals(1, f.getUniqueCount());
+        f.addValue(oneL);
+        assertEquals(1, f.getUniqueCount());
+        f.addValue(twoI);
+        assertEquals(2, f.getUniqueCount());
+    }
 }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/Frequency.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/Frequency.java?rev=1044981&r1=1044980&r2=1044981&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/Frequency.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/Frequency.java Mon
Dec 13 00:43:57 2010
@@ -241,7 +241,15 @@ public class Frequency implements Serial
         return getCount(Character.valueOf(v));
     }
 
-    //-------------------------------------------------------------
+    /**
+     * Returns the number of values in the frequency table.
+     * 
+     * @return the number of unique values that have been added to the frequency table.
+     * @see #valuesIterator() 
+     */
+    public int getUniqueCount(){
+    	return freqTable.keySet().size();
+    }
 
     /**
      * Returns the percentage of values that are equal to v

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1044981&r1=1044980&r2=1044981&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Dec 13 00:43:57 2010
@@ -134,6 +134,10 @@ The <action> type attribute can be add,u
       </action>
     </release>
     <release version="2.2" date="TBD" description="TBD">
+      <action dev="psteitz" type="update" issue="MATH-448" due-to="Patrick Meyer">
+        Added a getUniqueCount() method to Frequency to return the number of unique
+        values included in the frequency table.
+      </action>
       <action dev="psteitz" type="fix" issue="MATH-414">
         Modified NormalDistributionImpl.cumulativeProbability to return 0 or 1,
         respectively for values more than 40 standard deviations from the mean.

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/FrequencyTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/FrequencyTest.java?rev=1044981&r1=1044980&r2=1044981&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/FrequencyTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/FrequencyTest.java
Mon Dec 13 00:43:57 2010
@@ -251,5 +251,15 @@ public final class FrequencyTest extends
         f.addValue(twoI);
         assertEquals(f, TestUtils.serializeAndRecover(f));
     }
+    
+    public void testGetUniqueCount() {
+        assertEquals(0, f.getUniqueCount());
+        f.addValue(oneL);
+        assertEquals(1, f.getUniqueCount());
+        f.addValue(oneL);
+        assertEquals(1, f.getUniqueCount());
+        f.addValue(twoI);
+        assertEquals(2, f.getUniqueCount());
+    }
 }
 



Mime
View raw message