package com.qmth.qrzk.repository.utils.zujuan;

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

/**
 * 计数器
 * 
 * @author luoshi
 * 
 * @param <T>
 */
public class MapCounter<T> {

    private Map<T, Integer> store;

    public MapCounter() {
        this.store = new HashMap<T, Integer>();
    }

    public int incr(T key) {
        Integer value = store.get(key);
        if (value == null) {
            value = 0;
        }
        value++;
        store.put(key, value);
        return value;
    }

    public int count(T key) {
        Integer value = store.get(key);
        return value != null ? value : 0;
    }
}
