contains() added to PlayerZone - that's another AllZoneUtil call eliminated as well as useless copying to arrays with the only purpose of checking

This commit is contained in:
Maxmtg
2011-09-20 02:37:44 +00:00
parent 608c8a4705
commit 613b5a2bbd
7 changed files with 17 additions and 34 deletions

View File

@@ -393,14 +393,14 @@ public final class AllZone implements NewConstants {
final FGameState gameState = Singletons.getModel().getGameState();
if (gameState == null) { return null; }
if (AllZoneUtil.isCardInZone(gameState.getStackZone(), c)) {
if (gameState.getStackZone().contains(c)) {
return gameState.getStackZone();
}
for (Player p : gameState.getPlayers()) {
for(Zone z : Player.ALL_ZONES) {
PlayerZone pz = p.getZone(z);
if ( AllZoneUtil.isCardInZone(pz, c) )
if (pz.contains(c))
return pz;
}
}

View File

@@ -135,34 +135,11 @@ public final class AllZoneUtil {
* @return true if the card is present in this player's hand; false otherwise
*/
public static boolean isCardInPlayerGraveyard(final Player player, final Card card) {
return isCardInZone(player.getZone(Constant.Zone.Graveyard), card);
return player.getZone(Constant.Zone.Graveyard).contains(card);
}
//////// HAND
/**
* answers the question "is a specific card in the specified zone?".
*
* @param pz the PlayerZone to check
* @param card the specific card to look for
* @return true if the card is present in this zone; false otherwise
*/
public static boolean isCardInZone(final PlayerZone pz, final Card card) {
if (card == null) {
return false;
}
for (Card c : pz.getCards()) {
if (c.equals(card)) {
return true;
}
}
return false;
}
/**
* answers the question "is the given card in any exile zone?".
*

View File

@@ -17,7 +17,7 @@ public class DefaultPlayerZone extends PlayerZone implements java.io.Serializabl
/** Constant <code>serialVersionUID=-5687652485777639176L</code>. */
private static final long serialVersionUID = -5687652485777639176L;
private ArrayList<Card> cards = new ArrayList<Card>();
private List<Card> cards = new ArrayList<Card>();
private final Constant.Zone zoneName;
private final Player player;
private boolean update = true;
@@ -161,6 +161,10 @@ public class DefaultPlayerZone extends PlayerZone implements java.io.Serializabl
c.setTurnInZone(AllZone.getPhase().getTurn());
update();
}
public final boolean contains(Card c) {
return cards.contains(c);
}
/**
*

View File

@@ -82,6 +82,8 @@ interface IPlayerZone {
Card[] getCards();
Card[] getCards(int n);
boolean contains(Card c);
/** isEmpty returns true if given zone contains no cards */
boolean isEmpty();

View File

@@ -502,7 +502,7 @@ class CardFactory_Auras {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
// Animate Dead got destroyed before its ability resolved
if (!AllZoneUtil.isCardInZone(play, card)) {
if (!play.contains(card)) {
return;
}
@@ -550,7 +550,7 @@ class CardFactory_Auras {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
if (AllZoneUtil.isCardInZone(play, c)) {
if (play.contains(c)) {
AllZone.getGameAction().sacrifice(c);
}
}
@@ -564,7 +564,7 @@ class CardFactory_Auras {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
if (AllZoneUtil.isCardInZone(play, c)) {
if (play.contains(c)) {
AllZone.getStack().addSimultaneousStackEntry(detach);
}

View File

@@ -249,7 +249,7 @@ public class CardFactory_Creatures {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
boolean canPlayLand = card.getController().canPlayLand();
return (AllZoneUtil.isCardInZone(play, card) && library.get(0).isLand() && canPlayLand);
return (play.contains(card) && library.get(0).isLand() && canPlayLand);
}
};//SpellAbility
@@ -814,7 +814,7 @@ public class CardFactory_Creatures {
PlayerZone grave = AllZone.getZoneOf(target[0]);
//checks to see if card is still in the graveyard
if (grave != null && AllZoneUtil.isCardInZone(grave, target[0])) {
if (grave != null && grave.contains(target[0])) {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
target[0].addController(card.getController());
AllZone.getGameAction().moveTo(play, target[0]);

View File

@@ -95,7 +95,7 @@ public class CostExile extends CostPartWithList {
Integer amount = convertAmount();
if (amount != null && typeList.size() < amount)
return false;
} else if (!AllZoneUtil.isCardInZone(zone, source))
} else if (!zone.contains(source))
return false;
return true;
@@ -341,7 +341,7 @@ public class CostExile extends CostPartWithList {
@Override
public void showMessage() {
Card card = sa.getSourceCard();
if (sa.getActivatingPlayer().isHuman() && AllZoneUtil.isCardInZone(sa.getActivatingPlayer().getZone(part.getFrom()), card)) {
if (sa.getActivatingPlayer().isHuman() && sa.getActivatingPlayer().getZone(part.getFrom()).contains(card)) {
StringBuilder sb = new StringBuilder();
sb.append(card.getName());
sb.append(" - Exile?");