public class Counter<T> extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
protected class |
Counter.PairComparator |
protected class |
Counter.ReversedPairComparator |
Modifier and Type | Field and Description |
---|---|
protected AtomicBoolean |
dirty |
protected ConcurrentHashMap<T,AtomicDouble> |
map |
protected AtomicDouble |
totalCount |
Constructor and Description |
---|
Counter() |
Modifier and Type | Method and Description |
---|---|
T |
argMax()
This method returns element with highest counter value
|
PriorityQueue<Pair<T,Double>> |
asPriorityQueue() |
PriorityQueue<Pair<T,Double>> |
asReversedPriorityQueue() |
void |
clear()
This method effectively resets counter to empty state
|
boolean |
containsElement(T element)
This method checks, if element exist in this counter
|
void |
dropElementsBelowThreshold(double threshold)
This method will remove all elements with counts below given threshold from counter
|
Set<Map.Entry<T,AtomicDouble>> |
entrySet()
This method returns Set
|
double |
getCount(T element) |
double |
getProbability(T element)
This method returns probability of given element
|
void |
incrementAll(Collection<T> elements,
double inc)
This method will increment all elements in collection
|
<T2 extends T> |
incrementAll(Counter<T2> other)
This method will increment counts of this counter by counts from other counter
|
void |
incrementCount(T element,
double inc) |
boolean |
isEmpty()
This method returns TRUE if counter has no elements, FALSE otherwise
|
void |
keepTopNElements(int N)
This method removes all elements except of top N by counter values
|
Set<T> |
keySet()
This method returns Set of elements used in this counter
|
List<T> |
keySetSorted()
This method returns List of elements, sorted by their counts
|
void |
normalize()
This method will apply normalization to counter values and totals.
|
protected void |
rebuildTotals() |
double |
removeKey(T element)
This method removes given key from counter
|
double |
setCount(T element,
double count)
This method sets new counter value for given element
|
int |
size()
Returns total number of tracked elements
|
double |
totalCount()
This method returns total sum of counter values
|
protected ConcurrentHashMap<T,AtomicDouble> map
protected AtomicDouble totalCount
protected AtomicBoolean dirty
public double getCount(T element)
public void incrementCount(T element, double inc)
public void incrementAll(Collection<T> elements, double inc)
elements
- inc
- public <T2 extends T> void incrementAll(Counter<T2> other)
other
- public double getProbability(T element)
element
- public double setCount(T element, double count)
element
- element to be updatedcount
- new counter valuepublic boolean isEmpty()
public Set<Map.Entry<T,AtomicDouble>> entrySet()
public List<T> keySetSorted()
public void normalize()
protected void rebuildTotals()
public double totalCount()
public double removeKey(T element)
element
- public T argMax()
public void dropElementsBelowThreshold(double threshold)
threshold
- public boolean containsElement(T element)
element
- public void clear()
public int size()
public void keepTopNElements(int N)
N
- public PriorityQueue<Pair<T,Double>> asPriorityQueue()
public PriorityQueue<Pair<T,Double>> asReversedPriorityQueue()
Copyright © 2017. All rights reserved.