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