added a removeIf and streams

This commit is contained in:
igoudt 2018-03-22 10:10:46 +01:00
parent ddc43d05f6
commit e205fef785

View file

@ -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<GameState> {
this.watchers = state.watchers.copy();
for (Map.Entry<String, Object> 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<GameState> {
}
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<TriggeredAbility> getTriggered(UUID controllerId) {
List<TriggeredAbility> 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<GameState> {
}
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) {