a list that is null is just strange, just use an empty List

This commit is contained in:
igoudt 2018-03-22 10:11:19 +01:00
parent e205fef785
commit ad8b046b05

View file

@ -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<Watcher> emptyWatchers = new ArrayList<>();
private static final List<Ability> 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<Watcher> watchers = null;
protected List<Watcher> watchers = new ArrayList<>();
protected List<Ability> 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());
}
}
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<Watcher> getWatchers() {
if (watchers != null) {
return watchers;
} else {
return emptyWatchers;
}
}
@Override
public void addWatcher(Watcher watcher) {
if (watchers == null) {
watchers = new ArrayList<>();
}
watcher.setSourceId(this.sourceId);
watcher.setControllerId(this.controllerId);
watchers.add(watcher);