Added getTotalCount().

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1623 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray
2005-03-15 02:18:54 +00:00
parent 16ccf7e2ff
commit f1441c6ca8
@@ -19,6 +19,7 @@
package com.samskivert.util;
import java.util.HashMap;
import java.util.Iterator;
/**
* A hashmap that maintains a count for each key.
@@ -50,4 +51,16 @@ public class CountHashMap extends HashMap
int[] val = (int[]) get(key);
return (val == null) ? 0 : val[0];
}
/**
* Get the total count for all keys in the map.
*/
public int getTotalCount ()
{
int count = 0;
for (Iterator itr = values().iterator(); itr.hasNext(); ) {
count += ((int[]) itr.next())[0];
}
return count;
}
}