* Player: isPlayer was duplicating equals method

* CardLists may accept any iterable<card> for filtering 
- warnings
This commit is contained in:
Maxmtg
2012-10-05 20:40:31 +00:00
parent 5e434e7b60
commit c8398ed6d0
18 changed files with 53 additions and 68 deletions

View File

@@ -6472,17 +6472,17 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("YouCtrl")) { } else if (property.startsWith("YouCtrl")) {
if (!this.getController().isPlayer(sourceController)) { if (!this.getController().equals(sourceController)) {
return false; return false;
} }
} else if (property.startsWith("YouDontCtrl")) { } else if (property.startsWith("YouDontCtrl")) {
if (this.getController().isPlayer(sourceController)) { if (this.getController().equals(sourceController)) {
return false; return false;
} }
} else if (property.startsWith("EnchantedPlayerCtrl")) { } else if (property.startsWith("EnchantedPlayerCtrl")) {
final Object o = source.getEnchanting(); final Object o = source.getEnchanting();
if (o instanceof Player) { if (o instanceof Player) {
if (!this.getController().isPlayer((Player) o)) { if (!this.getController().equals((Player) o)) {
return false; return false;
} }
} else { // source not enchanting a player } else { // source not enchanting a player
@@ -6493,7 +6493,7 @@ public class Card extends GameEntity implements Comparable<Card> {
final Card newCard = AllZoneUtil.getCardState(source); final Card newCard = AllZoneUtil.getCardState(source);
for (final Object o : newCard.getRemembered()) { for (final Object o : newCard.getRemembered()) {
if (o instanceof Player) { if (o instanceof Player) {
if (!this.getController().isPlayer((Player) o)) { if (!this.getController().equals((Player) o)) {
return false; return false;
} }
} }
@@ -6502,7 +6502,7 @@ public class Card extends GameEntity implements Comparable<Card> {
for (final Object o : source.getRemembered()) { for (final Object o : source.getRemembered()) {
if (o instanceof Player) { if (o instanceof Player) {
if (!this.getController().isPlayer((Player) o)) { if (!this.getController().equals((Player) o)) {
return false; return false;
} }
} }
@@ -6514,7 +6514,7 @@ public class Card extends GameEntity implements Comparable<Card> {
if (parent.getTarget() != null) { if (parent.getTarget() != null) {
for (final Object o : parent.getTarget().getTargetPlayers()) { for (final Object o : parent.getTarget().getTargetPlayers()) {
if (o instanceof Player) { if (o instanceof Player) {
if (!this.getController().isPlayer((Player) o)) { if (!this.getController().equals((Player) o)) {
return false; return false;
} }
} }
@@ -6528,13 +6528,13 @@ public class Card extends GameEntity implements Comparable<Card> {
final ArrayList<SpellAbility> sas = AbilityFactory.getDefinedSpellAbilities(source, "Targeted", sa); final ArrayList<SpellAbility> sas = AbilityFactory.getDefinedSpellAbilities(source, "Targeted", sa);
for (final Card c : list) { for (final Card c : list) {
final Player p = c.getController(); final Player p = c.getController();
if (!this.getController().isPlayer(p)) { if (!this.getController().equals(p)) {
return false; return false;
} }
} }
for (final SpellAbility s : sas) { for (final SpellAbility s : sas) {
final Player p = s.getSourceCard().getController(); final Player p = s.getSourceCard().getController();
if (!this.getController().isPlayer(p)) { if (!this.getController().equals(p)) {
return false; return false;
} }
} }
@@ -6548,11 +6548,11 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("YouOwn")) { } else if (property.startsWith("YouOwn")) {
if (!this.getOwner().isPlayer(sourceController)) { if (!this.getOwner().equals(sourceController)) {
return false; return false;
} }
} else if (property.startsWith("YouDontOwn")) { } else if (property.startsWith("YouDontOwn")) {
if (this.getOwner().isPlayer(sourceController)) { if (this.getOwner().equals(sourceController)) {
return false; return false;
} }
} else if (property.startsWith("OwnedBy")) { } else if (property.startsWith("OwnedBy")) {
@@ -6561,7 +6561,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("OwnerDoesntControl")) { } else if (property.startsWith("OwnerDoesntControl")) {
if (this.getOwner().isPlayer(this.getController())) { if (this.getOwner().equals(this.getController())) {
return false; return false;
} }
} else if (property.startsWith("ControllerControls")) { } else if (property.startsWith("ControllerControls")) {
@@ -6925,15 +6925,15 @@ public class Card extends GameEntity implements Comparable<Card> {
return false; return false;
} }
} else if (property.startsWith("controllerWasDealtCombatDamageByThisTurn")) { } else if (property.startsWith("controllerWasDealtCombatDamageByThisTurn")) {
if (!(source.getDamageHistory().getDealtCombatDmgToHumanThisTurn() && this.getController().isPlayer(AllZone.getHumanPlayer())) if (!(source.getDamageHistory().getDealtCombatDmgToHumanThisTurn() && this.getController().equals(AllZone.getHumanPlayer()))
&& !(source.getDamageHistory().getDealtCombatDmgToComputerThisTurn() && this.getController().isPlayer( && !(source.getDamageHistory().getDealtCombatDmgToComputerThisTurn() && this.getController().equals(
AllZone.getComputerPlayer()))) { AllZone.getComputerPlayer()))) {
return false; return false;
} }
} else if (property.startsWith("controllerWasDealtDamageByThisTurn")) { } else if (property.startsWith("controllerWasDealtDamageByThisTurn")) {
if (!(source.getDamageHistory().getDealtDmgToHumanThisTurn() && this.getController().isPlayer(AllZone.getHumanPlayer())) if (!(source.getDamageHistory().getDealtDmgToHumanThisTurn() && this.getController().equals(AllZone.getHumanPlayer()))
&& !(source.getDamageHistory().getDealtDmgToComputerThisTurn() && this.getController() && !(source.getDamageHistory().getDealtDmgToComputerThisTurn() && this.getController()
.isPlayer(AllZone.getComputerPlayer()))) { .equals(AllZone.getComputerPlayer()))) {
return false; return false;
} }
} else if (property.startsWith("wasDealtDamageThisTurn")) { } else if (property.startsWith("wasDealtDamageThisTurn")) {

View File

@@ -300,38 +300,38 @@ public class CardLists {
Collections.shuffle(list, MyRandom.getRandom()); Collections.shuffle(list, MyRandom.getRandom());
} }
public static List<Card> filterControlledBy(List<Card> cardList, Player player) { public static List<Card> filterControlledBy(Iterable<Card> cardList, Player player) {
return CardLists.filter(cardList, CardPredicates.isController(player)); return CardLists.filter(cardList, CardPredicates.isController(player));
} }
public static List<Card> getValidCards(List<Card> cardList, String[] restrictions, Player sourceController, Card source) { public static List<Card> getValidCards(Iterable<Card> cardList, String[] restrictions, Player sourceController, Card source) {
return CardLists.filter(cardList, CardPredicates.restriction(restrictions, sourceController, source)); return CardLists.filter(cardList, CardPredicates.restriction(restrictions, sourceController, source));
} }
public static List<Card> getValidCards(List<Card> cardList, String restriction, Player sourceController, Card source) { public static List<Card> getValidCards(Iterable<Card> cardList, String restriction, Player sourceController, Card source) {
return CardLists.filter(cardList, CardPredicates.restriction(restriction.split(","), sourceController, source)); return CardLists.filter(cardList, CardPredicates.restriction(restriction.split(","), sourceController, source));
} }
public static List<Card> getTargetableCards(List<Card> cardList, SpellAbility source) { public static List<Card> getTargetableCards(Iterable<Card> cardList, SpellAbility source) {
return CardLists.filter(cardList, CardPredicates.isTargetableBy(source)); return CardLists.filter(cardList, CardPredicates.isTargetableBy(source));
} }
public static List<Card> getKeyword(List<Card> cardList, String keyword) { public static List<Card> getKeyword(Iterable<Card> cardList, String keyword) {
return CardLists.filter(cardList, CardPredicates.hasKeyword(keyword)); return CardLists.filter(cardList, CardPredicates.hasKeyword(keyword));
} }
public static List<Card> getNotKeyword(List<Card> cardList, String keyword) { public static List<Card> getNotKeyword(Iterable<Card> cardList, String keyword) {
return CardLists.filter(cardList, Predicates.not(CardPredicates.hasKeyword(keyword))); return CardLists.filter(cardList, Predicates.not(CardPredicates.hasKeyword(keyword)));
} }
// cardType is like "Land" or "Goblin", returns a new ArrayList<Card> that is a // cardType is like "Land" or "Goblin", returns a new ArrayList<Card> that is a
// subset of current CardList // subset of current CardList
public static List<Card> getNotType(List<Card> cardList, String cardType) { public static List<Card> getNotType(Iterable<Card> cardList, String cardType) {
return CardLists.filter(cardList, Predicates.not(CardPredicates.isType(cardType))); return CardLists.filter(cardList, Predicates.not(CardPredicates.isType(cardType)));
} }
public static List<Card> getType(List<Card> cardList, String cardType) { public static List<Card> getType(Iterable<Card> cardList, String cardType) {
return CardLists.filter(cardList, CardPredicates.isType(cardType)); return CardLists.filter(cardList, CardPredicates.isType(cardType));
} }
@@ -344,7 +344,7 @@ public class CardLists {
* @return a subset of this List<Card> whose items meet the filtering * @return a subset of this List<Card> whose items meet the filtering
* criteria; may be empty, but never null. * criteria; may be empty, but never null.
*/ */
public static List<Card> filter(List<Card> cardList, Predicate<Card> filt) { public static List<Card> filter(Iterable<Card> cardList, Predicate<Card> filt) {
return Lists.newArrayList(Iterables.filter(cardList, filt)); return Lists.newArrayList(Iterables.filter(cardList, filt));
} }

View File

@@ -43,7 +43,7 @@ public final class CardPredicates {
return new Predicate<Card>() { return new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
return c.getController().isPlayer(p); return c.getController().equals(p);
} }
}; };
} }
@@ -51,7 +51,7 @@ public final class CardPredicates {
return new Predicate<Card>() { return new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
return c.getOwner().isPlayer(p); return c.getOwner().equals(p);
} }
}; };
} }

View File

@@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.swing.JFrame; import javax.swing.JFrame;
@@ -1082,7 +1081,7 @@ public class GameAction {
final Player pl = (Player) entity; final Player pl = (Player) entity;
boolean invalid = false; boolean invalid = false;
if (tgt.canOnlyTgtOpponent() && !c.getController().getOpponent().isPlayer(pl)) { if (tgt.canOnlyTgtOpponent() && !c.getController().getOpponent().equals(pl)) {
invalid = true; invalid = true;
} else { } else {
if (pl.hasProtectionFrom(c)) { if (pl.hasProtectionFrom(c)) {

View File

@@ -888,10 +888,10 @@ public final class GameActionUtil {
GameActionUtil.playerCombatDamageWhirlingDervish(c); GameActionUtil.playerCombatDamageWhirlingDervish(c);
} }
if (player.isPlayer(AllZone.getHumanPlayer())) { if (player.equals(AllZone.getHumanPlayer())) {
c.getDamageHistory().setDealtDmgToHumanThisTurn(true); c.getDamageHistory().setDealtDmgToHumanThisTurn(true);
} }
if (player.isPlayer(AllZone.getComputerPlayer())) { if (player.equals(AllZone.getComputerPlayer())) {
c.getDamageHistory().setDealtDmgToComputerThisTurn(true); c.getDamageHistory().setDealtDmgToComputerThisTurn(true);
} }
} }
@@ -978,10 +978,10 @@ public final class GameActionUtil {
GameActionUtil.executeCelestialMantle(c); GameActionUtil.executeCelestialMantle(c);
} }
if (player.isPlayer(AllZone.getHumanPlayer())) { if (player.equals(AllZone.getHumanPlayer())) {
c.getDamageHistory().setDealtCombatDmgToHumanThisTurn(true); c.getDamageHistory().setDealtCombatDmgToHumanThisTurn(true);
} }
if (player.isPlayer(AllZone.getComputerPlayer())) { if (player.equals(AllZone.getComputerPlayer())) {
c.getDamageHistory().setDealtCombatDmgToComputerThisTurn(true); c.getDamageHistory().setDealtCombatDmgToComputerThisTurn(true);
} }
} // executeCombatDamageToPlayerEffects } // executeCombatDamageToPlayerEffects

View File

@@ -1673,7 +1673,7 @@ public class AbilityFactoryAttach {
if (!mandatory && card.isEquipment() && !targets.isEmpty()) { if (!mandatory && card.isEquipment() && !targets.isEmpty()) {
Card newTarget = (Card) targets.get(0); Card newTarget = (Card) targets.get(0);
//don't equip human creatures //don't equip human creatures
if (newTarget.getController().isPlayer(AllZone.getHumanPlayer())) { if (newTarget.getController().equals(AllZone.getHumanPlayer())) {
return false; return false;
} }

View File

@@ -409,7 +409,7 @@ public class AbilityFactoryCounters {
params.get("Defined"), sa); params.get("Defined"), sa);
// Don't activate Curse abilities on my cards and non-curse abilites // Don't activate Curse abilities on my cards and non-curse abilites
// on my opponents // on my opponents
if (cards.isEmpty() || !cards.get(0).getController().isPlayer(player)) { if (cards.isEmpty() || !cards.get(0).getController().equals(player)) {
return false; return false;
} }

View File

@@ -29,7 +29,6 @@ import forge.AllZoneUtil;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates;
import forge.Command; import forge.Command;
import forge.Singletons; import forge.Singletons;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;

View File

@@ -430,13 +430,13 @@ public class CardFactoryInstants {
final Card enchanting = c.getEnchantingCard(); final Card enchanting = c.getEnchantingCard();
if (enchanting != null) { if (enchanting != null) {
if ((enchanting.isAttacking() && enchanting.getController().isPlayer(you.getOpponent())) if ((enchanting.isAttacking() && enchanting.getController().equals(you.getOpponent()))
|| enchanting.getController().isPlayer(you)) { || enchanting.getController().equals(you)) {
return true; return true;
} }
} }
return (c.getOwner().isPlayer(you) && c.getController().isPlayer(you)); return (c.getOwner().equals(you) && c.getController().equals(you));
} }
}); });
for (final Card c : toReturn) { for (final Card c : toReturn) {

View File

@@ -29,6 +29,7 @@ import com.esotericsoftware.minlog.Log;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.AllZone; import forge.AllZone;
import forge.AllZoneUtil; import forge.AllZoneUtil;
@@ -1878,15 +1879,15 @@ public class CardFactoryUtil {
*/ */
public static List<Card> getActivateablesFromZone(final PlayerZone zone, final Player activator) { public static List<Card> getActivateablesFromZone(final PlayerZone zone, final Player activator) {
List<Card> cl = new ArrayList<Card>(zone.getCards()); Iterable<Card> cl = zone.getCards();
// Only check the top card of the library // Only check the top card of the library
if (zone.is(ZoneType.Library) && !cl.isEmpty()) { if (zone.is(ZoneType.Library)) {
cl = CardLists.createCardList(cl.get(0)); cl = Iterables.limit(cl, 1);
} }
if (activator.isPlayer(zone.getPlayer())) { if (activator.equals(zone.getPlayer())) {
cl = CardLists.filter(cl, new Predicate<Card>() { cl = Iterables.filter(cl, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
if (zone.is(ZoneType.Graveyard) && c.hasUnearth()) { if (zone.is(ZoneType.Graveyard) && c.hasUnearth()) {
@@ -1920,7 +1921,7 @@ public class CardFactoryUtil {
}); });
} else { } else {
// the activator is not the owner of the card // the activator is not the owner of the card
cl = CardLists.filter(cl, new Predicate<Card>() { cl = Iterables.filter(cl, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
@@ -1932,7 +1933,7 @@ public class CardFactoryUtil {
} }
}); });
} }
return cl; return Lists.newArrayList(cl);
} }
/** /**

View File

@@ -195,10 +195,10 @@ public class SpellAbilityRestriction extends SpellAbilityVariables {
if (!sa.isSpell() || cardZone.is(ZoneType.Battlefield) || !this.getZone().equals(ZoneType.Hand)) { if (!sa.isSpell() || cardZone.is(ZoneType.Battlefield) || !this.getZone().equals(ZoneType.Hand)) {
return false; return false;
} }
if (c.hasKeyword("May be played") && activator.isPlayer(c.getController())) { if (c.hasKeyword("May be played") && activator.equals(c.getController())) {
return true; return true;
} }
if (c.hasKeyword("May be played by your opponent") && !activator.isPlayer(c.getController())) { if (c.hasKeyword("May be played by your opponent") && !activator.equals(c.getController())) {
return true; return true;
} }
return false; return false;

View File

@@ -794,7 +794,7 @@ public class CombatUtil {
return false; return false;
} }
if (keyword.equals("No more than two creatures can attack you each combat.") && cntAttackers > 1 if (keyword.equals("No more than two creatures can attack you each combat.") && cntAttackers > 1
&& card.getController().getOpponent().isPlayer(c.getController())) { && card.getController().getOpponent().equals(c.getController())) {
return false; return false;
} }
if (keyword.equals("CARDNAME can only attack alone.") && combat.isAttacking(card)) { if (keyword.equals("CARDNAME can only attack alone.") && combat.isAttacking(card)) {

View File

@@ -83,7 +83,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
* @return a boolean. * @return a boolean.
*/ */
public final boolean isPlayerTurn(final Player player) { public final boolean isPlayerTurn(final Player player) {
return this.playerTurn.isPlayer(player); return this.playerTurn.equals(player);
} }
/** /**
@@ -691,7 +691,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
* @return a boolean. * @return a boolean.
*/ */
public final synchronized boolean is(final PhaseType phase, final Player player) { public final synchronized boolean is(final PhaseType phase, final Player player) {
return this.getPhase() == phase && this.getPlayerTurn().isPlayer(player); return this.getPhase() == phase && this.getPlayerTurn().equals(player);
} }
/** /**

View File

@@ -2066,7 +2066,7 @@ public class ComputerUtil {
// TODO: choose "worst" controlled enchanting Aura // TODO: choose "worst" controlled enchanting Aura
for (int j = 0; j < auras.size(); j++) { for (int j = 0; j < auras.size(); j++) {
final Card aura = auras.get(j); final Card aura = auras.get(j);
if (aura.getController().isPlayer(c.getController()) && list.contains(aura)) { if (aura.getController().equals(c.getController()) && list.contains(aura)) {
c = aura; c = aura;
break; break;
} }

View File

@@ -241,19 +241,6 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
*/ */
public abstract boolean isComputer(); public abstract boolean isComputer();
/**
* <p>
* isPlayer.
* </p>
*
* @param p1
* a {@link forge.game.player.Player} object.
* @return a boolean.
*/
public final boolean isPlayer(final Player p1) {
return (p1 != null) && p1.getName().equals(this.getName());
}
/** /**
* <p> * <p>
* getOpponent. * getOpponent.
@@ -1067,7 +1054,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
*/ */
@Override @Override
public final boolean canBeTargetedBy(final SpellAbility sa) { public final boolean canBeTargetedBy(final SpellAbility sa) {
if (this.hasKeyword("Shroud") || (!this.isPlayer(sa.getActivatingPlayer()) && this.hasKeyword("Hexproof")) if (this.hasKeyword("Shroud") || (!this.equals(sa.getActivatingPlayer()) && this.hasKeyword("Hexproof"))
|| this.hasProtectionFrom(sa.getSourceCard())) { || this.hasProtectionFrom(sa.getSourceCard())) {
return false; return false;
} }

View File

@@ -283,7 +283,7 @@ public class DefaultPlayerZone extends PlayerZone implements java.io.Serializabl
*/ */
@Override @Override
public final boolean is(final ZoneType zone, final Player player) { public final boolean is(final ZoneType zone, final Player player) {
return (zone.equals(this.zoneName) && this.player.isPlayer(player)); return (zone.equals(this.zoneName) && this.player.equals(player));
} }
/** /**

View File

@@ -984,7 +984,7 @@ public class MagicStack extends MyObservable {
} else if (source.hasKeyword("Rebound") } else if (source.hasKeyword("Rebound")
&& source.getCastFrom() == ZoneType.Hand && source.getCastFrom() == ZoneType.Hand
&& AllZone.getZoneOf(source).is(ZoneType.Stack) && AllZone.getZoneOf(source).is(ZoneType.Stack)
&& source.getOwner().isPlayer(source.getController())) //"If you cast this spell from your hand" && source.getOwner().equals(source.getController())) //"If you cast this spell from your hand"
{ {
//Move rebounding card to exile //Move rebounding card to exile

View File

@@ -20,7 +20,6 @@ package forge.gui.deckeditor.controllers;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import forge.AllZone;
import forge.Singletons; import forge.Singletons;
import forge.control.FControl; import forge.control.FControl;
import forge.deck.Deck; import forge.deck.Deck;