nl.lxtreme.ols.util.analysis
Class Frequency<TYPE extends Comparable<TYPE>>

java.lang.Object
  extended by nl.lxtreme.ols.util.analysis.Frequency<TYPE>

public final class Frequency<TYPE extends Comparable<TYPE>>
extends Object

Provides a frequency distribution.


Constructor Summary
Frequency()
          Creates a new Frequency instance.
Frequency(Comparator<TYPE> aComparator)
          Creates a new Frequency instance using the given comparator for sorting the added values.
 
Method Summary
 void addValue(TYPE aValue)
          Adds a given value to the distribution map.
 void clear()
          Clears all values from this frequency distribution.
 long getCount(TYPE aValue)
          Counts the number of occurrences of the given value.
 TYPE getHighestRanked()
          Returns the item with the highest count or rank.
 TYPE getLowestRanked()
          Returns the item with the lowest count or rank.
 long getTotalCount()
          Returns the number of entries in this frequency distribution map.
 int getUniqueValueCount()
          Returns the number of unique values in this frequency distribution map.
 Iterable<TYPE> values()
          Returns an iterator for the values in this frequency distribution map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Frequency

public Frequency()
Creates a new Frequency instance.


Frequency

public Frequency(Comparator<TYPE> aComparator)
Creates a new Frequency instance using the given comparator for sorting the added values.

Parameters:
aComparator - the comparator to use for the distribution map, cannot be null.
Throws:
IllegalArgumentException - in case the given comparator was null.
Method Detail

addValue

public void addValue(TYPE aValue)
Adds a given value to the distribution map.

Parameters:
aValue - the value to add, cannot be null.
Throws:
IllegalArgumentException - in case the given value was null.

clear

public void clear()
Clears all values from this frequency distribution.


getCount

public long getCount(TYPE aValue)
Counts the number of occurrences of the given value.

Parameters:
aValue - the value to count, cannot be null.
Throws:
IllegalArgumentException - in case the given value was null.

getHighestRanked

public TYPE getHighestRanked()
Returns the item with the highest count or rank.

Returns:
the item with the highest rank, can be null if this frequency distribution is empty.

getLowestRanked

public TYPE getLowestRanked()
Returns the item with the lowest count or rank.

Returns:
the item with the lowest rank, can be null if this frequency distribution is empty.

getTotalCount

public long getTotalCount()
Returns the number of entries in this frequency distribution map.

Returns:
a size, >= 0.

getUniqueValueCount

public int getUniqueValueCount()
Returns the number of unique values in this frequency distribution map.

Returns:
a unique value count, >= 0.

values

public Iterable<TYPE> values()
Returns an iterator for the values in this frequency distribution map.

Returns:
an iterator with all values, sorted in natural order.


Copyright © 2012 L'Xtreme IT consultancy. All Rights Reserved.