Cleanup - Map.getOrDefault and Map.computeIfAbsent

This commit is contained in:
Jetz
2024-08-10 12:48:52 -04:00
parent bdc890c32c
commit 4614c6c0c9
16 changed files with 22 additions and 77 deletions

View File

@@ -655,7 +655,7 @@ public abstract class CardTraitBase extends GameObject implements IHasCardView,
Map<String, String> result = Maps.newHashMap(output);
for (Map.Entry<String, String> e : input.entrySet()) {
String value = e.getValue();
result.put(e.getKey(), output.containsKey(value) ? output.get(value) : value);
result.put(e.getKey(), output.getOrDefault(value, value));
}
return result;
}

View File

@@ -78,7 +78,7 @@ public class GameEntityCounterTable extends ForwardingTable<Optional<Player>, Ga
}
Map<CounterType, Integer> alreadyRemoved = column(ge).get(Optional.absent());
for (Map.Entry<CounterType, Integer> e : ge.getCounters().entrySet()) {
int rest = e.getValue() - (alreadyRemoved.containsKey(e.getKey()) ? alreadyRemoved.get(e.getKey()) : 0);
int rest = e.getValue() - (alreadyRemoved.getOrDefault(e.getKey(), 0));
if (rest > 0) {
result.put(e.getKey(), rest);
}

View File

@@ -362,7 +362,7 @@ public class CountersMoveEffect extends SpellAbilityEffect {
if (cnum > 0) {
src.subtractCounter(cType, cnum, activator);
game.updateLastStateForCard(src);
countersToAdd.put(cType, (countersToAdd.containsKey(cType) ? countersToAdd.get(cType) : 0) + cnum);
countersToAdd.put(cType, (countersToAdd.getOrDefault(cType, 0)) + cnum);
}
}
}

View File

@@ -7950,26 +7950,14 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
}
}
} else {
List<String> result = chosenModesTurn.get(original);
if (result == null) {
result = Lists.newArrayList();
chosenModesTurn.put(original, result);
}
List<String> result = chosenModesTurn.computeIfAbsent(original, k -> Lists.newArrayList());
result.add(mode);
result = chosenModesGame.get(original);
if (result == null) {
result = Lists.newArrayList();
chosenModesGame.put(original, result);
}
result = chosenModesGame.computeIfAbsent(original, k -> Lists.newArrayList());
result.add(mode);
if (yourCombat) {
result = chosenModesYourCombat.get(original);
if (result == null) {
result = Lists.newArrayList();
chosenModesYourCombat.put(original, result);
}
result = chosenModesYourCombat.computeIfAbsent(original, k -> Lists.newArrayList());
result.add(mode);
}
}

View File

@@ -263,11 +263,7 @@ public class ManaCostBeingPaid {
private void increaseShard(final ManaCostShard shard, final int toAdd, final boolean forX) {
if (toAdd <= 0) { return; }
ShardCount sc = unpaidShards.get(shard);
if (sc == null) {
sc = new ShardCount();
unpaidShards.put(shard, sc);
}
ShardCount sc = unpaidShards.computeIfAbsent(shard, k -> new ShardCount());
if (forX) {
sc.xCount += toAdd;
}