From 3e5ff8ccb22854a44934e23fd2a26fbf358599a9 Mon Sep 17 00:00:00 2001 From: igoudt Date: Fri, 28 Apr 2017 13:27:22 +0200 Subject: [PATCH] rewrites to getOrDefault --- Mage.Sets/src/mage/cards/a/AlphaAuthority.java | 7 +++---- Mage.Sets/src/mage/cards/c/CerebralVortex.java | 5 +---- Mage.Sets/src/mage/cards/c/ConduitOfRuin.java | 14 +++----------- .../src/mage/cards/d/DescentOfTheDragons.java | 14 +++++--------- Mage.Sets/src/mage/cards/d/DreamSalvage.java | 17 +++-------------- .../src/mage/cards/e/ErdwalIlluminator.java | 15 ++++----------- .../src/mage/cards/g/GontisMachinations.java | 5 +---- .../mage/cards/j/JelevaNephaliasScourge.java | 5 +---- .../src/mage/cards/k/KydeleChosenOfKruphix.java | 16 +++++----------- Mage.Sets/src/mage/cards/m/MoltenPsyche.java | 5 +---- Mage.Sets/src/mage/cards/s/SylvanLibrary.java | 10 ++++------ Mage.Sets/src/mage/cards/t/Terastodon.java | 5 +---- Mage.Sets/src/mage/cards/t/TunnelIgnus.java | 11 +++++------ Mage.Sets/src/mage/cards/v/VileRedeemer.java | 7 +++---- .../src/mage/cards/v/VorracBattlehorns.java | 2 +- 15 files changed, 41 insertions(+), 97 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AlphaAuthority.java b/Mage.Sets/src/mage/cards/a/AlphaAuthority.java index 82db9980b4..0a83bd64c3 100644 --- a/Mage.Sets/src/mage/cards/a/AlphaAuthority.java +++ b/Mage.Sets/src/mage/cards/a/AlphaAuthority.java @@ -47,13 +47,12 @@ import mage.util.CardUtil; import java.util.UUID; /** - * * @author LevelX2 */ public class AlphaAuthority extends CardImpl { public AlphaAuthority(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}"); this.subtype.add("Aura"); @@ -66,7 +65,7 @@ public class AlphaAuthority extends CardImpl { // Enchanted creature has hexproof and can't be blocked by more than one creature. ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(HexproofAbility.getInstance(), AttachmentType.AURA, Duration.WhileOnBattlefield)); - Effect effect = new CantBeBlockedByMoreThanOneAttachedEffect(AttachmentType.AURA,1); + Effect effect = new CantBeBlockedByMoreThanOneAttachedEffect(AttachmentType.AURA, 1); effect.setText("and can't be blocked by more than one creature"); ability.addEffect(effect); this.addAbility(ability); @@ -95,7 +94,7 @@ class CantBeBlockedByMoreThanOneAttachedEffect extends ContinuousEffectImpl { super(duration, Outcome.Benefit); this.amount = amount; this.attachmentType = attachmentType; - staticText = (attachmentType == AttachmentType.AURA ? "Enchanted" : "Equipped") + " creature can't be blocked by more than " + CardUtil.numberToText(amount) + " creature" + (amount==1 ?"":"s"); + staticText = attachmentType.verb() + " creature can't be blocked by more than " + CardUtil.numberToText(amount) + " creature" + (amount == 1 ? "" : "s"); } public CantBeBlockedByMoreThanOneAttachedEffect(final CantBeBlockedByMoreThanOneAttachedEffect effect) { diff --git a/Mage.Sets/src/mage/cards/c/CerebralVortex.java b/Mage.Sets/src/mage/cards/c/CerebralVortex.java index 95bfc1fead..9421e1045a 100644 --- a/Mage.Sets/src/mage/cards/c/CerebralVortex.java +++ b/Mage.Sets/src/mage/cards/c/CerebralVortex.java @@ -136,10 +136,7 @@ class CerebralVortexWatcher extends Watcher { } public int getDraws(UUID playerId) { - if (draws.containsKey(playerId)) { - return draws.get(playerId); - } - return 0; + return draws.getOrDefault(playerId, 0); } @Override diff --git a/Mage.Sets/src/mage/cards/c/ConduitOfRuin.java b/Mage.Sets/src/mage/cards/c/ConduitOfRuin.java index a74e1bb076..9d44e437c2 100644 --- a/Mage.Sets/src/mage/cards/c/ConduitOfRuin.java +++ b/Mage.Sets/src/mage/cards/c/ConduitOfRuin.java @@ -56,7 +56,6 @@ import java.util.Map; import java.util.UUID; /** - * * @author LevelX2 */ public class ConduitOfRuin extends CardImpl { @@ -71,7 +70,7 @@ public class ConduitOfRuin extends CardImpl { } public ConduitOfRuin(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{6}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{6}"); this.subtype.add("Eldrazi"); this.power = new MageInt(5); this.toughness = new MageInt(5); @@ -117,20 +116,13 @@ class ConduitOfRuinWatcher extends Watcher { if (event.getType() == GameEvent.EventType.SPELL_CAST) { Spell spell = (Spell) game.getObject(event.getTargetId()); if (spell != null && spell.isCreature()) { - if (playerCreatureSpells.containsKey(event.getPlayerId())) { - playerCreatureSpells.put(event.getPlayerId(), playerCreatureSpells.get(event.getPlayerId()) + 1); - } else { - playerCreatureSpells.put(event.getPlayerId(), 1); - } + playerCreatureSpells.put(event.getPlayerId(), creatureSpellsCastThisTurn(event.getPlayerId()) + 1); } } } public int creatureSpellsCastThisTurn(UUID playerId) { - if (playerCreatureSpells.containsKey(playerId)) { - return playerCreatureSpells.get(playerId); - } - return 0; + return playerCreatureSpells.getOrDefault(playerId, 0); } @Override diff --git a/Mage.Sets/src/mage/cards/d/DescentOfTheDragons.java b/Mage.Sets/src/mage/cards/d/DescentOfTheDragons.java index d4aed13bd3..d891e90faf 100644 --- a/Mage.Sets/src/mage/cards/d/DescentOfTheDragons.java +++ b/Mage.Sets/src/mage/cards/d/DescentOfTheDragons.java @@ -44,13 +44,12 @@ import java.util.HashMap; import java.util.UUID; /** - * * @author jeffwadsworth */ public class DescentOfTheDragons extends CardImpl { public DescentOfTheDragons(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{4}{R}{R}"); + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{R}{R}"); // Destroy any number of target creatures. For each creature destroyed this way, its controller creates a 4/4 red Dragon creature token with flying. this.getSpellAbility().addEffect(new DescentOfTheDragonsEffect()); @@ -95,18 +94,15 @@ class DescentOfTheDragonsEffect extends OneShotEffect { if (permanent != null) { UUID controllerOfTargetId = permanent.getControllerId(); if (permanent.destroy(source.getSourceId(), game, false)) { - if(playersWithTargets.containsKey(controllerOfTargetId)) { - playersWithTargets.put(controllerOfTargetId, playersWithTargets.get(controllerOfTargetId) + 1); - } - else { - playersWithTargets.put(controllerOfTargetId, 1); - } + int count = playersWithTargets.getOrDefault(controllerOfTargetId, 0); + playersWithTargets.put(controllerOfTargetId, count + 1); + } } } } DragonToken dragonToken = new DragonToken(); - for(UUID playerId : playersWithTargets.keySet()) { + for (UUID playerId : playersWithTargets.keySet()) { dragonToken.putOntoBattlefield(playersWithTargets.get(playerId), game, source.getSourceId(), playerId); } return true; diff --git a/Mage.Sets/src/mage/cards/d/DreamSalvage.java b/Mage.Sets/src/mage/cards/d/DreamSalvage.java index b7848104e0..e9bcd54027 100644 --- a/Mage.Sets/src/mage/cards/d/DreamSalvage.java +++ b/Mage.Sets/src/mage/cards/d/DreamSalvage.java @@ -46,13 +46,12 @@ import java.util.Map.Entry; import java.util.UUID; /** - * * @author jeffwadsworth */ public class DreamSalvage extends CardImpl { public DreamSalvage(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{U/B}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{U/B}"); // Draw cards equal to the number of cards target opponent discarded this turn. @@ -92,23 +91,13 @@ class CardsDiscardedThisTurnWatcher extends Watcher { if (event.getType() == GameEvent.EventType.DISCARDED_CARD) { UUID playerId = event.getPlayerId(); if (playerId != null) { - Integer amount = amountOfCardsDiscardedThisTurn.get(playerId); - if (amount == null) { - amount = 1; - } else { - amount++; - } - amountOfCardsDiscardedThisTurn.put(playerId, amount); + amountOfCardsDiscardedThisTurn.put(playerId, getAmountCardsDiscarded(playerId) + 1); } } } public int getAmountCardsDiscarded(UUID playerId) { - Integer amount = amountOfCardsDiscardedThisTurn.get(playerId); - if (amount != null) { - return amount; - } - return 0; + return amountOfCardsDiscardedThisTurn.getOrDefault(playerId, 0); } @Override diff --git a/Mage.Sets/src/mage/cards/e/ErdwalIlluminator.java b/Mage.Sets/src/mage/cards/e/ErdwalIlluminator.java index 33d845dce8..7ba289641e 100644 --- a/Mage.Sets/src/mage/cards/e/ErdwalIlluminator.java +++ b/Mage.Sets/src/mage/cards/e/ErdwalIlluminator.java @@ -45,13 +45,12 @@ import java.util.HashMap; import java.util.UUID; /** - * * @author LevelX2 */ public class ErdwalIlluminator extends CardImpl { public ErdwalIlluminator(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}"); this.subtype.add("Spirit"); this.power = new MageInt(1); this.toughness = new MageInt(3); @@ -126,11 +125,8 @@ class InvestigatedWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { if (event.getType() == EventType.INVESTIGATED) { - if (!timesInvestigated.containsKey(event.getPlayerId())) { - timesInvestigated.put(event.getPlayerId(), 1); - } else { - timesInvestigated.put(event.getPlayerId(), timesInvestigated.get(event.getPlayerId()) + 1); - } + timesInvestigated.put(event.getPlayerId(), getTimesInvestigated(event.getPlayerId()) + 1); + } } @@ -141,9 +137,6 @@ class InvestigatedWatcher extends Watcher { } public int getTimesInvestigated(UUID playerId) { - if (timesInvestigated.containsKey(playerId)) { - return timesInvestigated.get(playerId); - } - return 0; + return timesInvestigated.getOrDefault(playerId, 0); } } diff --git a/Mage.Sets/src/mage/cards/g/GontisMachinations.java b/Mage.Sets/src/mage/cards/g/GontisMachinations.java index b1aa454a01..3a4d3131aa 100644 --- a/Mage.Sets/src/mage/cards/g/GontisMachinations.java +++ b/Mage.Sets/src/mage/cards/g/GontisMachinations.java @@ -152,10 +152,7 @@ class GontisMachinationsFirstLostLifeThisTurnWatcher extends Watcher { } public int timesLostLifeThisTurn(UUID playerId) { - if (playersLostLife.containsKey(playerId)) { - return playersLostLife.get(playerId); - } - return 0; + return playersLostLife.getOrDefault(playerId, 0); } } diff --git a/Mage.Sets/src/mage/cards/j/JelevaNephaliasScourge.java b/Mage.Sets/src/mage/cards/j/JelevaNephaliasScourge.java index c397716dbb..8175695708 100644 --- a/Mage.Sets/src/mage/cards/j/JelevaNephaliasScourge.java +++ b/Mage.Sets/src/mage/cards/j/JelevaNephaliasScourge.java @@ -205,10 +205,7 @@ class JelevaNephaliasWatcher extends Watcher { } public int getManaSpentToCastLastTime(int zoneChangeCounter) { - if (manaSpendToCast.containsKey(zoneChangeCounter)) { - return manaSpendToCast.get(zoneChangeCounter); - } - return 0; + return manaSpendToCast.getOrDefault(zoneChangeCounter, 0); } @Override diff --git a/Mage.Sets/src/mage/cards/k/KydeleChosenOfKruphix.java b/Mage.Sets/src/mage/cards/k/KydeleChosenOfKruphix.java index 0903406382..ca0a97b096 100644 --- a/Mage.Sets/src/mage/cards/k/KydeleChosenOfKruphix.java +++ b/Mage.Sets/src/mage/cards/k/KydeleChosenOfKruphix.java @@ -84,7 +84,7 @@ class CardsDrawnThisTurnDynamicValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { KydeleCardsDrawnThisTurnWatcher watcher = (KydeleCardsDrawnThisTurnWatcher) game.getState().getWatchers().get(KydeleCardsDrawnThisTurnWatcher.class.getName()); - return watcher.getNumCardsDrawnThisTurn(sourceAbility.getControllerId()); + return watcher.getCardsDrawnThisTurn(sourceAbility.getControllerId()).size(); } @Override @@ -119,20 +119,14 @@ class KydeleCardsDrawnThisTurnWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.DREW_CARD) { - if (!cardsDrawnThisTurn.containsKey(event.getPlayerId())) { - Set cardsDrawn = new LinkedHashSet<>(); - cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn); - } - Set cardsDrawn = cardsDrawnThisTurn.get(event.getPlayerId()); + Set cardsDrawn = getCardsDrawnThisTurn(event.getPlayerId()); cardsDrawn.add(event.getTargetId()); + cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn); } } - public int getNumCardsDrawnThisTurn(UUID playerId) { - if (cardsDrawnThisTurn.get(playerId) == null) { - return 0; - } - return cardsDrawnThisTurn.get(playerId).size(); + public Set getCardsDrawnThisTurn(UUID playerId) { + return cardsDrawnThisTurn.getOrDefault(playerId, new LinkedHashSet<>()); } @Override diff --git a/Mage.Sets/src/mage/cards/m/MoltenPsyche.java b/Mage.Sets/src/mage/cards/m/MoltenPsyche.java index a841e6dd88..a5f90702b3 100644 --- a/Mage.Sets/src/mage/cards/m/MoltenPsyche.java +++ b/Mage.Sets/src/mage/cards/m/MoltenPsyche.java @@ -167,10 +167,7 @@ class MoltenPsycheWatcher extends Watcher { } public int getDraws(UUID playerId) { - if (draws.containsKey(playerId)) { - return draws.get(playerId); - } - return 0; + return draws.getOrDefault(playerId, 0); } @Override diff --git a/Mage.Sets/src/mage/cards/s/SylvanLibrary.java b/Mage.Sets/src/mage/cards/s/SylvanLibrary.java index 5643ca41fc..ad4162f117 100644 --- a/Mage.Sets/src/mage/cards/s/SylvanLibrary.java +++ b/Mage.Sets/src/mage/cards/s/SylvanLibrary.java @@ -157,17 +157,15 @@ class SylvanLibraryCardsDrawnThisTurnWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.DREW_CARD) { - if (!cardsDrawnThisTurn.containsKey(event.getPlayerId())) { - Set cardsDrawn = new LinkedHashSet<>(); - cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn); - } - Set cardsDrawn = cardsDrawnThisTurn.get(event.getPlayerId()); + + Set cardsDrawn = getCardsDrawnThisTurn(event.getPlayerId()); cardsDrawn.add(event.getTargetId()); + cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn); } } public Set getCardsDrawnThisTurn(UUID playerId) { - return cardsDrawnThisTurn.get(playerId); + return cardsDrawnThisTurn.getOrDefault(playerId, new LinkedHashSet<>()); } @Override diff --git a/Mage.Sets/src/mage/cards/t/Terastodon.java b/Mage.Sets/src/mage/cards/t/Terastodon.java index c47a49b844..349040715d 100644 --- a/Mage.Sets/src/mage/cards/t/Terastodon.java +++ b/Mage.Sets/src/mage/cards/t/Terastodon.java @@ -106,10 +106,7 @@ class TerastodonEffect extends OneShotEffect { if (permanent != null) { if (permanent.destroy(source.getSourceId(), game, false)) { if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) { - int numberPermanents = 0; - if (destroyedPermanents.containsKey(permanent.getControllerId())) { - numberPermanents = destroyedPermanents.get(permanent.getControllerId()); - } + int numberPermanents = destroyedPermanents.getOrDefault(permanent.getControllerId(), 0); destroyedPermanents.put(permanent.getControllerId(), numberPermanents + 1); } } diff --git a/Mage.Sets/src/mage/cards/t/TunnelIgnus.java b/Mage.Sets/src/mage/cards/t/TunnelIgnus.java index 908e5664b1..7441af97dd 100644 --- a/Mage.Sets/src/mage/cards/t/TunnelIgnus.java +++ b/Mage.Sets/src/mage/cards/t/TunnelIgnus.java @@ -31,6 +31,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; + import mage.MageInt; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; @@ -53,7 +54,7 @@ import mage.watchers.Watcher; public class TunnelIgnus extends CardImpl { public TunnelIgnus(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{R}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{R}"); this.subtype.add("Elemental"); this.power = new MageInt(2); @@ -98,11 +99,9 @@ class TunnelIgnusWatcher extends Watcher { if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent.isLand() && game.getOpponents(this.controllerId).contains(permanent.getControllerId())) { - int count = 1; - if (counts.containsKey(permanent.getControllerId())) { - count += counts.get(permanent.getControllerId()); - } - counts.put(permanent.getControllerId(), count); + + int count = counts.getOrDefault(permanent.getControllerId(), 0); + counts.put(permanent.getControllerId(), count + 1); } } } diff --git a/Mage.Sets/src/mage/cards/v/VileRedeemer.java b/Mage.Sets/src/mage/cards/v/VileRedeemer.java index ad2beefe04..c0618330d6 100644 --- a/Mage.Sets/src/mage/cards/v/VileRedeemer.java +++ b/Mage.Sets/src/mage/cards/v/VileRedeemer.java @@ -29,6 +29,7 @@ package mage.cards.v; import java.util.HashMap; import java.util.UUID; + import mage.MageInt; import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCostsImpl; @@ -52,13 +53,12 @@ import mage.players.Player; import mage.watchers.Watcher; /** - * * @author LevelX2 */ public class VileRedeemer extends CardImpl { public VileRedeemer(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}"); this.subtype.add("Eldrazi"); this.power = new MageInt(3); this.toughness = new MageInt(3); @@ -136,8 +136,7 @@ class VileRedeemerNonTokenCreaturesDiedWatcher extends Watcher { if (zEvent.isDiesEvent() && zEvent.getTarget() != null && zEvent.getTarget().isCreature() && !(zEvent.getTarget() instanceof PermanentToken)) { - int count = amountOfCreaturesThatDied.containsKey(zEvent.getTarget().getControllerId()) - ? amountOfCreaturesThatDied.get(zEvent.getTarget().getControllerId()) : 0; + int count = getAmountOfNontokenCreatureDiedThisTurn(zEvent.getTargetId()); amountOfCreaturesThatDied.put(zEvent.getTarget().getControllerId(), ++count); } } diff --git a/Mage.Sets/src/mage/cards/v/VorracBattlehorns.java b/Mage.Sets/src/mage/cards/v/VorracBattlehorns.java index 367ca1a8c1..003c041f2e 100644 --- a/Mage.Sets/src/mage/cards/v/VorracBattlehorns.java +++ b/Mage.Sets/src/mage/cards/v/VorracBattlehorns.java @@ -93,7 +93,7 @@ class CantBeBlockedByMoreThanOneAttachedEffect extends ContinuousEffectImpl { super(duration, Outcome.Benefit); this.amount = amount; this.attachmentType = attachmentType; - staticText = (attachmentType == AttachmentType.AURA ? "Enchanted" : "Equipped") + " creature can't be blocked by more than " + CardUtil.numberToText(amount) + " creature" + (amount==1 ?"":"s"); + staticText = attachmentType.verb() + " creature can't be blocked by more than " + CardUtil.numberToText(amount) + " creature" + (amount==1 ?"":"s"); } public CantBeBlockedByMoreThanOneAttachedEffect(final CantBeBlockedByMoreThanOneAttachedEffect effect) {