diff --git a/src/main/java/org/apache/commons/math/stat/Frequency.java b/src/main/java/org/apache/commons/math/stat/Frequency.java index 4935e113d..898ed14a4 100644 --- a/src/main/java/org/apache/commons/math/stat/Frequency.java +++ b/src/main/java/org/apache/commons/math/stat/Frequency.java @@ -241,7 +241,15 @@ public class Frequency implements Serializable { 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 diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 43a7d9e25..c5e14da50 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -134,6 +134,10 @@ The type attribute can be add,update,fix,remove. + + Added a getUniqueCount() method to Frequency to return the number of unique + values included in the frequency table. + Modified NormalDistributionImpl.cumulativeProbability to return 0 or 1, respectively for values more than 40 standard deviations from the mean. diff --git a/src/test/java/org/apache/commons/math/stat/FrequencyTest.java b/src/test/java/org/apache/commons/math/stat/FrequencyTest.java index 4251be14e..0fa1ff8e0 100644 --- a/src/test/java/org/apache/commons/math/stat/FrequencyTest.java +++ b/src/test/java/org/apache/commons/math/stat/FrequencyTest.java @@ -251,5 +251,15 @@ public final class FrequencyTest extends TestCase { 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()); + } }