|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math.stat.Frequency
public class Frequency
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 to getCount,
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.
Nested Class Summary | |
---|---|
private static class |
Frequency.NaturalComparator<T extends java.lang.Comparable<T>>
A Comparator that compares comparable objects using the natural order. |
Field Summary | |
---|---|
private java.util.TreeMap<java.lang.Comparable<?>,java.lang.Long> |
freqTable
underlying collection |
private static long |
serialVersionUID
Serializable version identifier |
Constructor Summary | |
---|---|
Frequency()
Default constructor. |
|
Frequency(java.util.Comparator<?> comparator)
Constructor allowing values Comparator to be specified. |
Method Summary | |
---|---|
void |
addValue(char 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(int v)
Adds 1 to the frequency count for v. |
void |
addValue(java.lang.Integer v)
Deprecated. to be removed in math 3.0 |
void |
addValue(long v)
Adds 1 to the frequency count for v. |
void |
addValue(java.lang.Object v)
Deprecated. use addValue(Comparable) instead |
void |
clear()
Clears the frequency table |
boolean |
equals(java.lang.Object obj)
|
long |
getCount(char v)
Returns the number of values = v. |
long |
getCount(java.lang.Comparable<?> 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.Object v)
Deprecated. replaced by getCount(Comparable) as of 2.0 |
long |
getCumFreq(char 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(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.Object v)
Deprecated. replaced by getCumFreq(Comparable) as of 2.0 |
double |
getCumPct(char 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(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.Object v)
Deprecated. replaced by getCumPct(Comparable) as of 2.0 |
double |
getPct(char 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(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.Object v)
Deprecated. replaced by getPct(Comparable) as of 2.0 |
long |
getSumFreq()
Returns the sum of all frequencies. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
private final java.util.TreeMap<java.lang.Comparable<?>,java.lang.Long> freqTable
Constructor Detail |
---|
public Frequency()
public Frequency(java.util.Comparator<?> comparator)
comparator
- Comparator used to order valuesMethod Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
@Deprecated public void addValue(java.lang.Object v)
addValue(Comparable)
instead
If other objects have already been added to this Frequency, v must be comparable to those that have already been added.
v
- the value to add.
java.lang.IllegalArgumentException
- if v
is not Comparable,
or is not comparable with previous entriespublic void addValue(java.lang.Comparable<?> v)
If other objects have already been added to this Frequency, v must be comparable to those that have already been added.
v
- the value to add.
java.lang.IllegalArgumentException
- if v
is not comparable with previous entriespublic void addValue(int v)
v
- the value to add.@Deprecated public void addValue(java.lang.Integer v)
v
- the value to add.public void addValue(long v)
v
- the value to add.public void addValue(char v)
v
- the value to add.public void clear()
public java.util.Iterator<java.lang.Comparable<?>> valuesIterator()
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.
public long getSumFreq()
@Deprecated public long getCount(java.lang.Object v)
getCount(Comparable)
as of 2.0
v
- the value to lookup.
public long getCount(java.lang.Comparable<?> v)
v
- the value to lookup.
public long getCount(int v)
v
- the value to lookup.
public long getCount(long v)
v
- the value to lookup.
public long getCount(char v)
v
- the value to lookup.
@Deprecated public double getPct(java.lang.Object v)
getPct(Comparable)
as of 2.0
Returns Double.NaN
if no values have been added.
v
- the value to lookup
public double getPct(java.lang.Comparable<?> v)
Returns Double.NaN
if no values have been added.
v
- the value to lookup
public double getPct(int v)
v
- the value to lookup
public double getPct(long v)
v
- the value to lookup
public double getPct(char v)
v
- the value to lookup
@Deprecated public long getCumFreq(java.lang.Object v)
getCumFreq(Comparable)
as of 2.0
Returns 0 if v is not comparable to the values set.
v
- the value to lookup.
public long getCumFreq(java.lang.Comparable<?> v)
Returns 0 if v is not comparable to the values set.
v
- the value to lookup.
public long getCumFreq(int v)
Returns 0 if v is not comparable to the values set.
v
- the value to lookup
public long getCumFreq(long v)
Returns 0 if v is not comparable to the values set.
v
- the value to lookup
public long getCumFreq(char v)
Returns 0 if v is not comparable to the values set.
v
- the value to lookup
@Deprecated public double getCumPct(java.lang.Object v)
getCumPct(Comparable)
as of 2.0
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.
v
- the value to lookup
public double getCumPct(java.lang.Comparable<?> v)
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.
v
- the value to lookup
public double getCumPct(int v)
Returns 0 if v is not comparable to the values set.
v
- the value to lookup
public double getCumPct(long v)
Returns 0 if v is not comparable to the values set.
v
- the value to lookup
public double getCumPct(char v)
Returns 0 if v is not comparable to the values set.
v
- the value to lookup
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |