Pluck of revision 45a25185236e38606e761060427ee8fa60144a8c from branch i2p.i2p.zzz.test

---------------------------------------------------------------------------------------
    * netdb.jsp: Add country chart at bottom, clean up version chart
This commit is contained in:
zzz
2009-06-21 00:03:59 +00:00
parent 306b3017e4
commit bc38ca4f91
5 changed files with 102 additions and 62 deletions

View File

@ -0,0 +1,42 @@
package net.i2p.util;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* Count things.
*
* @author zzz
*/
public class ObjectCounter<K> {
private ConcurrentHashMap<K, Integer> _map;
public ObjectCounter() {
_map = new ConcurrentHashMap();
}
/**
* Add one.
* Not perfectly concurrent, new AtomicInteger(1) would be better,
* at the cost of some object churn.
*/
public void increment(K h) {
Integer i = _map.putIfAbsent(h, Integer.valueOf(1));
if (i != null)
_map.put(h, Integer.valueOf(i.intValue() + 1));
}
/**
* @return current count
*/
public int count(K h) {
Integer i = _map.get(h);
if (i != null)
return i.intValue();
return 0;
}
/**
* @return set of objects with counts > 0
*/
public Set<K> objects() {
return _map.keySet();
}
}