package com.scaleunlimited.yalder;

import java.util.HashMap;
import java.util.Map;

public class IntCounter {

    private Map<String, Integer> _counters;
    
    public IntCounter() {
        _counters = new HashMap<String, Integer>();
    }
    
    public int increment(String key) {
        return increment(key, 1);
    }

    public int increment(String key, int value) {
        Integer curCount = _counters.get(key);
        if (curCount == null) {
            _counters.put(key, value);
            return value;
        } else {
            _counters.put(key, curCount + value);
            return curCount + value;
        }
    }

    public int get(String key) {
        Integer curValue = _counters.get(key);
        return (curValue == null ? 0 : curValue);
    }

}

@@ -76,16 +76,66 @@
 til.Map;
+%0Aimport java.util.Map.Entry;%0Aimport java.util.Set;
 %0A%0Apublic
@@ -825,10 +825,279 @@
 %0A    %7D%0A%0A
+    public int sum() %7B%0A        int total = 0;%0A        for (Integer value : _counters.values()) %7B%0A            total += value;%0A        %7D%0A        %0A        return total;%0A    %7D%0A%0A    public Set%3CEntry%3CString, Integer%3E%3E entrySet() %7B%0A        return _counters.entrySet();%0A    %7D%0A%0A
 %7D%0A

Add more support to IntCounter