diff --git a/src/main/java/forge/card/BoosterUtils.java b/src/main/java/forge/card/BoosterUtils.java index 9a8c573335d..187d205d6fd 100644 --- a/src/main/java/forge/card/BoosterUtils.java +++ b/src/main/java/forge/card/BoosterUtils.java @@ -63,12 +63,12 @@ public final class BoosterUtils { final Iterable cardpool = CardDb.instance().getAllUniqueCards(); cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, - Predicate.and(filter, CardPrinted.Predicates.Presets.isCommon), numCommon, colorFilters)); + Predicate.and(filter, CardPrinted.Predicates.Presets.IS_COMMON), numCommon, colorFilters)); cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, - Predicate.and(filter, CardPrinted.Predicates.Presets.isUncommon), numUncommon, colorFilters)); + Predicate.and(filter, CardPrinted.Predicates.Presets.IS_UNCOMMON), numUncommon, colorFilters)); int nRares = numRare, nMythics = 0; - final Predicate filterMythics = Predicate.and(filter, CardPrinted.Predicates.Presets.isMythicRare); + final Predicate filterMythics = Predicate.and(filter, CardPrinted.Predicates.Presets.IS_MYTHIC_RARE); 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 @@ -80,7 +80,7 @@ public final class BoosterUtils { } cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, - Predicate.and(filter, CardPrinted.Predicates.Presets.isRare), nRares, colorFilters)); + Predicate.and(filter, CardPrinted.Predicates.Presets.IS_RARE), nRares, colorFilters)); if (nMythics > 0) { cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, filterMythics, nMythics, colorFilters)); } @@ -120,7 +120,7 @@ public final class BoosterUtils { if (size > 0) { final Predicate color2 = allowedColors.get(iAttempt % size); if (color2 != null) { - card = Predicate.and(filter, color2, CardPrinted.fnGetRules).random(source); + card = Predicate.and(filter, color2, CardPrinted.FN_GET_RULES).random(source); } } @@ -205,13 +205,13 @@ public final class BoosterUtils { Predicate rFilter; switch (rarity) { case Rare: - rFilter = CardPrinted.Predicates.Presets.isRareOrMythic; + rFilter = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC; break; case Common: - rFilter = CardPrinted.Predicates.Presets.isCommon; + rFilter = CardPrinted.Predicates.Presets.IS_COMMON; break; case Uncommon: - rFilter = CardPrinted.Predicates.Presets.isUncommon; + rFilter = CardPrinted.Predicates.Presets.IS_UNCOMMON; break; default: rFilter = Predicate.getTrue(CardPrinted.class); @@ -240,7 +240,7 @@ public final class BoosterUtils { colorFilter = Predicate.getTrue(CardRules.class); } } - return Predicate.and(rFilter, colorFilter, CardPrinted.fnGetRules); + return Predicate.and(rFilter, colorFilter, CardPrinted.FN_GET_RULES); } // return List of 5 or 6 cards, one for each color and maybe an @@ -280,6 +280,6 @@ public final class BoosterUtils { if (null == filter) { return null; } - return filter.first(in, CardPrinted.fnGetRules); + return filter.first(in, CardPrinted.FN_GET_RULES); } } diff --git a/src/main/java/forge/game/GameFormat.java b/src/main/java/forge/game/GameFormat.java index 5da08e88d2f..9e6955a8ad4 100644 --- a/src/main/java/forge/game/GameFormat.java +++ b/src/main/java/forge/game/GameFormat.java @@ -38,15 +38,15 @@ public final class GameFormat { private Predicate buildFilterPritned() { final Predicate banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames); - final Predicate allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue + final Predicate allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.IS_TRUE : CardPrinted.Predicates.printedInSets(this.allowedSetCodes, true); return Predicate.and(banNames, allowSets); } private Predicate buildFilterRules() { final Predicate banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames); - final Predicate allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue - : Predicate.brigde(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.fnGetRules); + final Predicate allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.IS_TRUE + : Predicate.brigde(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.FN_GET_RULES); return Predicate.and(banNames, allowSets); } diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorCommon.java b/src/main/java/forge/gui/deckeditor/DeckEditorCommon.java index 465d10c674e..f2458f70b16 100644 --- a/src/main/java/forge/gui/deckeditor/DeckEditorCommon.java +++ b/src/main/java/forge/gui/deckeditor/DeckEditorCommon.java @@ -284,7 +284,7 @@ public final class DeckEditorCommon extends DeckEditorBase { protected Predicate buildFilter() { final Predicate cardFilter = Predicate.and( Predicate.and(this.getFilterBoxes().buildFilter(), this.filterNameTypeSet.buildFilter()), - CardPrinted.Predicates.Presets.nonAlternate); + CardPrinted.Predicates.Presets.NON_ALTERNATE); return Predicate.instanceOf(cardFilter, CardPrinted.class); } diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorQuestMenu.java b/src/main/java/forge/gui/deckeditor/DeckEditorQuestMenu.java index acda2fb2efc..5f7b9679ba9 100644 --- a/src/main/java/forge/gui/deckeditor/DeckEditorQuestMenu.java +++ b/src/main/java/forge/gui/deckeditor/DeckEditorQuestMenu.java @@ -205,23 +205,23 @@ public class DeckEditorQuestMenu extends JMenuBar { // creatures sb.append(String.format("%d Creatures%n-------------%n", - CardRules.Predicates.Presets.IS_CREATURE.aggregate(all, all.fnToCard, all.fnToCount))); - for (final Entry e : CardRules.Predicates.Presets.IS_CREATURE.select(all, all.fnToCard)) { + CardRules.Predicates.Presets.IS_CREATURE.aggregate(all, all.getFnToCard(), all.getFnToCount()))); + for (final Entry e : CardRules.Predicates.Presets.IS_CREATURE.select(all, all.getFnToCard())) { sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName())); } // spells sb.append(String.format("%d Spells%n----------%n", - CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL.aggregate(all, all.fnToCard, all.fnToCount))); + CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL.aggregate(all, all.getFnToCard(), all.getFnToCount()))); for (final Entry e : CardRules.Predicates.Presets.IS_NON_CREATURE_SPELL.select(all, - all.fnToCard)) { + all.getFnToCard())) { sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName())); } // lands sb.append(String.format("%d Land%n--------%n", - CardRules.Predicates.Presets.IS_LAND.aggregate(all, all.fnToCard, all.fnToCount))); - for (final Entry e : CardRules.Predicates.Presets.IS_LAND.select(all, all.fnToCard)) { + CardRules.Predicates.Presets.IS_LAND.aggregate(all, all.getFnToCard(), all.getFnToCount()))); + for (final Entry e : CardRules.Predicates.Presets.IS_LAND.select(all, all.getFnToCard())) { sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName())); } diff --git a/src/main/java/forge/gui/deckeditor/FilterCheckBoxes.java b/src/main/java/forge/gui/deckeditor/FilterCheckBoxes.java index a09da2c7331..72c66136b94 100644 --- a/src/main/java/forge/gui/deckeditor/FilterCheckBoxes.java +++ b/src/main/java/forge/gui/deckeditor/FilterCheckBoxes.java @@ -161,7 +161,7 @@ class FilterCheckBoxes { final Predicate filterByType = types.size() == 7 ? CardRules.Predicates.Presets.CONSTANT_TRUE : Predicate.or(types); - return Predicate.brigde(Predicate.and(filterByColor, filterByType), CardPrinted.fnGetRules); + return Predicate.brigde(Predicate.and(filterByColor, filterByType), CardPrinted.FN_GET_RULES); } /** diff --git a/src/main/java/forge/gui/deckeditor/FilterNameTypeSetPanel.java b/src/main/java/forge/gui/deckeditor/FilterNameTypeSetPanel.java index 3aae1659c0e..f0df6424203 100644 --- a/src/main/java/forge/gui/deckeditor/FilterNameTypeSetPanel.java +++ b/src/main/java/forge/gui/deckeditor/FilterNameTypeSetPanel.java @@ -112,12 +112,12 @@ public class FilterNameTypeSetPanel extends JComponent { if (StringUtils.isNotBlank(this.txtCardType.getText())) { rules.add(Predicate.brigde(CardRules.Predicates.joinedType(StringOp.CONTAINS, this.txtCardType.getText()), - CardPrinted.fnGetRules)); + CardPrinted.FN_GET_RULES)); } if (StringUtils.isNotBlank(this.txtCardRules.getText())) { rules.add(Predicate.brigde(CardRules.Predicates.rules(StringOp.CONTAINS, this.txtCardRules.getText()), - CardPrinted.fnGetRules)); + CardPrinted.FN_GET_RULES)); } if (this.searchSetCombo.getSelectedIndex() != 0) { diff --git a/src/main/java/forge/gui/deckeditor/TableWithCards.java b/src/main/java/forge/gui/deckeditor/TableWithCards.java index ce5fa260e4d..46c0d5d561e 100644 --- a/src/main/java/forge/gui/deckeditor/TableWithCards.java +++ b/src/main/java/forge/gui/deckeditor/TableWithCards.java @@ -171,8 +171,8 @@ public final class TableWithCards { */ public static String getStats(final ItemPoolView deck) { final int total = deck.countAll(); - final int creature = CardRules.Predicates.Presets.IS_CREATURE.aggregate(deck, deck.fnToCard, deck.fnToCount); - final int land = CardRules.Predicates.Presets.IS_LAND.aggregate(deck, deck.fnToCard, deck.fnToCount); + final int creature = CardRules.Predicates.Presets.IS_CREATURE.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + final int land = CardRules.Predicates.Presets.IS_LAND.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); final StringBuffer show = new StringBuffer(); show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ") @@ -180,7 +180,7 @@ public final class TableWithCards { final String[] color = Constant.Color.ONLY_COLORS; final List> predicates = CardRules.Predicates.Presets.COLORS; for (int i = 0; i < color.length; ++i) { - show.append(String.format(", %s - %d", color[i], predicates.get(i).count(deck, deck.fnToCard))); + show.append(String.format(", %s - %d", color[i], predicates.get(i).count(deck, deck.getFnToCard()))); } return show.toString(); @@ -344,12 +344,12 @@ public final class TableWithCards { } if (useFilter && this.wantUnique) { - this.model.addCards(this.filter.uniqueByLast(this.pool, this.pool.fnToCardName, this.pool.fnToPrinted)); + this.model.addCards(this.filter.uniqueByLast(this.pool, this.pool.getFnToCardName(), this.pool.getFnToPrinted())); } else if (useFilter) { - this.model.addCards(this.filter.select(this.pool, this.pool.fnToPrinted)); + this.model.addCards(this.filter.select(this.pool, this.pool.getFnToPrinted())); } else if (this.wantUnique) { this.model.addCards(CardRules.Predicates.Presets.CONSTANT_TRUE.uniqueByLast(this.pool, - this.pool.fnToCardName, this.pool.fnToCard)); + this.pool.getFnToCardName(), this.pool.getFnToCard())); } this.model.resort(); diff --git a/src/main/java/forge/item/BoosterPack.java b/src/main/java/forge/item/BoosterPack.java index e74e09a0381..16a81489459 100644 --- a/src/main/java/forge/item/BoosterPack.java +++ b/src/main/java/forge/item/BoosterPack.java @@ -16,7 +16,7 @@ import forge.card.CardSet; public class BoosterPack implements InventoryItemFromSet { /** The Constant fnFromSet. */ - public static final Lambda1 fnFromSet = new Lambda1() { + public static final Lambda1 FN_FROM_SET = new Lambda1() { @Override public BoosterPack apply(final CardSet arg1) { return new BoosterPack(arg1); @@ -30,8 +30,9 @@ public class BoosterPack implements InventoryItemFromSet { /** * Instantiates a new booster pack. - * - * @param set the set + * + * @param set + * the set */ public BoosterPack(final String set) { this(SetUtils.getSetByCodeOrThrow(set)); @@ -39,103 +40,122 @@ public class BoosterPack implements InventoryItemFromSet { /** * Instantiates a new booster pack. - * - * @param set the set + * + * @param set + * the set */ public BoosterPack(final CardSet set) { - cardSet = set; - name = cardSet.getName() + " Booster Pack"; + this.cardSet = set; + this.name = this.cardSet.getName() + " Booster Pack"; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see forge.item.InventoryItemFromSet#getSet() */ /** + * Gets the sets the. + * * @return String */ @Override public final String getSet() { - return cardSet.getCode(); + return this.cardSet.getCode(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see forge.item.InventoryItemFromSet#getName() */ /** + * Gets the name. + * * @return String */ @Override public final String getName() { - return name; + return this.name; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see forge.item.InventoryItemFromSet#getImageFilename() */ /** + * Gets the image filename. + * * @return String */ @Override public final String getImageFilename() { - return "booster/" + cardSet.getCode() + ".png"; + return "booster/" + this.cardSet.getCode() + ".png"; } private CardPrinted getRandomBasicLand(final CardSet set) { return Predicate.and(CardPrinted.Predicates.printedInSets(set.getCode()), - CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.fnGetRules).random( + CardRules.Predicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES).random( CardDb.instance().getAllCards()); } private CardPrinted getLandFromNearestSet() { - List sets = SetUtils.getAllSets(); - int iThisSet = sets.indexOf(cardSet); + final List sets = SetUtils.getAllSets(); + final int iThisSet = sets.indexOf(this.cardSet); for (int iSet = iThisSet; iSet < sets.size(); iSet++) { - CardPrinted land = getRandomBasicLand(sets.get(iSet)); + final CardPrinted land = this.getRandomBasicLand(sets.get(iSet)); if (null != land) { return land; } } // if not found (though that's impossible) - return getRandomBasicLand(SetUtils.getSetByCode("M12")); + return this.getRandomBasicLand(SetUtils.getSetByCode("M12")); } private void generate() { - BoosterGenerator gen = new BoosterGenerator(cardSet); - cards = gen.getBoosterPack(); + final BoosterGenerator gen = new BoosterGenerator(this.cardSet); + this.cards = gen.getBoosterPack(); - int cntLands = cardSet.getBoosterData().getLand(); + final int cntLands = this.cardSet.getBoosterData().getLand(); if (cntLands > 0) { - cards.add(getLandFromNearestSet()); + this.cards.add(this.getLandFromNearestSet()); } } /** * Gets the cards. - * + * * @return the cards */ public final List getCards() { - if (null == cards) { - generate(); + if (null == this.cards) { + this.generate(); } - return cards; + return this.cards; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#hashCode() */ /** + * Hash code. + * * @return int */ @Override public final int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((cardSet == null) ? 0 : cardSet.hashCode()); + result = (prime * result) + ((this.cardSet == null) ? 0 : this.cardSet.hashCode()); return result; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#equals(java.lang.Object) */ @Override @@ -146,24 +166,28 @@ public class BoosterPack implements InventoryItemFromSet { if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (this.getClass() != obj.getClass()) { return false; } - BoosterPack other = (BoosterPack) obj; - if (cardSet == null) { + final BoosterPack other = (BoosterPack) obj; + if (this.cardSet == null) { if (other.cardSet != null) { return false; } - } else if (!cardSet.equals(other.cardSet)) { + } else if (!this.cardSet.equals(other.cardSet)) { return false; } return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see forge.item.InventoryItem#getType() */ /** + * Gets the type. + * * @return String */ @Override @@ -171,16 +195,20 @@ public class BoosterPack implements InventoryItemFromSet { return "Booster Pack"; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#clone() */ /** + * Clone. + * * @return Object */ @Override public final Object clone() { - return new BoosterPack(cardSet); // it's ok to share a reference to - // cardSet which is static anyway + return new BoosterPack(this.cardSet); // it's ok to share a reference to + // cardSet which is static anyway } } diff --git a/src/main/java/forge/item/CardDb.java b/src/main/java/forge/item/CardDb.java index 4b76f10f435..469ae964e82 100644 --- a/src/main/java/forge/item/CardDb.java +++ b/src/main/java/forge/item/CardDb.java @@ -31,30 +31,32 @@ public final class CardDb { // makes this working /** - * Instance. - * - * @return the card db - */ - public static CardDb instance() { - if (onlyInstance == null) { + * Instance. + * + * @return the card db + */ + public static CardDb instance() { + if (CardDb.onlyInstance == null) { throw new NullPointerException("CardDb has not yet been initialized, run setup() first"); } - return onlyInstance; + return CardDb.onlyInstance; } /** * Sets the up. - * - * @param list the new up + * + * @param list + * the new up */ public static void setup(final Iterator list) { - if (onlyInstance != null) { + if (CardDb.onlyInstance != null) { throw new RuntimeException("CardDb has already been initialized, don't do it twice please"); } synchronized (CardDb.class) { - if (onlyInstance == null) { // It's broken under 1.4 and below, on - // 1.5+ works again! - onlyInstance = new CardDb(list); + if (CardDb.onlyInstance == null) { // It's broken under 1.4 and + // below, on + // 1.5+ works again! + CardDb.onlyInstance = new CardDb(list); } } } @@ -67,15 +69,13 @@ public final class CardDb { private final Map uniqueCards = new Hashtable(); // need this to obtain cardReference by name+set+artindex - private final Map> allCardsBySet = - new Hashtable>(); + private final Map> allCardsBySet = new Hashtable>(); // this is the same list in flat storage private final List allCardsFlat = new ArrayList(); // Lambda to get rules for selects from list of printed cards /** The Constant fnGetCardPrintedByForgeCard. */ - public static final Lambda1 fnGetCardPrintedByForgeCard = - new Lambda1() { + public static final Lambda1 FN_GET_CARD_PRINTED_BY_FORGE_CARD = new Lambda1() { @Override public CardPrinted apply(final Card from) { return CardDb.instance().getCard(from.getName()); @@ -88,22 +88,23 @@ public final class CardDb { private CardDb(final Iterator parser) { while (parser.hasNext()) { - addNewCard(parser.next()); + this.addNewCard(parser.next()); } // TODO consider using Collections.unmodifiableList wherever possible } /** * Adds the new card. - * - * @param card the card + * + * @param card + * the card */ public void addNewCard(final CardRules card) { if (null == card) { return; } // consider that a success - // System.out.println(card.getName()); - String cardName = card.getName().toLowerCase(); + // System.out.println(card.getName()); + final String cardName = card.getName().toLowerCase(); // 1. register among oracle uniques // cards.put(cardName, card); @@ -111,38 +112,41 @@ public final class CardDb { // 2. Save refs into two lists: one flat and other keyed with sets & // name CardPrinted lastAdded = null; - for (Entry s : card.getSetsPrinted()) { - lastAdded = addToLists(card, cardName, s); + for (final Entry s : card.getSetsPrinted()) { + lastAdded = this.addToLists(card, cardName, s); } - uniqueCards.put(cardName, lastAdded); + this.uniqueCards.put(cardName, lastAdded); } /** * Adds the to lists. - * - * @param card the card - * @param cardName the card name - * @param s the s + * + * @param card + * the card + * @param cardName + * the card name + * @param s + * the s * @return the card printed */ public CardPrinted addToLists(final CardRules card, final String cardName, final Entry s) { CardPrinted lastAdded = null; - String set = s.getKey(); + final String set = s.getKey(); // get this set storage, if not found, create it! - Map setMap = allCardsBySet.get(set); + Map setMap = this.allCardsBySet.get(set); if (null == setMap) { setMap = new Hashtable(); - allCardsBySet.put(set, setMap); + this.allCardsBySet.put(set, setMap); } - int count = s.getValue().getCopiesCount(); - CardPrinted[] cardCopies = new CardPrinted[count]; + final int count = s.getValue().getCopiesCount(); + final CardPrinted[] cardCopies = new CardPrinted[count]; setMap.put(cardName, cardCopies); for (int i = 0; i < count; i++) { lastAdded = CardPrinted.build(card, set, s.getValue().getRarity(), i, card.isAltState(), card.isDoubleFaced()); - allCardsFlat.add(lastAdded); + this.allCardsFlat.add(lastAdded); cardCopies[i] = lastAdded; } @@ -151,23 +155,24 @@ public final class CardDb { /** * Checks if is card supported. - * - * @param cardName the card name + * + * @param cardName + * the card name * @return true, if is card supported */ public boolean isCardSupported(final String cardName) { - ImmutablePair nameWithSet = splitCardName(cardName); + final ImmutablePair nameWithSet = CardDb.splitCardName(cardName); if (nameWithSet.right == null) { - return uniqueCards.containsKey(nameWithSet.left.toLowerCase()); + return this.uniqueCards.containsKey(nameWithSet.left.toLowerCase()); } // Set exists? - Map cardsFromset = allCardsBySet.get(nameWithSet.right.toUpperCase()); + final Map cardsFromset = this.allCardsBySet.get(nameWithSet.right.toUpperCase()); if (cardsFromset == null) { return false; } // Card exists? - CardPrinted[] cardCopies = cardsFromset.get(nameWithSet.left.toLowerCase()); - return cardCopies != null && cardCopies.length > 0; + final CardPrinted[] cardCopies = cardsFromset.get(nameWithSet.left.toLowerCase()); + return (cardCopies != null) && (cardCopies.length > 0); } /** @@ -175,10 +180,10 @@ public final class CardDb { */ private static ImmutablePair splitCardName(final String name) { String cardName = name; // .trim() ? - int pipePos = cardName.indexOf('|'); + final int pipePos = cardName.indexOf('|'); if (pipePos >= 0) { - String setName = cardName.substring(pipePos + 1).trim(); + final String setName = cardName.substring(pipePos + 1).trim(); cardName = cardName.substring(0, pipePos); // only if set is not blank try to load it if (StringUtils.isNotBlank(setName) && !"???".equals(setName)) { @@ -191,19 +196,20 @@ public final class CardDb { // Single fetch /** * Gets the card. - * - * @param name the name + * + * @param name + * the name * @return the card */ public CardPrinted getCard(final String name) { // Sometimes they read from decks things like "CardName|Set" - but we // can handle it - ImmutablePair nameWithSet = splitCardName(name); + final ImmutablePair nameWithSet = CardDb.splitCardName(name); if (nameWithSet.right != null) { - return getCard(nameWithSet.left, nameWithSet.right); + return this.getCard(nameWithSet.left, nameWithSet.right); } // OK, plain name here - CardPrinted card = uniqueCards.get(nameWithSet.left.toLowerCase()); + final CardPrinted card = this.uniqueCards.get(nameWithSet.left.toLowerCase()); if (card != null) { return card; } @@ -213,41 +219,49 @@ public final class CardDb { // Advanced fetch by name+set /** * Gets the card. - * - * @param name the name - * @param set the set + * + * @param name + * the name + * @param set + * the set * @return the card */ public CardPrinted getCard(final String name, final String set) { - return getCard(name, set, 0); + return this.getCard(name, set, 0); } /** * Gets the card. - * - * @param name the name - * @param set the set - * @param artIndex the art index + * + * @param name + * the name + * @param set + * the set + * @param artIndex + * the art index * @return the card */ public CardPrinted getCard(final String name, final String set, final int artIndex) { // 1. get set - Map cardsFromset = allCardsBySet.get(set.toUpperCase()); + final Map cardsFromset = this.allCardsBySet.get(set.toUpperCase()); if (null == cardsFromset) { - String err = String.format("Asked for card '%s' from set '%s': that set was not found. :(", name, set); + final String err = String + .format("Asked for card '%s' from set '%s': that set was not found. :(", name, set); throw new NoSuchElementException(err); } // 2. Find the card itself - CardPrinted[] cardCopies = cardsFromset.get(name.toLowerCase()); + final CardPrinted[] cardCopies = cardsFromset.get(name.toLowerCase()); if (null == cardCopies) { - String err = String.format("Asked for card '%s' from '%s': set found, but the card wasn't. :(", name, set); + final String err = String.format("Asked for card '%s' from '%s': set found, but the card wasn't. :(", name, + set); throw new NoSuchElementException(err); } // 3. Get the proper copy - if (artIndex >= 0 && artIndex <= cardCopies.length) { + if ((artIndex >= 0) && (artIndex <= cardCopies.length)) { return cardCopies[artIndex]; } - String err = String.format("Asked for '%s' from '%s' #%d: db didn't find that copy.", name, set, artIndex); + final String err = String + .format("Asked for '%s' from '%s' #%d: db didn't find that copy.", name, set, artIndex); throw new NoSuchElementException(err); } @@ -255,30 +269,32 @@ public final class CardDb { // we'll still check /** * Gets the card. - * - * @param forgeCard the forge card + * + * @param forgeCard + * the forge card * @return the card */ public CardPrinted getCard(final Card forgeCard) { - String name = forgeCard.getName(); - String set = forgeCard.getCurSetCode(); + final String name = forgeCard.getName(); + final String set = forgeCard.getCurSetCode(); if (StringUtils.isNotBlank(set)) { - return getCard(name, set); + return this.getCard(name, set); } - return getCard(name); + return this.getCard(name); } // Multiple fetch /** * Gets the cards. - * - * @param names the names + * + * @param names + * the names * @return the cards */ public List getCards(final Iterable names) { - List result = new ArrayList(); - for (String name : names) { - result.add(getCard(name)); + final List result = new ArrayList(); + for (final String name : names) { + result.add(this.getCard(name)); } return result; } @@ -286,22 +302,22 @@ public final class CardDb { // returns a list of all cards from their respective latest editions /** * Gets the all unique cards. - * + * * @return the all unique cards */ public Iterable getAllUniqueCards() { - return uniqueCards.values(); + return this.uniqueCards.values(); } // public Iterable getAllCardRules() { return cards.values(); } // // still not needed /** * Gets the all cards. - * + * * @return the all cards */ public Iterable getAllCards() { - return allCardsFlat; + return this.allCardsFlat; } } diff --git a/src/main/java/forge/item/CardPrinted.java b/src/main/java/forge/item/CardPrinted.java index df2dbc3a2de..31605aca4a6 100644 --- a/src/main/java/forge/item/CardPrinted.java +++ b/src/main/java/forge/item/CardPrinted.java @@ -47,88 +47,108 @@ public final class CardPrinted implements Comparable, InventoryItem private transient String imageFilename = null; // field RO accessors - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see forge.item.InventoryItemFromSet#getName() */ /** + * Gets the name. + * * @return String */ + @Override public String getName() { - return name; + return this.name; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see forge.item.InventoryItemFromSet#getSet() */ /** + * Gets the sets the. + * * @return String */ + @Override public String getSet() { - return cardSet; + return this.cardSet; } /** * Gets the art index. - * + * * @return the art index */ public int getArtIndex() { - return artIndex; + return this.artIndex; } /** * Checks if is foil. - * + * * @return true, if is foil */ public boolean isFoil() { - return foiled; + return this.foiled; } /** * Gets the card. - * + * * @return the card */ public CardRules getCard() { - return card; + return this.card; } /** * Gets the rarity. - * + * * @return the rarity */ public CardRarity getRarity() { - return rarity; + return this.rarity; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see forge.item.InventoryItemFromSet#getImageFilename() */ /** + * Gets the image filename. + * * @return String */ + @Override public String getImageFilename() { - if (imageFilename == null) { - imageFilename = CardUtil.buildFilename(this); + if (this.imageFilename == null) { + this.imageFilename = CardUtil.buildFilename(this); } - return imageFilename; + return this.imageFilename; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see forge.item.InventoryItem#getType() */ /** + * Gets the type. + * * @return String */ + @Override public String getType() { - return card.getType().toString(); + return this.card.getType().toString(); } // Lambda to get rules for selects from list of printed cards /** The Constant fnGetRules. */ - public static final Lambda1 fnGetRules = new Lambda1() { + public static final Lambda1 FN_GET_RULES = new Lambda1() { @Override public CardRules apply(final CardPrinted from) { return from.card; @@ -137,42 +157,47 @@ public final class CardPrinted implements Comparable, InventoryItem // Constructor is private. All non-foiled instances are stored in CardDb private CardPrinted(final CardRules c, final String set, final CardRarity rare, final int index, - final boolean foil, final boolean isAlt, final boolean isDF) - { - card = c; - name = c.getName(); - cardSet = set; - artIndex = index; - foiled = foil; - rarity = rare; - isAlternate = isAlt; - isDoubleFaced = isDF; - nameLcase = name.toLowerCase(); + final boolean foil, final boolean isAlt, final boolean isDF) { + this.card = c; + this.name = c.getName(); + this.cardSet = set; + this.artIndex = index; + this.foiled = foil; + this.rarity = rare; + this.isAlternate = isAlt; + this.isDoubleFaced = isDF; + this.nameLcase = this.name.toLowerCase(); } /* package visibility */ /** * Builds the. - * - * @param c the c - * @param set the set - * @param rare the rare - * @param index the index - * @param isAlt the is alt - * @param isDF the is df + * + * @param c + * the c + * @param set + * the set + * @param rare + * the rare + * @param index + * the index + * @param isAlt + * the is alt + * @param isDF + * the is df * @return the card printed */ static CardPrinted build(final CardRules c, final String set, final CardRarity rare, final int index, - final boolean isAlt, final boolean isDF) - { + final boolean isAlt, final boolean isDF) { return new CardPrinted(c, set, rare, index, false, isAlt, isDF); } /* foiled don't need to stay in CardDb's structures, so u'r free to create */ /** * Make foiled. - * - * @param c the c + * + * @param c + * the c * @return the card printed */ public static CardPrinted makeFoiled(final CardPrinted c) { @@ -180,7 +205,9 @@ public final class CardPrinted implements Comparable, InventoryItem } // Want this class to be a key for HashTable - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#equals(java.lang.Object) */ @Override @@ -191,57 +218,61 @@ public final class CardPrinted implements Comparable, InventoryItem if (obj == null) { return false; } - if (getClass() != obj.getClass()) { + if (this.getClass() != obj.getClass()) { return false; } - CardPrinted other = (CardPrinted) obj; - if (!name.equals(other.name)) { + final CardPrinted other = (CardPrinted) obj; + if (!this.name.equals(other.name)) { return false; } - if (!cardSet.equals(other.cardSet)) { + if (!this.cardSet.equals(other.cardSet)) { return false; } - if (other.foiled != this.foiled || other.artIndex != this.artIndex) { + if ((other.foiled != this.foiled) || (other.artIndex != this.artIndex)) { return false; } return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { - int code = nameLcase.hashCode() * 11 + cardSet.hashCode() * 59 + artIndex * 2; - if (foiled) { + final int code = (this.nameLcase.hashCode() * 11) + (this.cardSet.hashCode() * 59) + (this.artIndex * 2); + if (this.foiled) { return code + 1; } return code; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#toString() */ @Override public String toString() { - return name; + return this.name; // cannot still decide, if this "name|set" format is needed anymore // return String.format("%s|%s", name, cardSet); } /** * To forge card. - * + * * @return the card */ public Card toForgeCard() { - Card c = AllZone.getCardFactory().getCard(name, null); + final Card c = AllZone.getCardFactory().getCard(this.name, null); if (c != null) { - c.setCurSetCode(getSet()); - c.setRandomPicture(artIndex + 1); - c.setImageFilename(getImageFilename()); + c.setCurSetCode(this.getSet()); + c.setRandomPicture(this.artIndex + 1); + c.setImageFilename(this.getImageFilename()); if (c.hasAlternateState()) { c.changeState(); c.setImageFilename(CardUtil.buildFilename(c)); @@ -252,35 +283,37 @@ public final class CardPrinted implements Comparable, InventoryItem return c; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override public int compareTo(final CardPrinted o) { - int nameCmp = nameLcase.compareTo(o.nameLcase); + final int nameCmp = this.nameLcase.compareTo(o.nameLcase); if (0 != nameCmp) { return nameCmp; } // TODO compare sets properly - return cardSet.compareTo(o.cardSet); + return this.cardSet.compareTo(o.cardSet); } /** * Checks if is alternate. - * + * * @return true, if is alternate */ public boolean isAlternate() { - return isAlternate; + return this.isAlternate; } /** * Checks if is double faced. - * + * * @return true, if is double faced */ public boolean isDoubleFaced() { - return isDoubleFaced; + return this.isDoubleFaced; } /** @@ -290,9 +323,11 @@ public final class CardPrinted implements Comparable, InventoryItem /** * Rarity. - * - * @param isEqual the is equal - * @param value the value + * + * @param isEqual + * the is equal + * @param value + * the value * @return the predicate */ public static Predicate rarity(final boolean isEqual, final CardRarity value) { @@ -301,13 +336,15 @@ public final class CardPrinted implements Comparable, InventoryItem /** * Printed in sets. - * - * @param value the value - * @param shouldContain the should contain + * + * @param value + * the value + * @param shouldContain + * the should contain * @return the predicate */ public static Predicate printedInSets(final List value, final boolean shouldContain) { - if (value == null || value.isEmpty()) { + if ((value == null) || value.isEmpty()) { return Predicate.getTrue(CardPrinted.class); } return new PredicateSets(value, shouldContain); @@ -315,21 +352,23 @@ public final class CardPrinted implements Comparable, InventoryItem /** * Printed in sets. - * - * @param value the value + * + * @param value + * the value * @return the predicate */ public static Predicate printedInSets(final String value) { - if (value == null || value.isEmpty()) { + if ((value == null) || value.isEmpty()) { return Predicate.getTrue(CardPrinted.class); } - return new PredicateSets(Arrays.asList(new String[] {value}), true); + return new PredicateSets(Arrays.asList(new String[] { value }), true); } /** * Name. - * - * @param what the what + * + * @param what + * the what * @return the predicate */ public static Predicate name(final String what) { @@ -338,9 +377,11 @@ public final class CardPrinted implements Comparable, InventoryItem /** * Name. - * - * @param op the op - * @param what the what + * + * @param op + * the op + * @param what + * the what * @return the predicate */ public static Predicate name(final PredicateString.StringOp op, final String what) { @@ -349,8 +390,9 @@ public final class CardPrinted implements Comparable, InventoryItem /** * Names except. - * - * @param what the what + * + * @param what + * the what * @return the predicate */ public static Predicate namesExcept(final List what) { @@ -370,12 +412,12 @@ public final class CardPrinted implements Comparable, InventoryItem @Override public boolean isTrue(final CardPrinted card) { - return card.rarity.equals(operand) == shouldBeEqual; + return card.rarity.equals(this.operand) == this.shouldBeEqual; } public PredicateRarity(final CardRarity type, final boolean wantEqual) { - operand = type; - shouldBeEqual = wantEqual; + this.operand = type; + this.shouldBeEqual = wantEqual; } } @@ -385,12 +427,12 @@ public final class CardPrinted implements Comparable, InventoryItem @Override public boolean isTrue(final CardPrinted card) { - return sets.contains(card.cardSet) == mustContain; + return this.sets.contains(card.cardSet) == this.mustContain; } public PredicateSets(final List wantSets, final boolean shouldContain) { - sets = wantSets; // maybe should make a copy here? - mustContain = shouldContain; + this.sets = wantSets; // maybe should make a copy here? + this.mustContain = shouldContain; } } @@ -399,7 +441,7 @@ public final class CardPrinted implements Comparable, InventoryItem @Override public boolean isTrue(final CardPrinted card) { - return op(card.getName(), operand); + return this.op(card.getName(), this.operand); } public PredicateName(final PredicateString.StringOp operator, final String operand) { @@ -413,9 +455,9 @@ public final class CardPrinted implements Comparable, InventoryItem @Override public boolean isTrue(final CardPrinted card) { - String cardName = card.getName(); - for (int i = 0; i < operand.length; i++) { - if (op(cardName, operand[i])) { + final String cardName = card.getName(); + for (final String element : this.operand) { + if (this.op(cardName, element)) { return false; } } @@ -436,31 +478,32 @@ public final class CardPrinted implements Comparable, InventoryItem // Think twice before using these, since rarity is a prop of printed // card. /** The Constant isCommon. */ - public static final Predicate isCommon = rarity(true, CardRarity.Common); - + public static final Predicate IS_COMMON = Predicates.rarity(true, CardRarity.Common); + /** The Constant isUncommon. */ - public static final Predicate isUncommon = rarity(true, CardRarity.Uncommon); - + public static final Predicate IS_UNCOMMON = Predicates.rarity(true, CardRarity.Uncommon); + /** The Constant isRare. */ - public static final Predicate isRare = rarity(true, CardRarity.Rare); - + public static final Predicate IS_RARE = Predicates.rarity(true, CardRarity.Rare); + /** The Constant isMythicRare. */ - public static final Predicate isMythicRare = rarity(true, CardRarity.MythicRare); - + public static final Predicate IS_MYTHIC_RARE = Predicates.rarity(true, CardRarity.MythicRare); + /** The Constant isRareOrMythic. */ - public static final Predicate isRareOrMythic = Predicate.or(isRare, isMythicRare); - + public static final Predicate IS_RARE_OR_MYTHIC = Predicate.or(Presets.IS_RARE, + Presets.IS_MYTHIC_RARE); + /** The Constant isSpecial. */ - public static final Predicate isSpecial = rarity(true, CardRarity.Special); - + public static final Predicate IS_SPECIAL = Predicates.rarity(true, CardRarity.Special); + /** The Constant exceptLands. */ - public static final Predicate exceptLands = rarity(false, CardRarity.BasicLand); + public static final Predicate EXCEPT_LANDS = Predicates.rarity(false, CardRarity.BasicLand); /** The Constant isTrue. */ - public static final Predicate isTrue = Predicate.getTrue(CardPrinted.class); + public static final Predicate IS_TRUE = Predicate.getTrue(CardPrinted.class); /** The Constant nonAlternate. */ - public static final Predicate nonAlternate = new PredicateNotAlternate(); + public static final Predicate NON_ALTERNATE = new PredicateNotAlternate(); } } } diff --git a/src/main/java/forge/item/CardPrintedCharacteristics.java b/src/main/java/forge/item/CardPrintedCharacteristics.java index 7499d850ed6..4a2255a04cc 100644 --- a/src/main/java/forge/item/CardPrintedCharacteristics.java +++ b/src/main/java/forge/item/CardPrintedCharacteristics.java @@ -1,8 +1,7 @@ package forge.item; /** - * - * + * The Class CardPrintedCharacteristics. */ public class CardPrintedCharacteristics { private String name; @@ -10,17 +9,18 @@ public class CardPrintedCharacteristics { /** * Gets the name. - * + * * @return the name */ public final String getName() { - return name; + return this.name; } /** * Sets the name. - * - * @param name0 the name to set + * + * @param name0 + * the name to set */ public final void setName(final String name0) { this.name = name0; // TODO Add 0 to parameter's name. @@ -28,17 +28,18 @@ public class CardPrintedCharacteristics { /** * Gets the card set. - * + * * @return the cardSet */ public final String getCardSet() { - return cardSet; + return this.cardSet; } /** * Sets the card set. - * - * @param cardSet0 the cardSet to set + * + * @param cardSet0 + * the cardSet to set */ public final void setCardSet(final String cardSet0) { this.cardSet = cardSet0; // TODO: Add 0 to parameter's name. diff --git a/src/main/java/forge/item/InventoryItem.java b/src/main/java/forge/item/InventoryItem.java index 873cfe0bb7d..7bdb478b2bd 100644 --- a/src/main/java/forge/item/InventoryItem.java +++ b/src/main/java/forge/item/InventoryItem.java @@ -4,7 +4,7 @@ package forge.item; * Interface to define a player's inventory may hold. Should include * CardPrinted, Booster, Pets, Plants... etc */ -public interface InventoryItem /* extends Comparable */{ +public interface InventoryItem { /** * An inventory item has to provide a name. diff --git a/src/main/java/forge/item/InventoryItemFromSet.java b/src/main/java/forge/item/InventoryItemFromSet.java index 6cc7b50a0a9..bd622d199a1 100644 --- a/src/main/java/forge/item/InventoryItemFromSet.java +++ b/src/main/java/forge/item/InventoryItemFromSet.java @@ -8,21 +8,23 @@ public interface InventoryItemFromSet extends InventoryItem { /** * An inventory item has to provide a name. - * + * * @return the name */ + @Override String getName(); /** * An inventory item has to provide a picture. - * + * * @return the image filename */ + @Override String getImageFilename(); /** * An item belonging to a set should return its set as well. - * + * * @return the sets the */ String getSet(); diff --git a/src/main/java/forge/item/ItemPool.java b/src/main/java/forge/item/ItemPool.java index 9c04963a171..62d8d367094 100644 --- a/src/main/java/forge/item/ItemPool.java +++ b/src/main/java/forge/item/ItemPool.java @@ -3,51 +3,65 @@ package forge.item; import java.util.Collections; import java.util.Map.Entry; - /** - *

CardPool class.

+ *

+ * CardPool class. + *

* Represents a list of cards with amount of each - * @param an Object + * + * @param + * an Object */ -public final class ItemPool extends ItemPoolView { +public final class ItemPool extends ItemPoolView { // Constructors here /** * * ItemPool Constructor. - * @param cls a T + * + * @param cls + * a T */ - public ItemPool(final Class cls) { super(cls); } + public ItemPool(final Class cls) { + super(cls); + } /** * * ItemPool Constructor. - * @param names a String - * @param cls a T + * + * @param names + * a String + * @param cls + * a T */ - @SuppressWarnings("unchecked") // conversion here must be safe + @SuppressWarnings("unchecked") + // conversion here must be safe public ItemPool(final Iterable names, final Class cls) { super(cls); - addAllCards((Iterable) CardDb.instance().getCards(names)); - } + this.addAllCards((Iterable) CardDb.instance().getCards(names)); + } /** - * * createFrom method. - * @param from a Tin - * @param clsHint a Tout - * @param an InventoryItem - * @param an InventoryItem + * + * @param + * an InventoryItem + * @param + * an InventoryItem + * @param from + * a Tin + * @param clsHint + * a Tout * @return InventoryItem */ @SuppressWarnings("unchecked") - public static ItemPool - createFrom(final ItemPoolView from, final Class clsHint) - { - ItemPool result = new ItemPool(clsHint); + public static ItemPool createFrom( + final ItemPoolView from, final Class clsHint) { + final ItemPool result = new ItemPool(clsHint); if (from != null) { - for (Entry e : from) { - Tin srcKey = e.getKey(); + for (final Entry e : from) { + final Tin srcKey = e.getKey(); if (clsHint.isInstance(srcKey)) { result.put((Tout) srcKey, e.getValue()); } @@ -57,21 +71,24 @@ public final class ItemPool extends ItemPoolView { } /** - * * createFrom method. - * @param from a Iterable - * @param clsHint a Class + * + * @param + * an InventoryItem + * @param + * an InventoryItem + * @param from + * a Iterable + * @param clsHint + * a Class * @return an InventoryItem - * @param an InventoryItem - * @param an InventoryItem */ @SuppressWarnings("unchecked") - public static ItemPool - createFrom(final Iterable from, final Class clsHint) - { - ItemPool result = new ItemPool(clsHint); + public static ItemPool createFrom( + final Iterable from, final Class clsHint) { + final ItemPool result = new ItemPool(clsHint); if (from != null) { - for (Tin srcKey : from) { + for (final Tin srcKey : from) { if (clsHint.isInstance(srcKey)) { result.put((Tout) srcKey, Integer.valueOf(1)); } @@ -84,99 +101,136 @@ public final class ItemPool extends ItemPoolView { /** * * Get item view. + * * @return a ItemPoolView */ - public ItemPoolView getView() { return new ItemPoolView(Collections.unmodifiableMap(cards), myClass); } + public ItemPoolView getView() { + return new ItemPoolView(Collections.unmodifiableMap(this.getCards()), this.getMyClass()); + } // Cards manipulation /** * * Add Card. - * @param card a T + * + * @param card + * a T */ public void add(final T card) { - add(card, 1); - } + this.add(card, 1); + } + /** * * add method. - * @param card a T - * @param amount a int + * + * @param card + * a T + * @param amount + * a int */ public void add(final T card, final int amount) { - if (amount <= 0) { return; } - cards.put(card, count(card) + amount); - isListInSync = false; + if (amount <= 0) { + return; + } + this.getCards().put(card, this.count(card) + amount); + this.setListInSync(false); } private void put(final T card, final int amount) { - cards.put(card, amount); - isListInSync = false; + this.getCards().put(card, amount); + this.setListInSync(false); } /** - * * addAllCards. - * @param cards a Iterable - * @param a InventoryItem + * + * @param + * a InventoryItem + * @param cards + * a Iterable */ @SuppressWarnings("unchecked") public void addAllCards(final Iterable cards) { - for (U cr : cards) { if (myClass.isInstance(cr)) { add((T) cr); } } - isListInSync = false; + for (final U cr : cards) { + if (this.getMyClass().isInstance(cr)) { + this.add((T) cr); + } + } + this.setListInSync(false); } /** - * * addAll. - * @param map a Iterable> - * @param an InventoryItem + * + * @param + * an InventoryItem + * @param map + * a Iterable> */ @SuppressWarnings("unchecked") public void addAll(final Iterable> map) { - for (Entry e : map) { - if (myClass.isInstance(e.getKey())) { - add((T) e.getKey(), e.getValue()); + for (final Entry e : map) { + if (this.getMyClass().isInstance(e.getKey())) { + this.add((T) e.getKey(), e.getValue()); } } - isListInSync = false; + this.setListInSync(false); } /** * * Remove. - * @param card a T + * + * @param card + * a T */ public void remove(final T card) { - remove(card, 1); - } + this.remove(card, 1); + } /** * * Remove. - * @param card a T - * @param amount a int + * + * @param card + * a T + * @param amount + * a int */ public void remove(final T card, final int amount) { - int count = count(card); - if (count == 0 || amount <= 0) { return; } - if (count <= amount) { cards.remove(card); } - else { cards.put(card, count - amount); } - isListInSync = false; + final int count = this.count(card); + if ((count == 0) || (amount <= 0)) { + return; + } + if (count <= amount) { + this.getCards().remove(card); + } else { + this.getCards().put(card, count - amount); + } + this.setListInSync(false); } + /** * * RemoveAll. - * @param map a T + * + * @param map + * a T */ public void removeAll(final Iterable> map) { - for (Entry e : map) { remove(e.getKey(), e.getValue()); } - isListInSync = false; + for (final Entry e : map) { + this.remove(e.getKey(), e.getValue()); + } + this.setListInSync(false); } /** * * Clear. */ - public void clear() { cards.clear(); isListInSync = false; } + public void clear() { + this.getCards().clear(); + this.setListInSync(false); + } } diff --git a/src/main/java/forge/item/ItemPoolView.java b/src/main/java/forge/item/ItemPoolView.java index 6cc22c06279..72bcf09a1bc 100644 --- a/src/main/java/forge/item/ItemPoolView.java +++ b/src/main/java/forge/item/ItemPoolView.java @@ -15,8 +15,9 @@ import forge.card.CardRules; *

* CardPoolView class. *

- * - * @param an InventoryItem + * + * @param + * an InventoryItem * @author Forge * @version $Id: CardPoolView.java 9708 2011-08-09 19:34:12Z jendave $ */ @@ -24,16 +25,16 @@ public class ItemPoolView implements Iterable> fnToCard = new Lambda1>() { + private final Lambda1> fnToCard = new Lambda1>() { @Override public CardRules apply(final Entry from) { - T item = from.getKey(); + final T item = from.getKey(); return item instanceof CardPrinted ? ((CardPrinted) item).getCard() : null; } }; /** The fn to printed. */ - public final Lambda1> fnToPrinted = new Lambda1>() { + private final Lambda1> fnToPrinted = new Lambda1>() { @Override public T apply(final Entry from) { return from.getKey(); @@ -41,7 +42,7 @@ public class ItemPoolView implements Iterable> fnToCardName = new Lambda1>() { + private final Lambda1> fnToCardName = new Lambda1>() { @Override public String apply(final Entry from) { return from.getKey().getName(); @@ -49,7 +50,7 @@ public class ItemPoolView implements Iterable> fnToCount = new Lambda1>() { + private final Lambda1> fnToCount = new Lambda1>() { @Override public Integer apply(final Entry from) { return from.getValue(); @@ -65,8 +66,8 @@ public class ItemPoolView implements Iterable */ public ItemPoolView(final Class cls) { - cards = new Hashtable(); - myClass = cls; + this.setCards(new Hashtable()); + this.myClass = cls; } /** @@ -79,25 +80,25 @@ public class ItemPoolView implements Iterable */ public ItemPoolView(final Map inMap, final Class cls) { - cards = inMap; - myClass = cls; + this.setCards(inMap); + this.myClass = cls; } // Data members /** The cards. */ - protected Map cards; - + private Map cards; + /** The my class. */ - protected final Class myClass; // class does not keep this in runtime by + private final Class myClass; // class does not keep this in runtime by // itself // same thing as above, it was copied to provide sorting (needed by table // views in deck editors) /** The cards list ordered. */ - protected List> cardsListOrdered = new ArrayList>(); + private List> cardsListOrdered = new ArrayList>(); /** The is list in sync. */ - protected boolean isListInSync = false; + private boolean isListInSync = false; /** * iterator. @@ -106,7 +107,7 @@ public class ItemPoolView implements Iterable> iterator() { - return cards.entrySet().iterator(); + return this.getCards().entrySet().iterator(); } // Cards read only operations @@ -119,10 +120,10 @@ public class ItemPoolView implements Iterable implements Iterable implements Iterable implements Iterable implements Iterable implements Iterable> */ public final List> getOrderedList() { - if (!isListInSync) { - rebuildOrderedList(); + if (!this.isListInSync()) { + this.rebuildOrderedList(); } - return cardsListOrdered; + return this.cardsListOrdered; } private void rebuildOrderedList() { - cardsListOrdered.clear(); - if (cards != null) { - for (Entry e : cards.entrySet()) { - cardsListOrdered.add(e); + this.cardsListOrdered.clear(); + if (this.getCards() != null) { + for (final Entry e : this.getCards().entrySet()) { + this.cardsListOrdered.add(e); } } - isListInSync = true; + this.setListInSync(true); } /** @@ -207,8 +208,8 @@ public class ItemPoolView implements Iterable */ public final List toFlatList() { - List result = new ArrayList(); - for (Entry e : this) { + final List result = new ArrayList(); + for (final Entry e : this) { for (int i = 0; i < e.getValue(); i++) { result.add(e.getKey()); } @@ -223,8 +224,8 @@ public class ItemPoolView implements Iterable e : this) { + final CardList result = new CardList(); + for (final Entry e : this) { if (e.getKey() instanceof CardPrinted) { for (int i = 0; i < e.getValue(); i++) { result.add(((CardPrinted) e.getKey()).toForgeCard()); @@ -233,4 +234,67 @@ public class ItemPoolView implements Iterable getCards() { + return cards; + } + + /** + * @param cards the cards to set + */ + public void setCards(Map cards) { + this.cards = cards; // TODO: Add 0 to parameter's name. + } + + /** + * @return the myClass + */ + public Class getMyClass() { + return myClass; + } + + /** + * @return the isListInSync + */ + public boolean isListInSync() { + return isListInSync; + } + + /** + * @param isListInSync the isListInSync to set + */ + public void setListInSync(boolean isListInSync) { + this.isListInSync = isListInSync; // TODO: Add 0 to parameter's name. + } + + /** + * @return the fnToCard + */ + public Lambda1> getFnToCard() { + return fnToCard; + } + + /** + * @return the fnToCardName + */ + public Lambda1> getFnToCardName() { + return fnToCardName; + } + + /** + * @return the fnToCount + */ + public Lambda1> getFnToCount() { + return fnToCount; + } + + /** + * @return the fnToPrinted + */ + public Lambda1> getFnToPrinted() { + return fnToPrinted; + } } diff --git a/src/main/java/forge/item/package-info.java b/src/main/java/forge/item/package-info.java index c37d4b7a98c..b2c023f908f 100644 --- a/src/main/java/forge/item/package-info.java +++ b/src/main/java/forge/item/package-info.java @@ -1,2 +1,3 @@ /** Forge Card Game. */ package forge.item; + diff --git a/src/main/java/forge/quest/data/QuestData.java b/src/main/java/forge/quest/data/QuestData.java index 187a8d42791..9b86bd301a2 100644 --- a/src/main/java/forge/quest/data/QuestData.java +++ b/src/main/java/forge/quest/data/QuestData.java @@ -184,7 +184,7 @@ public final class QuestData { setDifficulty(diff); Predicate filter = Predicate.and(standardStart ? SetUtils.getStandard().getFilterPrinted() - : CardPrinted.Predicates.Presets.isTrue, CardPrinted.Predicates.Presets.nonAlternate); + : CardPrinted.Predicates.Presets.IS_TRUE, CardPrinted.Predicates.Presets.NON_ALTERNATE); myCards.setupNewGameCardPool(filter, diff); credits = QuestPreferences.getStartingCredits(); diff --git a/src/main/java/forge/quest/data/QuestUtilCards.java b/src/main/java/forge/quest/data/QuestUtilCards.java index 3ac19112861..a7a7c7ca560 100644 --- a/src/main/java/forge/quest/data/QuestUtilCards.java +++ b/src/main/java/forge/quest/data/QuestUtilCards.java @@ -113,7 +113,7 @@ public final class QuestUtilCards { q.newCardList.add(card); } - private static final Predicate rarePredicate = CardPrinted.Predicates.Presets.isRareOrMythic; + private static final Predicate rarePredicate = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC; /** * Adds the random rare. @@ -283,7 +283,7 @@ public final class QuestUtilCards { int rollD100 = MyRandom.getRandom().nextInt(100); Predicate filter = rollD100 < 40 ? filterT2booster : (rollD100 < 75 ? filterExtButT2 : filterNotExt); - q.shopList.addAllCards(filter.random(SetUtils.getAllSets(), 1, BoosterPack.fnFromSet)); + q.shopList.addAllCards(filter.random(SetUtils.getAllSets(), 1, BoosterPack.FN_FROM_SET)); } addBasicLands(q.shopList, 10, 5); diff --git a/src/main/java/forge/quest/gui/QuestWinLoseHandler.java b/src/main/java/forge/quest/gui/QuestWinLoseHandler.java index 4addde60cd8..455416c109f 100644 --- a/src/main/java/forge/quest/gui/QuestWinLoseHandler.java +++ b/src/main/java/forge/quest/gui/QuestWinLoseHandler.java @@ -427,7 +427,7 @@ public class QuestWinLoseHandler extends WinLoseModeHandler { GameFormat selected = ch.getSelectedValue(); List cardsWon = model.qData.getCards().addCards( - Predicate.and(selected.getFilterPrinted(), CardPrinted.Predicates.Presets.nonAlternate)); + Predicate.and(selected.getFilterPrinted(), CardPrinted.Predicates.Presets.NON_ALTERNATE)); // Generate Swing components and attach. lblTemp1 = new TitleLabel("Bonus booster pack from the \"" + selected.getName() + "\" format!");