public int incrementCount ( K key , int amount ) { int [ ] val = get ( key ) ; if ( val == null ) { put ( key , val = new int [ 1 ] ) ; } val [ 0 ] += amount ; return val [ 0 ] ; /* Alternate implementation, less hashing on the first increment but more garbage created * every other time. (this whole method would be more optimal if this class were * rewritten) * int[] newVal = new int[] { amount }; int[] oldVal = put(key, newVal); if (oldVal != null) { newVal[0] += oldVal[0]; return oldVal[0]; } return 0; */ }
Increment the value associated with the specified key return the new value .