diff --git a/src/main/java/forge/card/BoosterGenerator.java b/src/main/java/forge/card/BoosterGenerator.java index 7abaf9d56eb..eed0b58e6a9 100644 --- a/src/main/java/forge/card/BoosterGenerator.java +++ b/src/main/java/forge/card/BoosterGenerator.java @@ -26,7 +26,8 @@ public class BoosterGenerator { // Function to open a booster as it is. /** The Constant IDENTITY_PICK. */ - public static final Lambda1, BoosterGenerator> IDENTITY_PICK = new Lambda1, BoosterGenerator>() { + public static final Lambda1, BoosterGenerator> IDENTITY_PICK + = new Lambda1, BoosterGenerator>() { @Override public List apply(final BoosterGenerator arg1) { return arg1.getBoosterPack(); @@ -43,7 +44,7 @@ public class BoosterGenerator { * @return the simple picker */ public static Closure1, BoosterGenerator> getSimplePicker(final BoosterGenerator source) { - return new Closure1, BoosterGenerator>(IDENTITY_PICK, source); + return new Closure1, BoosterGenerator>(BoosterGenerator.IDENTITY_PICK, source); } // These lists are to hold cards grouped by rarity in advance. @@ -59,7 +60,7 @@ public class BoosterGenerator { // private List commonCreatures; // private List commonNonCreatures; - private static final List emptyList = Collections.unmodifiableList(new ArrayList(0)); + private static final List EMPTY_LIST = Collections.unmodifiableList(new ArrayList(0)); // Modern boosters contain 10 commons, 3 uncommmons, 1 rare/mythic // They also contain 1 land and 1 token/rules, but we don't pick them now. @@ -78,8 +79,8 @@ public class BoosterGenerator { * the cards */ public BoosterGenerator(final Iterable cards) { - for (CardPrinted c : cards) { - addToRarity(c); + for (final CardPrinted c : cards) { + this.addToRarity(c); } } @@ -90,8 +91,8 @@ public class BoosterGenerator { * the d pool */ public BoosterGenerator(final Deck dPool) { - for (Entry e : dPool.getMain()) { - addToRarity(e.getKey()); + for (final Entry e : dPool.getMain()) { + this.addToRarity(e.getKey()); } } @@ -107,34 +108,35 @@ public class BoosterGenerator { if (!cardSet.canGenerateBooster()) { throw new InvalidParameterException("BoosterGenerator: Set " + cardSet + " cannot generate boosters!"); } - CardSet.BoosterData bs = cardSet.getBoosterData(); + final CardSet.BoosterData bs = cardSet.getBoosterData(); - numCommons = bs.getCommon(); - numUncommons = bs.getUncommon(); - numRareSlots = bs.getRare(); - numSpecials = bs.getSpecial(); - numDoubleFaced = bs.getDoubleFaced(); + this.numCommons = bs.getCommon(); + this.numUncommons = bs.getUncommon(); + this.numRareSlots = bs.getRare(); + this.numSpecials = bs.getSpecial(); + this.numDoubleFaced = bs.getDoubleFaced(); - Predicate filter = CardPrinted.Predicates.printedInSets(cardSet.getCode()); - List cardsInThisSet = filter.select(CardDb.instance().getAllCards()); + final Predicate filter = CardPrinted.Predicates.printedInSets(cardSet.getCode()); + final List cardsInThisSet = filter.select(CardDb.instance().getAllCards()); - for (CardPrinted c : cardsInThisSet) { - addToRarity(c); + for (final CardPrinted c : cardsInThisSet) { + this.addToRarity(c); // System.out.println(c); } // System.out.println("done"); } private List pickRandomCards(final List source, final int count) { - return pickRandomCards(source, count, false); + return this.pickRandomCards(source, count, false); } - private List pickRandomCards(final List source, final int count, boolean singleton) { + private List pickRandomCards(final List source, + final int count, final boolean singleton) { int listSize = source == null ? 0 : source.size(); - if (count <= 0 || listSize == 0) { - return emptyList; + if ((count <= 0) || (listSize == 0)) { + return BoosterGenerator.EMPTY_LIST; } - List result = new ArrayList(count); + final List result = new ArrayList(count); int index = Integer.MAX_VALUE; for (int iCard = 0; iCard < count; iCard++) { @@ -154,20 +156,21 @@ public class BoosterGenerator { return result; } - private List pickRandomRaresOrMythics(final List rares, final List mythics, final int count) { - int raresSize = rares == null ? 0 : rares.size(); - int mythicsSize = mythics == null ? 0 : mythics.size(); - if (count <= 0 || raresSize == 0) { - return emptyList; + private List pickRandomRaresOrMythics(final List rares, final List mythics, + final int count) { + final int raresSize = rares == null ? 0 : rares.size(); + final int mythicsSize = mythics == null ? 0 : mythics.size(); + if ((count <= 0) || (raresSize == 0)) { + return BoosterGenerator.EMPTY_LIST; } - List result = new ArrayList(count); + final List result = new ArrayList(count); int indexRares = Integer.MAX_VALUE; int indexMythics = Integer.MAX_VALUE; for (int iCard = 0; iCard < count; iCard++) { - int rollD8 = MyRandom.getRandom().nextInt(8); - boolean takeMythic = mythicsSize > 0 && rollD8 < 1; + final int rollD8 = MyRandom.getRandom().nextInt(8); + final boolean takeMythic = (mythicsSize > 0) && (rollD8 < 1); if (takeMythic) { if (indexRares >= raresSize) { Collections.shuffle(mythics, MyRandom.getRandom()); @@ -187,25 +190,30 @@ public class BoosterGenerator { return result; } - /** * Gets the booster pack. * * @return the booster pack */ public final List getBoosterPack() { - return getBoosterPack(numCommons, numUncommons, numRareSlots, 0, 0, numSpecials, numDoubleFaced, 0, 0); + return this.getBoosterPack(this.numCommons, this.numUncommons, this.numRareSlots, 0, 0, this.numSpecials, + this.numDoubleFaced, 0, 0); } - public final List getSingletonBoosterPack( final int nAnyCard) { - List temp = new ArrayList(); + /** + * Gets the singleton booster pack. + * + * @param nAnyCard the n any card + * @return the singleton booster pack + */ + public final List getSingletonBoosterPack(final int nAnyCard) { + final List temp = new ArrayList(); - temp.addAll(pickRandomCards(allButLands, nAnyCard, true)); + temp.addAll(this.pickRandomCards(this.allButLands, nAnyCard, true)); return temp; } - /** * So many parameters are needed for custom limited cardpools,. * @@ -233,9 +241,9 @@ public class BoosterGenerator { final int nRares, final int nMythics, final int nSpecs, final int nDoubls, final int nAnyCard, final int nLands) { - List temp = new ArrayList(); + final List temp = new ArrayList(); - temp.addAll(pickRandomCards(commons, nCom)); + temp.addAll(this.pickRandomCards(this.commons, nCom)); /* * if( nComCreat > 0 || nComNonCr > 0) { if * (commonNonCreatures.isEmpty()) { @@ -245,50 +253,50 @@ public class BoosterGenerator { * temp.addAll(pickRandomCards(commonNonCreatures, nComNonCr)); } */ - temp.addAll(pickRandomCards(uncommons, nUnc)); + temp.addAll(this.pickRandomCards(this.uncommons, nUnc)); if (nRareSlots > 0) { - temp.addAll(pickRandomRaresOrMythics(rares, mythics, nRareSlots)); + temp.addAll(this.pickRandomRaresOrMythics(this.rares, this.mythics, nRareSlots)); } - if (nRares > 0 || nMythics > 0) { - temp.addAll(pickRandomCards(rares, nRares)); - temp.addAll(pickRandomCards(mythics, nMythics)); + if ((nRares > 0) || (nMythics > 0)) { + temp.addAll(this.pickRandomCards(this.rares, nRares)); + temp.addAll(this.pickRandomCards(this.mythics, nMythics)); } if (nDoubls > 0) { - temp.addAll(pickRandomCards(doubleFaced, nDoubls)); + temp.addAll(this.pickRandomCards(this.doubleFaced, nDoubls)); } - temp.addAll(pickRandomCards(specials, nSpecs)); + temp.addAll(this.pickRandomCards(this.specials, nSpecs)); - temp.addAll(pickRandomCards(allButLands, nAnyCard)); + temp.addAll(this.pickRandomCards(this.allButLands, nAnyCard)); - temp.addAll(pickRandomCards(basicLands, nLands)); + temp.addAll(this.pickRandomCards(this.basicLands, nLands)); return temp; } private void addToRarity(final CardPrinted c) { - if(c.isAlternate()) { + if (c.isAlternate()) { return; } - if (c.isDoubleFaced() && numDoubleFaced > 0) { - doubleFaced.add(c); + if (c.isDoubleFaced() && (this.numDoubleFaced > 0)) { + this.doubleFaced.add(c); } else { switch (c.getRarity()) { case Common: - commons.add(c); + this.commons.add(c); break; case Uncommon: - uncommons.add(c); + this.uncommons.add(c); break; case Rare: - rares.add(c); + this.rares.add(c); break; case MythicRare: - mythics.add(c); + this.mythics.add(c); break; case Special: - specials.add(c); + this.specials.add(c); break; default: break; @@ -296,9 +304,9 @@ public class BoosterGenerator { } if (c.getCard().getType().isBasicLand()) { - basicLands.add(c); + this.basicLands.add(c); } else { - allButLands.add(c); + this.allButLands.add(c); } } diff --git a/src/main/java/forge/card/BoosterUtils.java b/src/main/java/forge/card/BoosterUtils.java index 6792139b927..251e00c57aa 100644 --- a/src/main/java/forge/card/BoosterUtils.java +++ b/src/main/java/forge/card/BoosterUtils.java @@ -39,13 +39,13 @@ public final class BoosterUtils { */ public static List getQuestStarterDeck(final Predicate filter, final int numCommon, final int numUncommon, final int numRare) { - ArrayList cards = new ArrayList(); + final ArrayList cards = new ArrayList(); // Each color should have around the same amount of monocolored cards // There should be 3 Colorless cards for every 4 cards in a single color // There should be 1 Multicolor card for every 4 cards in a single color - List> colorFilters = new ArrayList>(); + final List> colorFilters = new ArrayList>(); colorFilters.add(CardRules.Predicates.Presets.isMulticolor); for (int i = 0; i < 4; i++) { @@ -60,28 +60,29 @@ public final class BoosterUtils { colorFilters.add(CardRules.Predicates.Presets.isGreen); } - Iterable cardpool = CardDb.instance().getAllUniqueCards(); + final Iterable cardpool = CardDb.instance().getAllUniqueCards(); - cards.addAll(generateDefinetlyColouredCards(cardpool, + cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, Predicate.and(filter, CardPrinted.Predicates.Presets.isCommon), numCommon, colorFilters)); - cards.addAll(generateDefinetlyColouredCards(cardpool, + cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, Predicate.and(filter, CardPrinted.Predicates.Presets.isUncommon), numUncommon, colorFilters)); int nRares = numRare, nMythics = 0; - Predicate filterMythics = Predicate.and(filter, CardPrinted.Predicates.Presets.isMythicRare); - boolean haveMythics = filterMythics.any(cardpool); - for (int iSlot = 0; haveMythics && iSlot < numRare; iSlot++) { - if (MyRandom.getRandom().nextInt(7) < 1) { // a bit higher chance to get - // a mythic + final Predicate filterMythics = Predicate.and(filter, CardPrinted.Predicates.Presets.isMythicRare); + final boolean haveMythics = filterMythics.any(cardpool); + for (int iSlot = 0; haveMythics && (iSlot < numRare); iSlot++) { + if (MyRandom.getRandom().nextInt(7) < 1) { // a bit higher chance to + // get + // a mythic nRares--; nMythics++; } } - cards.addAll(generateDefinetlyColouredCards(cardpool, + cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, Predicate.and(filter, CardPrinted.Predicates.Presets.isRare), nRares, colorFilters)); if (nMythics > 0) { - cards.addAll(generateDefinetlyColouredCards(cardpool, filterMythics, nMythics, colorFilters)); + cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, filterMythics, nMythics, colorFilters)); } return cards; } @@ -102,9 +103,9 @@ public final class BoosterUtils { private static ArrayList generateDefinetlyColouredCards(final Iterable source, final Predicate filter, final int cntNeeded, final List> allowedColors) { // If color is null, use colorOrder progression to grab cards - ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList(); - int size = allowedColors == null ? 0 : allowedColors.size(); + final int size = allowedColors == null ? 0 : allowedColors.size(); Collections.shuffle(allowedColors); int cntMade = 0, iAttempt = 0; @@ -113,7 +114,7 @@ public final class BoosterUtils { int allowedMisses = (2 + size + 2) * cntNeeded; // lol, 2+2 is not magic // constant! - while (cntMade < cntNeeded && allowedMisses > 0) { + while ((cntMade < cntNeeded) && (allowedMisses > 0)) { CardPrinted card = null; if (size > 0) { @@ -128,7 +129,7 @@ public final class BoosterUtils { card = filter.random(source); } - if (card != null && !result.contains(card)) { + if ((card != null) && !result.contains(card)) { result.add(card); cntMade++; } else { @@ -153,8 +154,8 @@ public final class BoosterUtils { * @return the list */ public static List generateCards(final int num, final CardRarity rarity, final String color) { - Predicate whatYouWant = getPredicateForConditions(rarity, color); - return generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num); + final Predicate whatYouWant = BoosterUtils.getPredicateForConditions(rarity, color); + return BoosterUtils.generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num); } /** @@ -170,25 +171,26 @@ public final class BoosterUtils { * the color * @return the list */ - public static List generateCards(final Predicate filter, final int num, final CardRarity rarity, - final String color) { - Predicate whatYouWant = Predicate.and(filter, getPredicateForConditions(rarity, color)); - return generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num); + public static List generateCards(final Predicate filter, final int num, + final CardRarity rarity, final String color) { + final Predicate whatYouWant = Predicate.and(filter, + BoosterUtils.getPredicateForConditions(rarity, color)); + return BoosterUtils.generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num); } private static List generateDistinctCards(final Iterable source, final Predicate filter, final int cntNeeded) { - ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList(); int cntMade = 0; // This will prevent endless loop @ wh int allowedMisses = (2 + 2) * cntNeeded; // lol, 2+2 is not magic // constant! - while (cntMade < cntNeeded && allowedMisses > 0) { - CardPrinted card = filter.random(source); + while ((cntMade < cntNeeded) && (allowedMisses > 0)) { + final CardPrinted card = filter.random(source); - if (card != null && !result.contains(card)) { + if ((card != null) && !result.contains(card)) { result.add(card); cntMade++; } else { @@ -219,7 +221,7 @@ public final class BoosterUtils { if (StringUtils.isBlank(color)) { colorFilter = Predicate.getTrue(CardRules.class); } else { - String col = color.toLowerCase(); + final String col = color.toLowerCase(); if (col.startsWith("wh")) { colorFilter = CardRules.Predicates.Presets.isWhite; } else if (col.startsWith("bla")) { @@ -251,18 +253,18 @@ public final class BoosterUtils { * @return the variety */ public static List getVariety(final List in) { - List out = new ArrayList(); + final List out = new ArrayList(); Collections.shuffle(in, MyRandom.getRandom()); for (int i = 0; i < Constant.Color.COLORS.length; i++) { - CardPrinted check = findCardOfColor(in, i); + final CardPrinted check = BoosterUtils.findCardOfColor(in, i); if (check != null) { out.add(check); } } return out; - }// getVariety() + } // getVariety() /** * Find card of color. @@ -274,7 +276,7 @@ public final class BoosterUtils { * @return the card printed */ public static CardPrinted findCardOfColor(final List in, final int color) { - Predicate filter = CardRules.Predicates.Presets.colors.get(color); + final Predicate filter = CardRules.Predicates.Presets.colors.get(color); if (null == filter) { return null; } diff --git a/src/main/java/forge/card/CardCharacteristics.java b/src/main/java/forge/card/CardCharacteristics.java index 4d55acba677..bb7a6ebac76 100644 --- a/src/main/java/forge/card/CardCharacteristics.java +++ b/src/main/java/forge/card/CardCharacteristics.java @@ -31,10 +31,10 @@ public class CardCharacteristics { private ArrayList triggers = new ArrayList(); private ArrayList staticAbilities = new ArrayList(); private ArrayList staticAbilityStrings = new ArrayList(); - private String ImageFilename = ""; + private String imageFilename = ""; private String imageName = ""; private Map sVars = new TreeMap(); - private ArrayList Sets = new ArrayList(); + private ArrayList sets = new ArrayList(); /** * Gets the name. @@ -300,7 +300,7 @@ public class CardCharacteristics { * @return the imageFilename */ public final String getImageFilename() { - return ImageFilename; + return imageFilename; } /** @@ -310,7 +310,7 @@ public class CardCharacteristics { * the imageFilename to set */ public final void setImageFilename(final String imageFilename0) { - ImageFilename = imageFilename0; // TODO: Add 0 to parameter's name. + imageFilename = imageFilename0; // TODO: Add 0 to parameter's name. } /** @@ -339,7 +339,7 @@ public class CardCharacteristics { * @return the sets */ public final ArrayList getSets() { - return Sets; + return sets; } /** @@ -349,7 +349,7 @@ public class CardCharacteristics { * the sets to set */ public final void setSets(final ArrayList sets0) { - Sets = new ArrayList(sets0); // TODO: Add 0 to parameter's + sets = new ArrayList(sets0); // TODO: Add 0 to parameter's // name. } diff --git a/src/main/java/forge/card/CardColor.java b/src/main/java/forge/card/CardColor.java index 803d1d1d2d4..b117b9c8c69 100644 --- a/src/main/java/forge/card/CardColor.java +++ b/src/main/java/forge/card/CardColor.java @@ -49,7 +49,7 @@ public final class CardColor implements Comparable { } /** The null color. */ - public static CardColor nullColor = new CardColor(); + private static CardColor nullColor = new CardColor(); /** * Checks for any color. @@ -264,4 +264,22 @@ public final class CardColor implements Comparable { return "multi"; } } + + /** + * Gets the null color. + * + * @return the nullColor + */ + public static CardColor getNullColor() { + return nullColor; + } + + /** + * Sets the null color. + * + * @param nullColor the nullColor to set + */ + public static void setNullColor(CardColor nullColor) { + CardColor.nullColor = nullColor; // TODO: Add 0 to parameter's name. + } } diff --git a/src/main/java/forge/gui/deckeditor/PresetColumns.java b/src/main/java/forge/gui/deckeditor/PresetColumns.java index 4ff84dadcec..e3491b27d7c 100644 --- a/src/main/java/forge/gui/deckeditor/PresetColumns.java +++ b/src/main/java/forge/gui/deckeditor/PresetColumns.java @@ -23,7 +23,7 @@ public abstract class PresetColumns { } private static CardColor toColor(final InventoryItem i) { - return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.nullColor; + return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.getNullColor(); } private static String toPTL(final InventoryItem i) {