-
-
Save dpash/0e28f29eff0f8576c3f6fb3285acddd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MutableInteger { | |
private int val; | |
public MutableInteger(int val) { | |
this.val = val; | |
} | |
public int get() { | |
return val; | |
} | |
public void set(int val) { | |
this.val = val; | |
} | |
@Override | |
public String toString() { | |
return Integer.toString(val); | |
} | |
} | |
public class CounterConcurrentHashMap<K> extends ConcurrentHashMap<K, MutableInteger> { | |
public MutableInteger up(K key) { | |
MutableInteger initValue = new MutableInteger(1); | |
MutableInteger oldValue = put(key, initValue); | |
if (oldValue != null) { | |
initValue.set(oldValue.get() + 1); | |
} | |
return initValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment