Code cleanup

This commit is contained in:
drdev
2014-10-09 01:36:52 +00:00
parent 5e22f01358
commit 1ac14d3a29
2 changed files with 10 additions and 93 deletions

View File

@@ -36,12 +36,13 @@ import java.util.List;
* @version $Id$ * @version $Id$
*/ */
public class PlayerZone extends Zone { public class PlayerZone extends Zone {
/** Constant <code>serialVersionUID=-5687652485777639176L</code>. */
private static final long serialVersionUID = -5687652485777639176L;
// the this is not the owner of the card // the this is not the owner of the card
private final class AlienCardsActivationFilter implements Predicate<Card> { private final class AlienCardsActivationFilter implements Predicate<Card> {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
if (c.hasStartOfKeyword("May be played by your opponent") if (c.hasStartOfKeyword("May be played by your opponent")
|| c.hasKeyword("Your opponent may look at this card.")) { || c.hasKeyword("Your opponent may look at this card.")) {
return true; return true;
@@ -78,59 +79,36 @@ public class PlayerZone extends Zone {
} }
} }
/** Constant <code>serialVersionUID=-5687652485777639176L</code>. */
private static final long serialVersionUID = -5687652485777639176L;
private final Player player; private final Player player;
public PlayerZone(final ZoneType zone, final Player inPlayer) { public PlayerZone(final ZoneType zone, final Player inPlayer) {
super(zone, inPlayer.getGame()); super(zone, inPlayer.getGame());
this.player = inPlayer; this.player = inPlayer;
} }
/**
* <p>
* Getter for the field <code>player</code>.
* </p>
*
* @return a {@link forge.game.player.Player} object.
*/
public final Player getPlayer() { public final Player getPlayer() {
return this.player; return this.player;
} }
/**
* <p>
* toString.
* </p>
*
* @return a {@link java.lang.String} object.
*/
@Override @Override
public final String toString() { public final String toString() {
return String.format("%s %s", Lang.getPossesive(this.player.toString()), this.zoneType); return String.format("%s %s", Lang.getPossesive(this.player.toString()), this.zoneType);
} }
public List<Card> getCardsPlayerCanActivate(Player who) { public List<Card> getCardsPlayerCanActivate(Player who) {
Iterable<Card> cl = roCardList; // copy to new AL won't help here Iterable<Card> cl = roCardList; // copy to new AL won't help here
// Only check the top card of the library // Only check the top card of the library
if (is(ZoneType.Library)) { if (is(ZoneType.Library)) {
cl = Iterables.limit(cl, 1); cl = Iterables.limit(cl, 1);
} }
boolean checkingForOwner = who == this.player; boolean checkingForOwner = who == this.player;
if (checkingForOwner && (this.is(ZoneType.Battlefield) || this.is(ZoneType.Hand))) if (checkingForOwner && (this.is(ZoneType.Battlefield) || this.is(ZoneType.Hand))) {
return roCardList; return roCardList;
}
final Predicate<Card> filterPredicate = checkingForOwner ? new OwnCardsActivationFilter() : new AlienCardsActivationFilter(); final Predicate<Card> filterPredicate = checkingForOwner ? new OwnCardsActivationFilter() : new AlienCardsActivationFilter();
return Lists.newArrayList(cl = Iterables.filter(cl, filterPredicate)); return Lists.newArrayList(cl = Iterables.filter(cl, filterPredicate));
} }
} }

View File

@@ -43,10 +43,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
* @version $Id: PlayerZone.java 17582 2012-10-19 22:39:09Z Max mtg $ * @version $Id: PlayerZone.java 17582 2012-10-19 22:39:09Z Max mtg $
*/ */
public class Zone implements java.io.Serializable, Iterable<Card> { public class Zone implements java.io.Serializable, Iterable<Card> {
/** Constant <code>serialVersionUID=-5687652485777639176L</code>. */
private static final long serialVersionUID = -5687652485777639176L; private static final long serialVersionUID = -5687652485777639176L;
/** The cards. */
private final transient List<Card> cardList = new CopyOnWriteArrayList<Card>(); private final transient List<Card> cardList = new CopyOnWriteArrayList<Card>();
protected final transient List<Card> roCardList; protected final transient List<Card> roCardList;
protected final ZoneType zoneType; protected final ZoneType zoneType;
@@ -118,8 +116,6 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
return zone == zoneType; return zone == zoneType;
} }
// PlayerZone should override it with a correct implementation
public final boolean is(final ZoneType zone, final Player player) { public final boolean is(final ZoneType zone, final Player player) {
return zoneType == zone && player == getPlayer(); return zoneType == zone && player == getPlayer();
} }
@@ -137,76 +133,35 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
} }
public final List<Card> getCards() { public final List<Card> getCards() {
//System.out.println(zoneName + ": " + Integer.toHexString(System.identityHashCode(roCardList)));
return getCards(true); return 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 return roCardList; // Non-Battlefield PlayerZones don't care about the filter
return roCardList;
} }
/*
* (non-Javadoc)
*
* @see forge.IPlayerZone#isEmpty()
*/
public final boolean isEmpty() { public final boolean isEmpty() {
return cardList.isEmpty(); return cardList.isEmpty();
} }
/**
* <p>
* Getter for the field <code>cardsAddedThisTurn</code>.
* </p>
*/
public final MapOfLists<ZoneType, Card> getCardsAddedThisTurn() { public final MapOfLists<ZoneType, Card> getCardsAddedThisTurn() {
return cardsAddedThisTurn; return cardsAddedThisTurn;
} }
/**
* <p>
* Getter for the field <code>cardsAddedLastTurn</code>.
* </p>
*/
public final MapOfLists<ZoneType, Card> getCardsAddedLastTurn() { public final MapOfLists<ZoneType, Card> getCardsAddedLastTurn() {
return cardsAddedLastTurn; return cardsAddedLastTurn;
} }
/**
* <p>
* Getter for the field <code>cardsAddedThisTurn</code>.
* </p>
*
* @param origin
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final List<Card> getCardsAddedThisTurn(final ZoneType origin) { public final List<Card> getCardsAddedThisTurn(final ZoneType origin) {
//System.out.print("Request cards put into " + getZoneType() + " from " + origin + ".Amount: "); //System.out.print("Request cards put into " + getZoneType() + " from " + origin + ".Amount: ");
return getCardsAdded(cardsAddedThisTurn, origin); return getCardsAdded(cardsAddedThisTurn, origin);
} }
/**
* <p>
* Getter for the field <code>getcardsAddedLastTurn</code>.
* </p>
*
* @param origin
* a {@link java.lang.String} object.
* @return a {@link forge.CardList} object.
*/
public final List<Card> getCardsAddedLastTurn(final ZoneType origin) { public final List<Card> getCardsAddedLastTurn(final ZoneType origin) {
//System.out.print("Last turn - Request cards put into " + getZoneType() + " from " + origin + ".Amount: "); //System.out.print("Last turn - Request cards put into " + getZoneType() + " from " + origin + ".Amount: ");
return getCardsAdded(cardsAddedLastTurn, origin); return getCardsAdded(cardsAddedLastTurn, origin);
} }
/**
* <p>
* getCardsAdded.
* </p>
*/
private final List<Card> getCardsAdded(final MapOfLists<ZoneType, Card> cardsAdded, final ZoneType origin) { private final List<Card> getCardsAdded(final MapOfLists<ZoneType, Card> cardsAdded, final ZoneType origin) {
if (origin != null) { if (origin != null) {
Collection<Card> cards = cardsAdded.get(origin); Collection<Card> cards = cardsAdded.get(origin);
@@ -221,11 +176,6 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
return ret; return ret;
} }
/**
* <p>
* resetCardsAddedThisTurn.
* </p>
*/
public final void resetCardsAddedThisTurn() { public final void resetCardsAddedThisTurn() {
cardsAddedLastTurn.clear(); cardsAddedLastTurn.clear();
for (Entry<ZoneType, Collection<Card>> entry : cardsAddedThisTurn.entrySet()) { for (Entry<ZoneType, Collection<Card>> entry : cardsAddedThisTurn.entrySet()) {
@@ -234,26 +184,15 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
cardsAddedThisTurn.clear(); cardsAddedThisTurn.clear();
} }
/* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/
@Override @Override
public Iterator<Card> iterator() { public Iterator<Card> iterator() {
return roCardList.iterator(); return roCardList.iterator();
} }
public void shuffle() public void shuffle() {
{
Collections.shuffle(cardList); Collections.shuffle(cardList);
} }
/**
* <p>
* toString.
* </p>
*
* @return a {@link java.lang.String} object.
*/
@Override @Override
public String toString() { public String toString() {
return zoneType.toString(); return zoneType.toString();