Code cleanup

This commit is contained in:
drdev
2013-12-08 17:49:49 +00:00
parent 0b9d254e12
commit 61fe9f2282

View File

@@ -57,52 +57,49 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
protected final transient MapOfLists<ZoneType, Card> cardsAddedThisTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists()); protected final transient MapOfLists<ZoneType, Card> cardsAddedThisTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists());
public Zone(final ZoneType zone, Game game) { public Zone(final ZoneType zone, Game game) {
this.zoneType = zone; this.zoneType = zone;
this.game = game; this.game = game;
this.roCardList = Collections.unmodifiableList(cardList); this.roCardList = Collections.unmodifiableList(cardList);
//System.out.println(zoneName + " (ct) " + Integer.toHexString(System.identityHashCode(roCardList))); //System.out.println(zoneName + " (ct) " + Integer.toHexString(System.identityHashCode(roCardList)));
} }
public Player getPlayer() { // generic zones like stack have no player associated public Player getPlayer() { // generic zones like stack have no player associated
return null; return null;
} }
public final void add(final Card c) { public final void add(final Card c) {
add(c, null); add(c, null);
} }
public void add(final Card c, final Integer index) { public void add(final Card c, final Integer index) {
// Immutable cards are usually emblems and effects // Immutable cards are usually emblems and effects
if (!c.isImmutable()) { if (!c.isImmutable()) {
final Zone oldZone = game.getZoneOf(c); final Zone oldZone = game.getZoneOf(c);
final ZoneType zt = oldZone == null ? ZoneType.Stack : oldZone.getZoneType(); final ZoneType zt = oldZone == null ? ZoneType.Stack : oldZone.getZoneType();
cardsAddedThisTurn.add(zt, c); cardsAddedThisTurn.add(zt, c);
} }
c.setTurnInZone(game.getPhaseHandler().getTurn()); c.setTurnInZone(game.getPhaseHandler().getTurn());
if (zoneType != ZoneType.Battlefield) { if (zoneType != ZoneType.Battlefield) {
c.setTapped(false); c.setTapped(false);
} }
c.setZone(this); c.setZone(this);
if ( index == null ) if (index == null) {
this.cardList.add(c); this.cardList.add(c);
else }
else {
this.cardList.add(index.intValue(), c); this.cardList.add(index.intValue(), c);
}
game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Added, c)); game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Added, c));
} }
public final boolean contains(final Card c) { public final boolean contains(final Card c) {
return this.cardList.contains(c); return this.cardList.contains(c);
} }
public final boolean contains(final Predicate<Card> condition) { public final boolean contains(final Predicate<Card> condition) {
return Iterables.any(this.cardList, condition); return Iterables.any(this.cardList, condition);
} }
@@ -112,7 +109,6 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Removed, c)); game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.Removed, c));
} }
public final void setCards(final Iterable<Card> cards) { public final void setCards(final Iterable<Card> cards) {
cardList.clear(); cardList.clear();
for (Card c : cards) { for (Card c : cards) {
@@ -120,10 +116,8 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
cardList.add(c); cardList.add(c);
} }
game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.ComplexUpdate, null)); game.fireEvent(new GameEventZone(zoneType, getPlayer(), EventValueChangeType.ComplexUpdate, null));
} }
public final boolean is(final ZoneType zone) { public final boolean is(final ZoneType zone) {
return zone == this.zoneType; return zone == this.zoneType;
} }
@@ -134,7 +128,6 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
return zoneType == zone && player == getPlayer(); return zoneType == zone && player == getPlayer();
} }
public final ZoneType getZoneType() { public final ZoneType getZoneType() {
return this.zoneType; return this.zoneType;
} }
@@ -143,7 +136,6 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
return this.cardList.size(); return this.cardList.size();
} }
public final Card get(final int index) { public final Card get(final int index) {
return this.cardList.get(index); return this.cardList.get(index);
} }
@@ -153,7 +145,6 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
return this.getCards(true); return this.getCards(true);
} }
public List<Card> getCards(final boolean filter) { public List<Card> getCards(final boolean filter) {
// Non-Battlefield PlayerZones don't care about the filter // Non-Battlefield PlayerZones don't care about the filter
return this.roCardList; return this.roCardList;
@@ -193,11 +184,12 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
Collection<Card> cards = cardsAddedThisTurn.get(origin); Collection<Card> cards = cardsAddedThisTurn.get(origin);
return cards == null ? Lists.<Card>newArrayList() : Lists.newArrayList(cards); return cards == null ? Lists.<Card>newArrayList() : Lists.newArrayList(cards);
} }
// all cards if key == null // all cards if key == null
final List<Card> ret = new ArrayList<Card>(); final List<Card> ret = new ArrayList<Card>();
for(Collection<Card> kv : cardsAddedThisTurn.values()) for (Collection<Card> kv : cardsAddedThisTurn.values()) {
ret.addAll(kv); ret.addAll(kv);
}
return ret; return ret;
} }
@@ -234,6 +226,4 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
public String toString() { public String toString() {
return this.zoneType.toString(); return this.zoneType.toString();
} }
} }