From ad8b046b05dfefebcc0d245408d69a1a00a2ec2a Mon Sep 17 00:00:00 2001 From: igoudt Date: Thu, 22 Mar 2018 10:11:19 +0100 Subject: [PATCH] a list that is null is just strange, just use an empty List --- .../main/java/mage/abilities/AbilityImpl.java | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index 0a4d958873..e990ffb9d1 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -27,10 +27,6 @@ */ package mage.abilities; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; import mage.MageObject; import mage.MageObjectReference; import mage.Mana; @@ -63,6 +59,11 @@ import mage.util.ThreadLocalStringBuilder; import mage.watchers.Watcher; import org.apache.log4j.Logger; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; + /** * @author BetaSteward_at_googlemail.com */ @@ -70,7 +71,6 @@ public abstract class AbilityImpl implements Ability { private static final Logger logger = Logger.getLogger(AbilityImpl.class); private static final ThreadLocalStringBuilder threadLocalBuilder = new ThreadLocalStringBuilder(100); - private static final List emptyWatchers = new ArrayList<>(); private static final List emptyAbilities = new ArrayList<>(); protected UUID id; @@ -95,7 +95,7 @@ public abstract class AbilityImpl implements Ability { protected boolean worksFaceDown = false; protected MageObject sourceObject; protected int sourceObjectZoneChangeCounter; - protected List watchers = null; + protected List watchers = new ArrayList<>(); protected List subAbilities = null; protected boolean canFizzle = true; protected TargetAdjustment targetAdjustment = TargetAdjustment.NONE; @@ -125,12 +125,10 @@ public abstract class AbilityImpl implements Ability { this.manaCostsToPay = ability.manaCostsToPay.copy(); this.costs = ability.costs.copy(); this.optionalCosts = ability.optionalCosts.copy(); - if (ability.watchers != null) { - this.watchers = new ArrayList<>(); - for (Watcher watcher : ability.watchers) { - watchers.add(watcher.copy()); - } + for (Watcher watcher : ability.watchers) { + watchers.add(watcher.copy()); } + if (ability.subAbilities != null) { this.subAbilities = new ArrayList<>(); for (Ability subAbility : ability.subAbilities) { @@ -623,11 +621,10 @@ public abstract class AbilityImpl implements Ability { @Override public void setControllerId(UUID controllerId) { this.controllerId = controllerId; - if (watchers != null) { for (Watcher watcher : watchers) { watcher.setControllerId(controllerId); } - } + if (subAbilities != null) { for (Ability subAbility : subAbilities) { subAbility.setControllerId(controllerId); @@ -652,11 +649,10 @@ public abstract class AbilityImpl implements Ability { subAbility.setSourceId(sourceId); } } - if (watchers != null) { for (Watcher watcher : watchers) { watcher.setSourceId(sourceId); } - } + } @Override @@ -718,18 +714,12 @@ public abstract class AbilityImpl implements Ability { @Override public List getWatchers() { - if (watchers != null) { - return watchers; - } else { - return emptyWatchers; - } + return watchers; } @Override public void addWatcher(Watcher watcher) { - if (watchers == null) { - watchers = new ArrayList<>(); - } + watcher.setSourceId(this.sourceId); watcher.setControllerId(this.controllerId); watchers.add(watcher);