BAEL-1375 Using compute for every usage. (#3242)
This commit is contained in:
parent
04df1cfef0
commit
9627971b46
|
@ -38,23 +38,14 @@ public class CounterUtil {
|
||||||
|
|
||||||
public static void counterWithMutableInteger(Map<String, MutableInteger> counterMap) {
|
public static void counterWithMutableInteger(Map<String, MutableInteger> counterMap) {
|
||||||
for (String country : COUNTRY_NAMES) {
|
for (String country : COUNTRY_NAMES) {
|
||||||
MutableInteger oldValue = counterMap.get(country);
|
counterMap.compute(country, (k, v) -> v == null ? new MutableInteger(0) : v)
|
||||||
if (oldValue != null) {
|
.increment();
|
||||||
oldValue.increment();
|
|
||||||
} else {
|
|
||||||
counterMap.put(country, new MutableInteger(1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void counterWithPrimitiveArray(Map<String, int[]> counterMap) {
|
public static void counterWithPrimitiveArray(Map<String, int[]> counterMap) {
|
||||||
for (String country : COUNTRY_NAMES) {
|
for (String country : COUNTRY_NAMES) {
|
||||||
int[] oldCounter = counterMap.get(country);
|
counterMap.compute(country, (k, v) -> v == null ? new int[] { 0 } : v)[0]++;
|
||||||
if (oldCounter != null) {
|
|
||||||
oldCounter[0] += 1;
|
|
||||||
} else {
|
|
||||||
counterMap.put(country, new int[] { 1 });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue