From e205fef7856d43a89622b6bbb28cd180ecd4a76f Mon Sep 17 00:00:00 2001 From: igoudt Date: Thu, 22 Mar 2018 10:10:46 +0100 Subject: [PATCH] added a removeIf and streams --- Mage/src/main/java/mage/game/GameState.java | 25 ++++++--------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/Mage/src/main/java/mage/game/GameState.java b/Mage/src/main/java/mage/game/GameState.java index 7dbfeedc9a..22cbccb7f9 100644 --- a/Mage/src/main/java/mage/game/GameState.java +++ b/Mage/src/main/java/mage/game/GameState.java @@ -29,6 +29,8 @@ package mage.game; import java.io.Serializable; import java.util.*; +import java.util.stream.Collectors; + import mage.MageObject; import mage.abilities.*; import mage.abilities.effects.ContinuousEffect; @@ -170,7 +172,7 @@ public class GameState implements Serializable, Copyable { this.watchers = state.watchers.copy(); for (Map.Entry entry : state.values.entrySet()) { if (entry.getValue() instanceof HashSet) { - this.values.put(entry.getKey(), (HashSet) ((HashSet) entry.getValue()).clone()); + this.values.put(entry.getKey(), ((HashSet) entry.getValue()).clone()); } else { this.values.put(entry.getKey(), entry.getValue()); } @@ -882,22 +884,12 @@ public class GameState implements Serializable, Copyable { } public void removeDelayedTriggeredAbility(UUID abilityId) { - for (DelayedTriggeredAbility ability : delayed) { - if (ability.getId().equals(abilityId)) { - delayed.remove(ability); - break; - } - } + delayed.removeIf(ability -> ability.getId().equals(abilityId)); } public List getTriggered(UUID controllerId) { - List triggereds = new ArrayList<>(); - for (TriggeredAbility ability : triggered) { - if (ability.getControllerId().equals(controllerId)) { - triggereds.add(ability); - } - } - return triggereds; + return triggered.stream().filter(triggeredAbility -> triggeredAbility.getControllerId().equals(controllerId)) + .collect(Collectors.toList()); } public DelayedTriggeredAbilities getDelayed() { @@ -1089,10 +1081,7 @@ public class GameState implements Serializable, Copyable { } public int getZoneChangeCounter(UUID objectId) { - if (this.zoneChangeCounter.containsKey(objectId)) { - return this.zoneChangeCounter.get(objectId); - } - return 1; + return zoneChangeCounter.getOrDefault(objectId, 1); } public void updateZoneChangeCounter(UUID objectId) {