Java HashMap Counter incrementTwoLevelHashMap(HashMap map, String key1, String key2, int n)

Here you can find the source of incrementTwoLevelHashMap(HashMap map, String key1, String key2, int n)

Description

increment Two Level Hash Map

License

Apache License

Declaration

public static void incrementTwoLevelHashMap(HashMap map, String key1, String key2, int n) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.HashMap;

public class Main {
    public static void incrementTwoLevelHashMap(HashMap map, String key1, String key2, int n) {
        HashMap map2 = (HashMap) map.get(key1);
        if (map2 == null) {
            map2 = new HashMap();
            map.put(key1, map2);//from   ww w  .j  a  va  2 s .co m
        }
        incrementHashMap(map2, key2, n);
    }

    public static void incrementHashMap(HashMap map, String key, int n) {
        int count;
        Integer countI = (Integer) map.get(key);
        if (countI == null)
            count = 0;
        else {
            count = countI;
        }
        map.put(key, count + n);
    }
}

Related

  1. increment(HashMap m, X key)
  2. incrementHashMap(HashMap map, String key, int n)
  3. incrementMap(HashMap map, Integer key)