rewrites to getOrDefault

This commit is contained in:
igoudt 2017-04-28 13:27:22 +02:00
parent f69ff3aca9
commit 3e5ff8ccb2
15 changed files with 41 additions and 97 deletions

View file

@ -47,7 +47,6 @@ import mage.util.CardUtil;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public class AlphaAuthority extends CardImpl {
@ -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) {

View file

@ -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

View file

@ -56,7 +56,6 @@ import java.util.Map;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public class ConduitOfRuin extends CardImpl {
@ -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

View file

@ -44,7 +44,6 @@ import java.util.HashMap;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public class DescentOfTheDragons extends CardImpl {
@ -95,12 +94,9 @@ 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);
}
}
}

View file

@ -46,7 +46,6 @@ import java.util.Map.Entry;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public class DreamSalvage extends CardImpl {
@ -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

View file

@ -45,7 +45,6 @@ import java.util.HashMap;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public class ErdwalIlluminator extends CardImpl {
@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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

View file

@ -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<UUID> cardsDrawn = new LinkedHashSet<>();
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
}
Set<UUID> cardsDrawn = cardsDrawnThisTurn.get(event.getPlayerId());
Set<UUID> 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<UUID> getCardsDrawnThisTurn(UUID playerId) {
return cardsDrawnThisTurn.getOrDefault(playerId, new LinkedHashSet<>());
}
@Override

View file

@ -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

View file

@ -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<UUID> cardsDrawn = new LinkedHashSet<>();
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
}
Set<UUID> cardsDrawn = cardsDrawnThisTurn.get(event.getPlayerId());
Set<UUID> cardsDrawn = getCardsDrawnThisTurn(event.getPlayerId());
cardsDrawn.add(event.getTargetId());
cardsDrawnThisTurn.put(event.getPlayerId(), cardsDrawn);
}
}
public Set<UUID> getCardsDrawnThisTurn(UUID playerId) {
return cardsDrawnThisTurn.get(playerId);
return cardsDrawnThisTurn.getOrDefault(playerId, new LinkedHashSet<>());
}
@Override

View file

@ -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);
}
}

View file

@ -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;
@ -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);
}
}
}

View file

@ -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,7 +53,6 @@ import mage.players.Player;
import mage.watchers.Watcher;
/**
*
* @author LevelX2
*/
public class VileRedeemer extends CardImpl {
@ -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);
}
}

View file

@ -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) {