Code cleanup: make a lot of methods static and remove some unnecessary interface implements and casts.

This commit is contained in:
elcnesh
2014-12-10 18:40:19 +00:00
parent 5055ed4d2b
commit 6de61cb9a6
10 changed files with 30 additions and 58 deletions

View File

@@ -93,7 +93,7 @@ public class AiAttackController {
attackers.add(c);
}
}
this.blockers = this.getPossibleBlockers(oppList, this.attackers);
this.blockers = getPossibleBlockers(oppList, this.attackers);
} // constructor
public AiAttackController(final Player ai, Card attacker) {
@@ -105,7 +105,7 @@ public class AiAttackController {
if (CombatUtil.canAttack(attacker, this.defendingOpponent)) {
attackers.add(attacker);
}
this.blockers = this.getPossibleBlockers(oppList, this.attackers);
this.blockers = getPossibleBlockers(oppList, this.attackers);
} // overloaded constructor to evaluate single specified attacker
public static List<Card> getOpponentCreatures(final Player defender) {
@@ -156,7 +156,7 @@ public class AiAttackController {
* a {@link forge.CardList} object.
* @return a {@link forge.CardList} object.
*/
public final List<Card> sortAttackers(final List<Card> in) {
public final static List<Card> sortAttackers(final List<Card> in) {
final List<Card> list = new ArrayList<Card>();
// Cards with triggers should come first (for Battle Cry)
@@ -219,7 +219,7 @@ public class AiAttackController {
return false;
}
public final List<Card> getPossibleBlockers(final List<Card> blockers, final List<Card> attackers) {
public final static List<Card> getPossibleBlockers(final List<Card> blockers, final List<Card> attackers) {
List<Card> possibleBlockers = new ArrayList<Card>(blockers);
possibleBlockers = CardLists.filter(possibleBlockers, new Predicate<Card>() {
@Override
@@ -230,7 +230,7 @@ public class AiAttackController {
return possibleBlockers;
}
public final boolean canBlockAnAttacker(final Card c, final List<Card> attackers) {
public final static boolean canBlockAnAttacker(final Card c, final List<Card> attackers) {
final List<Card> attackerList = new ArrayList<Card>(attackers);
if (!c.isCreature()) {
return false;
@@ -277,7 +277,7 @@ public class AiAttackController {
int blockersNeeded = this.oppList.size();
// don't hold back creatures that can't block any of the human creatures
final List<Card> list = this.getPossibleBlockers(attackers, this.oppList);
final List<Card> list = getPossibleBlockers(attackers, this.oppList);
//Calculate the amount of creatures necessary
for (int i = 0; i < list.size(); i++) {
@@ -307,7 +307,7 @@ public class AiAttackController {
// In addition, if the computer guesses it needs no blockers, make sure
// that
// it won't be surprised by Exalted
final int humanExaltedBonus = this.countExaltedBonus(opp);
final int humanExaltedBonus = countExaltedBonus(opp);
if (humanExaltedBonus > 0) {
final boolean finestHour = opp.isCardInPlay("Finest Hour");
@@ -316,7 +316,7 @@ public class AiAttackController {
//
// total attack = biggest creature + exalted, *2 if Rafiq is in
// play
int humanBasePower = this.getAttack(this.oppList.get(0)) + humanExaltedBonus;
int humanBasePower = getAttack(this.oppList.get(0)) + humanExaltedBonus;
if (finestHour) {
// For Finest Hour, one creature could attack and get the
// bonus TWICE
@@ -490,18 +490,6 @@ public class AiAttackController {
final boolean LOG_AI_ATTACKS = false;
public final List<Player> getDefendingPlayers(Combat combat) {
final List<Player> defending = new ArrayList<Player>();
for (final GameEntity o : combat.getDefenders()) {
if (o instanceof Player) {
defending.add((Player) o);
}
}
return defending;
}
/**
* <p>
* Getter for the field <code>attackers</code>.
@@ -806,7 +794,7 @@ public class AiAttackController {
System.out.println("Normal attack");
attackersLeft = this.notNeededAsBlockers(ai, attackersLeft);
attackersLeft = this.sortAttackers(attackersLeft);
attackersLeft = sortAttackers(attackersLeft);
if ( LOG_AI_ATTACKS )
System.out.println("attackersLeft = " + attackersLeft);
@@ -849,7 +837,7 @@ public class AiAttackController {
}
}
if (!found) {
defender = getDefendingPlayers(combat).get(0);
defender = combat.getDefendingPlayers().get(0);
}
}
}
@@ -866,7 +854,7 @@ public class AiAttackController {
* a {@link forge.game.player.Player} object.
* @return a int.
*/
public final int countExaltedBonus(final Player player) {
public final static int countExaltedBonus(final Player player) {
int bonus = 0;
for (Card c : player.getCardsIn(ZoneType.Battlefield)) {
bonus += c.getKeywordAmount("Exalted");
@@ -884,7 +872,7 @@ public class AiAttackController {
* a {@link forge.game.card.Card} object.
* @return a int.
*/
public final int getAttack(final Card c) {
public final static int getAttack(final Card c) {
int n = c.getNetCombatDamage();
if (c.hasKeyword("Double Strike")) {

View File

@@ -77,7 +77,7 @@ public class AiBlockController {
}
// finds the creatures able to block the attacker
private List<Card> getPossibleBlockers(final Combat combat, final Card attacker, final List<Card> blockersLeft, final boolean solo) {
private static List<Card> getPossibleBlockers(final Combat combat, final Card attacker, final List<Card> blockersLeft, final boolean solo) {
final List<Card> blockers = new ArrayList<Card>();
for (final Card blocker : blockersLeft) {
@@ -120,7 +120,7 @@ public class AiBlockController {
return blockers;
}
private List<CardCollection> sortAttackerByDefender(final Combat combat) {
private static List<CardCollection> sortAttackerByDefender(final Combat combat) {
FCollectionView<GameEntity> defenders = combat.getDefenders();
final ArrayList<CardCollection> attackers = new ArrayList<CardCollection>(defenders.size());
for (GameEntity defender : defenders) {

View File

@@ -362,7 +362,7 @@ public class AiController {
return spellAbilities;
}
private ArrayList<SpellAbility> getPlayableCounters(final CardCollection l) {
private static ArrayList<SpellAbility> getPlayableCounters(final CardCollection l) {
final ArrayList<SpellAbility> spellAbility = new ArrayList<SpellAbility>();
for (final Card c : l) {
for (final SpellAbility sa : c.getNonManaAbilities()) {

View File

@@ -23,7 +23,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class AiCostDecision extends CostDecisionMakerBase implements ICostVisitor<PaymentDecision> {
public class AiCostDecision extends CostDecisionMakerBase {
private final SpellAbility ability;
private final Card source;
@@ -593,7 +593,7 @@ public class AiCostDecision extends CostDecisionMakerBase implements ICostVisito
@Override
public PaymentDecision visit(CostUnattach cost) {
Card cardToUnattach = cost.findCardToUnattach(source, (Player) player, ability);
final Card cardToUnattach = cost.findCardToUnattach(source, player, ability);
if (cardToUnattach == null) {
// We really shouldn't be able to get here if there's nothing to unattach
return null;

View File

@@ -185,9 +185,9 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
}
}
private PaperCard getFirstWithImage(Collection<PaperCard> cards) {
private static PaperCard getFirstWithImage(final Collection<PaperCard> cards) {
//NOTE: this is written this way to avoid checking final card in list
Iterator<PaperCard> iterator = cards.iterator();
final Iterator<PaperCard> iterator = cards.iterator();
PaperCard pc = iterator.next();
while (iterator.hasNext()) {
if (pc.hasImage()) {

View File

@@ -17,13 +17,13 @@
*/
package forge.card;
import java.util.StringTokenizer;
import org.apache.commons.lang3.StringUtils;
import forge.card.mana.IParserManaCost;
import forge.card.mana.ManaCost;
import forge.card.mana.ManaCostShard;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
import java.util.StringTokenizer;
/**
* A collection of methods containing full
@@ -65,7 +65,7 @@ public final class CardRules implements ICardCharacteristics {
colorIdentity = newRules.colorIdentity;
}
private byte calculateColorIdentity(ICardFace face) {
private static byte calculateColorIdentity(final ICardFace face) {
byte res = face.getColor().getColor();
boolean isReminder = false;
boolean isSymbol = false;
@@ -154,7 +154,7 @@ public final class CardRules implements ICardCharacteristics {
}
}
private boolean canCastFace(ICardFace face, byte colorCode) {
private static boolean canCastFace(final ICardFace face, final byte colorCode) {
if (face.getManaCost().isNoCost()) {
//if card face has no cost, assume castable only by mana of its defined color
return face.getColor().hasNoColorsExcept(colorCode);
@@ -214,22 +214,6 @@ public final class CardRules implements ICardCharacteristics {
public String getPictureUrl(boolean backface ) { return backface ? dlUrlOtherSide : dlUrl; }
public void setDlUrls(String[] dlUrls) { this.dlUrl = dlUrls[0]; this.dlUrlOtherSide = dlUrls[1]; }
public final List<String> getReplacements() {
return null;
}
public final List<String> getTriggers() {
return null;
}
public final List<String> getStaticAbilities() {
return null;
}
public final List<String> getAbilities() {
return null;
}
public ColorSet getColorIdentity() {
return colorIdentity;
}

View File

@@ -248,7 +248,7 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
return subtypes.contains(creatureType) || subtypes.contains("AllCreatureTypes");
}
private String toMixedCase(final String s) {
private static String toMixedCase(final String s) {
if (s.equals("")) {
return s;
}

View File

@@ -194,7 +194,7 @@ public enum DeckFormat {
return null;
}
public String getPlaneSectionConformanceProblem(CardPool planes) {
public static String getPlaneSectionConformanceProblem(final CardPool planes) {
//Must contain at least 10 planes/phenomenons, but max 2 phenomenons. Singleton.
if (planes == null || planes.countAll() < 10) {
return "should have at least 10 planes";
@@ -214,7 +214,7 @@ public enum DeckFormat {
return null;
}
public String getSchemeSectionConformanceProblem(CardPool schemes) {
public static String getSchemeSectionConformanceProblem(final CardPool schemes) {
//Must contain at least 20 schemes, max 2 of each.
if (schemes == null || schemes.countAll() < 20) {
return "must contain at least 20 schemes";

View File

@@ -88,7 +88,7 @@ public class DeckStorage extends StorageReaderFolder<Deck> implements IItemSeria
return result;
}
private void adjustFileLocation(final File file, final Deck result) {
private static void adjustFileLocation(final File file, final Deck result) {
if (result == null) {
file.delete();
} else {

View File

@@ -272,7 +272,7 @@ public final class NameGenerator {
}
/** Generates a specified number of random names. */
public List<String> getRandomNames(int generateAmount, final List<String> excludeNames) {
public static List<String> getRandomNames(final int generateAmount, final List<String> excludeNames) {
usedNames = excludeNames;
final List<String> names = new ArrayList<String>(generateAmount);
for (int i = 0; i < generateAmount; i++) {