From f1441c6ca8e28e12ebc3d1c2e70cf530252e0556 Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 15 Mar 2005 02:18:54 +0000 Subject: [PATCH] Added getTotalCount(). git-svn-id: https://samskivert.googlecode.com/svn/trunk@1623 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/util/CountHashMap.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/projects/samskivert/src/java/com/samskivert/util/CountHashMap.java b/projects/samskivert/src/java/com/samskivert/util/CountHashMap.java index 6ee98354..11b2fb94 100644 --- a/projects/samskivert/src/java/com/samskivert/util/CountHashMap.java +++ b/projects/samskivert/src/java/com/samskivert/util/CountHashMap.java @@ -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; + } }