mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Cleanup - Map.getOrDefault and Map.computeIfAbsent
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user