diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java index 7697ea27ac..bb8e03f3c6 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java @@ -1288,45 +1288,36 @@ public class ContinuousEffects implements Serializable { switch (effect.getEffectType()) { case REPLACEMENT: case REDIRECTION: - ReplacementEffect newReplacementEffect = (ReplacementEffect) effect; - replacementEffects.addEffect(newReplacementEffect, source); + replacementEffects.addEffect((ReplacementEffect) effect, source); break; case PREVENTION: - PreventionEffect newPreventionEffect = (PreventionEffect) effect; - preventionEffects.addEffect(newPreventionEffect, source); + preventionEffects.addEffect((PreventionEffect) effect, source); break; case RESTRICTION: - RestrictionEffect newRestrictionEffect = (RestrictionEffect) effect; - restrictionEffects.addEffect(newRestrictionEffect, source); + restrictionEffects.addEffect((RestrictionEffect) effect, source); break; case RESTRICTION_UNTAP_NOT_MORE_THAN: - RestrictionUntapNotMoreThanEffect newRestrictionUntapNotMoreThanEffect = (RestrictionUntapNotMoreThanEffect) effect; - restrictionUntapNotMoreThanEffects.addEffect(newRestrictionUntapNotMoreThanEffect, source); + restrictionUntapNotMoreThanEffects.addEffect((RestrictionUntapNotMoreThanEffect) effect, source); break; case REQUIREMENT: - RequirementEffect newRequirementEffect = (RequirementEffect) effect; - requirementEffects.addEffect(newRequirementEffect, source); + requirementEffects.addEffect((RequirementEffect) effect, source); break; case ASTHOUGH: AsThoughEffect newAsThoughEffect = (AsThoughEffect) effect; - if (!asThoughEffectsMap.containsKey(newAsThoughEffect.getAsThoughEffectType())) { + asThoughEffectsMap.computeIfAbsent(newAsThoughEffect.getAsThoughEffectType(), x -> { ContinuousEffectsList list = new ContinuousEffectsList<>(); allEffectsLists.add(list); - asThoughEffectsMap.put(newAsThoughEffect.getAsThoughEffectType(), list); - } - asThoughEffectsMap.get(newAsThoughEffect.getAsThoughEffectType()).addEffect(newAsThoughEffect, source); + return list; + }).addEffect(newAsThoughEffect, source); break; case COSTMODIFICATION: - CostModificationEffect newCostModificationEffect = (CostModificationEffect) effect; - costModificationEffects.addEffect(newCostModificationEffect, source); + costModificationEffects.addEffect((CostModificationEffect) effect, source); break; case SPLICE: - SpliceCardEffect newSpliceCardEffect = (SpliceCardEffect) effect; - spliceCardEffects.addEffect(newSpliceCardEffect, source); + spliceCardEffects.addEffect((SpliceCardEffect) effect, source); break; case CONTINUOUS_RULE_MODIFICATION: - ContinuousRuleModifyingEffect newContinuousRuleModifiyingEffect = (ContinuousRuleModifyingEffect) effect; - continuousRuleModifyingEffects.addEffect(newContinuousRuleModifiyingEffect, source); + continuousRuleModifyingEffects.addEffect((ContinuousRuleModifyingEffect) effect, source); break; default: layeredEffects.addEffect(effect, source); diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffectsList.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffectsList.java index 502bca43c5..cbac4704dd 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffectsList.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffectsList.java @@ -192,24 +192,19 @@ public class ContinuousEffectsList extends ArrayList * @param source - connected ability */ public void addEffect(T effect, Ability source) { - if (effectAbilityMap.containsKey(effect.getId())) { - Set set = effectAbilityMap.get(effect.getId()); - for (Ability ability : set) { - if (ability.getId().equals(source.getId()) && ability.getSourceId().equals(source.getSourceId())) { - return; - } - } - set.add(source); + Set set = effectAbilityMap.computeIfAbsent(effect.getId(), x -> new HashSet<>()); + if (set.stream() + .filter(ability -> ability.getId().equals(source.getId())) + .map(Ability::getId) + .anyMatch(source.getId()::equals)) { return; } - Set set = new HashSet<>(); set.add(source); - this.effectAbilityMap.put(effect.getId(), set); this.add(effect); } public Set getAbility(UUID effectId) { - return effectAbilityMap.getOrDefault(effectId, new HashSet<>()); + return effectAbilityMap.computeIfAbsent(effectId, x -> new HashSet<>()); } public void removeTemporaryEffects() { @@ -230,7 +225,7 @@ public class ContinuousEffectsList extends ArrayList @Override public boolean contains(Object object) { - if (object == null || !(object instanceof ContinuousEffect)) { + if (!(object instanceof ContinuousEffect)) { return false; }