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

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1044981 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2010-12-13 00:43:57 +00:00
parent 49792e27a5
commit f85dc5760b
3 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -134,6 +134,10 @@ The <action> type attribute can be add,update,fix,remove.
</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.

View File

@ -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());
}
}