Class Frequency
- java.lang.Object
-
- org.apache.commons.math.stat.Frequency
-
- All Implemented Interfaces:
java.io.Serializable
public class Frequency extends java.lang.Object implements java.io.Serializable
Maintains a frequency distribution.Accepts int, long, char or Comparable values. New values added must be comparable to those that have been added, otherwise the add method will throw an IllegalArgumentException.
Integer values (int, long, Integer, Long) are not distinguished by type -- i.e.
addValue(Long.valueOf(2)), addValue(2), addValue(2l)
all have the same effect (similarly for arguments togetCount,
etc.).char values are converted by
addValue
to Character instances. As such, these values are not comparable to integral values, so attempts to combine integral types with chars in a frequency distribution will fail.The values are ordered using the default (natural order), unless a
Comparator
is supplied in the constructor.- Version:
- $Revision: 1054186 $ $Date: 2011-01-01 03:28:46 +0100 (sam. 01 janv. 2011) $
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addValue(char v)
Adds 1 to the frequency count for v.void
addValue(int v)
Adds 1 to the frequency count for v.void
addValue(long v)
Adds 1 to the frequency count for v.void
addValue(java.lang.Comparable<?> v)
Adds 1 to the frequency count for v.void
addValue(java.lang.Integer v)
Deprecated.to be removed in math 3.0void
addValue(java.lang.Object v)
Deprecated.useaddValue(Comparable)
insteadvoid
clear()
Clears the frequency tableboolean
equals(java.lang.Object obj)
long
getCount(char v)
Returns the number of values = v.long
getCount(int v)
Returns the number of values = v.long
getCount(long v)
Returns the number of values = v.long
getCount(java.lang.Comparable<?> v)
Returns the number of values = v.long
getCount(java.lang.Object v)
Deprecated.replaced bygetCount(Comparable)
as of 2.0long
getCumFreq(char v)
Returns the cumulative frequency of values less than or equal to v.long
getCumFreq(int v)
Returns the cumulative frequency of values less than or equal to v.long
getCumFreq(long v)
Returns the cumulative frequency of values less than or equal to v.long
getCumFreq(java.lang.Comparable<?> v)
Returns the cumulative frequency of values less than or equal to v.long
getCumFreq(java.lang.Object v)
Deprecated.replaced bygetCumFreq(Comparable)
as of 2.0double
getCumPct(char v)
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).double
getCumPct(int v)
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).double
getCumPct(long v)
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).double
getCumPct(java.lang.Comparable<?> v)
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).double
getCumPct(java.lang.Object v)
Deprecated.replaced bygetCumPct(Comparable)
as of 2.0double
getPct(char v)
Returns the percentage of values that are equal to v (as a proportion between 0 and 1).double
getPct(int v)
Returns the percentage of values that are equal to v (as a proportion between 0 and 1).double
getPct(long v)
Returns the percentage of values that are equal to v (as a proportion between 0 and 1).double
getPct(java.lang.Comparable<?> v)
Returns the percentage of values that are equal to v (as a proportion between 0 and 1).double
getPct(java.lang.Object v)
Deprecated.replaced bygetPct(Comparable)
as of 2.0long
getSumFreq()
Returns the sum of all frequencies.int
getUniqueCount()
Returns the number of values in the frequency table.int
hashCode()
java.lang.String
toString()
Return a string representation of this frequency distribution.java.util.Iterator<java.lang.Comparable<?>>
valuesIterator()
Returns an Iterator over the set of values that have been added.
-
-
-
Method Detail
-
toString
public java.lang.String toString()
Return a string representation of this frequency distribution.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation.
-
addValue
@Deprecated public void addValue(java.lang.Object v)
Deprecated.useaddValue(Comparable)
insteadAdds 1 to the frequency count for v.If other objects have already been added to this Frequency, v must be comparable to those that have already been added.
- Parameters:
v
- the value to add.- Throws:
java.lang.IllegalArgumentException
- ifv
is not Comparable, or is not comparable with previous entries
-
addValue
public void addValue(java.lang.Comparable<?> v)
Adds 1 to the frequency count for v.If other objects have already been added to this Frequency, v must be comparable to those that have already been added.
- Parameters:
v
- the value to add.- Throws:
java.lang.IllegalArgumentException
- ifv
is not comparable with previous entries
-
addValue
public void addValue(int v)
Adds 1 to the frequency count for v.- Parameters:
v
- the value to add.
-
addValue
@Deprecated public void addValue(java.lang.Integer v)
Deprecated.to be removed in math 3.0Adds 1 to the frequency count for v.- Parameters:
v
- the value to add.
-
addValue
public void addValue(long v)
Adds 1 to the frequency count for v.- Parameters:
v
- the value to add.
-
addValue
public void addValue(char v)
Adds 1 to the frequency count for v.- Parameters:
v
- the value to add.
-
clear
public void clear()
Clears the frequency table
-
valuesIterator
public java.util.Iterator<java.lang.Comparable<?>> valuesIterator()
Returns an Iterator over the set of values that have been added.If added values are integral (i.e., integers, longs, Integers, or Longs), they are converted to Longs when they are added, so the objects returned by the Iterator will in this case be Longs.
- Returns:
- values Iterator
-
getSumFreq
public long getSumFreq()
Returns the sum of all frequencies.- Returns:
- the total frequency count.
-
getCount
@Deprecated public long getCount(java.lang.Object v)
Deprecated.replaced bygetCount(Comparable)
as of 2.0Returns the number of values = v. Returns 0 if the value is not comparable.- Parameters:
v
- the value to lookup.- Returns:
- the frequency of v.
-
getCount
public long getCount(java.lang.Comparable<?> v)
Returns the number of values = v. Returns 0 if the value is not comparable.- Parameters:
v
- the value to lookup.- Returns:
- the frequency of v.
-
getCount
public long getCount(int v)
Returns the number of values = v.- Parameters:
v
- the value to lookup.- Returns:
- the frequency of v.
-
getCount
public long getCount(long v)
Returns the number of values = v.- Parameters:
v
- the value to lookup.- Returns:
- the frequency of v.
-
getCount
public long getCount(char v)
Returns the number of values = v.- Parameters:
v
- the value to lookup.- Returns:
- the frequency of v.
-
getUniqueCount
public int getUniqueCount()
Returns the number of values in the frequency table.- Returns:
- the number of unique values that have been added to the frequency table.
- See Also:
valuesIterator()
-
getPct
@Deprecated public double getPct(java.lang.Object v)
Deprecated.replaced bygetPct(Comparable)
as of 2.0Returns the percentage of values that are equal to v (as a proportion between 0 and 1).Returns
Double.NaN
if no values have been added.- Parameters:
v
- the value to lookup- Returns:
- the proportion of values equal to v
-
getPct
public double getPct(java.lang.Comparable<?> v)
Returns the percentage of values that are equal to v (as a proportion between 0 and 1).Returns
Double.NaN
if no values have been added.- Parameters:
v
- the value to lookup- Returns:
- the proportion of values equal to v
-
getPct
public double getPct(int v)
Returns the percentage of values that are equal to v (as a proportion between 0 and 1).- Parameters:
v
- the value to lookup- Returns:
- the proportion of values equal to v
-
getPct
public double getPct(long v)
Returns the percentage of values that are equal to v (as a proportion between 0 and 1).- Parameters:
v
- the value to lookup- Returns:
- the proportion of values equal to v
-
getPct
public double getPct(char v)
Returns the percentage of values that are equal to v (as a proportion between 0 and 1).- Parameters:
v
- the value to lookup- Returns:
- the proportion of values equal to v
-
getCumFreq
@Deprecated public long getCumFreq(java.lang.Object v)
Deprecated.replaced bygetCumFreq(Comparable)
as of 2.0Returns the cumulative frequency of values less than or equal to v.Returns 0 if v is not comparable to the values set.
- Parameters:
v
- the value to lookup.- Returns:
- the proportion of values equal to v
-
getCumFreq
public long getCumFreq(java.lang.Comparable<?> v)
Returns the cumulative frequency of values less than or equal to v.Returns 0 if v is not comparable to the values set.
- Parameters:
v
- the value to lookup.- Returns:
- the proportion of values equal to v
-
getCumFreq
public long getCumFreq(int v)
Returns the cumulative frequency of values less than or equal to v.Returns 0 if v is not comparable to the values set.
- Parameters:
v
- the value to lookup- Returns:
- the proportion of values equal to v
-
getCumFreq
public long getCumFreq(long v)
Returns the cumulative frequency of values less than or equal to v.Returns 0 if v is not comparable to the values set.
- Parameters:
v
- the value to lookup- Returns:
- the proportion of values equal to v
-
getCumFreq
public long getCumFreq(char v)
Returns the cumulative frequency of values less than or equal to v.Returns 0 if v is not comparable to the values set.
- Parameters:
v
- the value to lookup- Returns:
- the proportion of values equal to v
-
getCumPct
@Deprecated public double getCumPct(java.lang.Object v)
Deprecated.replaced bygetCumPct(Comparable)
as of 2.0Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).Returns
Double.NaN
if no values have been added. Returns 0 if at least one value has been added, but v is not comparable to the values set.- Parameters:
v
- the value to lookup- Returns:
- the proportion of values less than or equal to v
-
getCumPct
public double getCumPct(java.lang.Comparable<?> v)
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).Returns
Double.NaN
if no values have been added. Returns 0 if at least one value has been added, but v is not comparable to the values set.- Parameters:
v
- the value to lookup- Returns:
- the proportion of values less than or equal to v
-
getCumPct
public double getCumPct(int v)
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).Returns 0 if v is not comparable to the values set.
- Parameters:
v
- the value to lookup- Returns:
- the proportion of values less than or equal to v
-
getCumPct
public double getCumPct(long v)
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).Returns 0 if v is not comparable to the values set.
- Parameters:
v
- the value to lookup- Returns:
- the proportion of values less than or equal to v
-
getCumPct
public double getCumPct(char v)
Returns the cumulative percentage of values less than or equal to v (as a proportion between 0 and 1).Returns 0 if v is not comparable to the values set.
- Parameters:
v
- the value to lookup- Returns:
- the proportion of values less than or equal to v
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-