Added getTotalCount().
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1623 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
package com.samskivert.util;
|
package com.samskivert.util;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A hashmap that maintains a count for each key.
|
* A hashmap that maintains a count for each key.
|
||||||
@@ -50,4 +51,16 @@ public class CountHashMap extends HashMap
|
|||||||
int[] val = (int[]) get(key);
|
int[] val = (int[]) get(key);
|
||||||
return (val == null) ? 0 : val[0];
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user