com.twitter.common.stats
Class CounterMapWithTopKey<K>

java.lang.Object
  extended by com.twitter.common.stats.CounterMap<K>
      extended by com.twitter.common.stats.CounterMapWithTopKey<K>
All Implemented Interfaces:
Cloneable, Iterable<Map.Entry<K,Integer>>

public class CounterMapWithTopKey<K>
extends CounterMap<K>

Same as CounterMap, but also keeps track of the item with the highest count.


Constructor Summary
CounterMapWithTopKey()
           
 
Method Summary
 K getMostCommonKey()
           
 int incrementAndGet(K key)
          Increments the counter value associated with key, and returns the new value.
 void reset(K key)
          Resets the value for key.
 void set(K key, int newValue)
          Assigns a value to a key.
 String toString()
           
 
Methods inherited from class com.twitter.common.stats.CounterMap
clone, get, incrementAndGet, iterator, keySet, size, toMap, values
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CounterMapWithTopKey

public CounterMapWithTopKey()
Method Detail

incrementAndGet

public int incrementAndGet(K key)
Increments the counter value associated with key, and returns the new value.

Overrides:
incrementAndGet in class CounterMap<K>
Parameters:
key - The key to increment
Returns:
The incremented value.

set

public void set(K key,
                int newValue)
Assigns a value to a key.

Overrides:
set in class CounterMap<K>
Parameters:
key - The key to assign a value to.
newValue - The value to assign.

reset

public void reset(K key)
Resets the value for key. This will simply set the stored value to 0. The most common key is updated by scanning the entire map.

Overrides:
reset in class CounterMap<K>
Parameters:
key - The key to reset.

getMostCommonKey

public K getMostCommonKey()
Returns:
The key with the highest count in the map. If multiple keys have this count, return an arbitrary one.

toString

public String toString()
Overrides:
toString in class CounterMap<K>