diff --git a/src/main/java/forge/item/BoosterPack.java b/src/main/java/forge/item/BoosterPack.java index cee11c13d3f..e6985d57d0a 100644 --- a/src/main/java/forge/item/BoosterPack.java +++ b/src/main/java/forge/item/BoosterPack.java @@ -4,57 +4,96 @@ import java.util.List; import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.maxmtg.Predicate; - import forge.SetUtils; import forge.card.BoosterGenerator; import forge.card.CardRules; import forge.card.CardSet; -/** - * TODO: Write javadoc for this type. - * +/** + * TODO Write javadoc for this type. + * */ public class BoosterPack implements InventoryItemFromSet { - public final static Lambda1 fnFromSet = new Lambda1() { - @Override public BoosterPack apply(CardSet arg1) { return new BoosterPack(arg1); } }; - + /** The Constant fnFromSet. */ + public static final Lambda1 fnFromSet = new Lambda1() { + @Override + public BoosterPack apply(final CardSet arg1) { + return new BoosterPack(arg1); + } + }; + private final CardSet cardSet; private final String name; - + private List cards = null; - public BoosterPack(String set) { + /** + * Instantiates a new booster pack. + * + * @param set the set + */ + public BoosterPack(final String set) { this(SetUtils.getSetByCodeOrThrow(set)); } - public BoosterPack(CardSet set) { + /** + * Instantiates a new booster pack. + * + * @param set the set + */ + public BoosterPack(final CardSet set) { cardSet = set; name = cardSet.getName() + " Booster Pack"; } - - - @Override public String getSet() { return cardSet.getCode(); } - @Override public String getName() { return name; } - @Override public String getImageFilename() { - return "booster/"+cardSet.getCode()+".png"; + /* (non-Javadoc) + * @see forge.item.InventoryItemFromSet#getSet() + */ + /** + * @return String + */ + @Override + public final String getSet() { + return cardSet.getCode(); } - private CardPrinted getRandomBasicLand(CardSet set) { + /* (non-Javadoc) + * @see forge.item.InventoryItemFromSet#getName() + */ + /** + * @return String + */ + @Override + public final String getName() { + return name; + } + + /* (non-Javadoc) + * @see forge.item.InventoryItemFromSet#getImageFilename() + */ + /** + * @return String + */ + @Override + public final String getImageFilename() { + return "booster/" + cardSet.getCode() + ".png"; + } + + private CardPrinted getRandomBasicLand(final CardSet set) { return Predicate.and(CardPrinted.Predicates.printedInSets(set.getCode()), - CardRules.Predicates.Presets.isBasicLand, - CardPrinted.fnGetRules).random(CardDb.instance().getAllCards()); + CardRules.Predicates.Presets.isBasicLand, CardPrinted.fnGetRules).random( + CardDb.instance().getAllCards()); } - private CardPrinted getLandFromNearestSet() - { + private CardPrinted getLandFromNearestSet() { List sets = SetUtils.getAllSets(); int iThisSet = sets.indexOf(cardSet); - for (int iSet = iThisSet; iSet < sets.size(); iSet++) - { + for (int iSet = iThisSet; iSet < sets.size(); iSet++) { CardPrinted land = getRandomBasicLand(sets.get(iSet)); - if (null != land) return land; + if (null != land) { + return land; + } } // if not found (though that's impossible) return getRandomBasicLand(SetUtils.getSetByCode("M12")); @@ -63,48 +102,85 @@ public class BoosterPack implements InventoryItemFromSet { private void generate() { BoosterGenerator gen = new BoosterGenerator(cardSet); cards = gen.getBoosterPack(); - + int cntLands = cardSet.getBoosterData().getLand(); if (cntLands > 0) { cards.add(getLandFromNearestSet()); } } - public List getCards() { - if (null == cards) { generate(); } + + /** + * Gets the cards. + * + * @return the cards + */ + public final List getCards() { + if (null == cards) { + generate(); + } return cards; } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + /** + * @return int + */ @Override - public int hashCode() { + public final int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((cardSet == null) ? 0 : cardSet.hashCode()); return result; } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ @Override - public boolean equals(Object obj) { - if (this == obj) + public final boolean equals(final Object obj) { + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } BoosterPack other = (BoosterPack) obj; if (cardSet == null) { - if (other.cardSet != null) + if (other.cardSet != null) { return false; - } else if (!cardSet.equals(other.cardSet)) + } + } else if (!cardSet.equals(other.cardSet)) { return false; + } return true; } - @Override public String getType() { return "Booster Pack"; } - @Override public Object clone() { - return new BoosterPack(cardSet); // it's ok to share a reference to cardSet which is static anyway + /* (non-Javadoc) + * @see forge.item.InventoryItem#getType() + */ + /** + * @return String + */ + @Override + public final String getType() { + return "Booster Pack"; } - - + /* (non-Javadoc) + * @see java.lang.Object#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 + } } diff --git a/src/main/java/forge/item/CardDb.java b/src/main/java/forge/item/CardDb.java index e629182ebc2..4b76f10f435 100644 --- a/src/main/java/forge/item/CardDb.java +++ b/src/main/java/forge/item/CardDb.java @@ -5,87 +5,126 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Map.Entry; +import java.util.NoSuchElementException; import net.slightlymagic.braids.util.lambda.Lambda1; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; + import forge.Card; import forge.card.CardInSet; import forge.card.CardRules; import forge.card.MtgDataParser; - /** - *

CardDb class.

- * + *

+ * CardDb class. + *

+ * * @author Forge * @version $Id: CardDb.java 9708 2011-08-09 19:34:12Z jendave $ */ public final class CardDb { - private static volatile CardDb onlyInstance = null; // 'volatile' keyword makes this working - public static CardDb instance() { + private static volatile CardDb onlyInstance = null; // 'volatile' keyword + // makes this working + + /** + * Instance. + * + * @return the card db + */ + public static CardDb instance() { if (onlyInstance == null) { throw new NullPointerException("CardDb has not yet been initialized, run setup() first"); } return onlyInstance; } + + /** + * Sets the up. + * + * @param list the new up + */ public static void setup(final Iterator list) { if (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! + if (onlyInstance == null) { // It's broken under 1.4 and below, on + // 1.5+ works again! onlyInstance = new CardDb(list); } } } // Here oracle cards - //private final Map cards = new Hashtable(); - + // private final Map cards = new Hashtable(); + // Here are refs, get them by name 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 - public static final Lambda1 fnGetCardPrintedByForgeCard = new Lambda1() { - @Override public CardPrinted apply(final Card from) { return CardDb.instance().getCard(from.getName()); } + /** The Constant fnGetCardPrintedByForgeCard. */ + public static final Lambda1 fnGetCardPrintedByForgeCard = + new Lambda1() { + @Override + public CardPrinted apply(final Card from) { + return CardDb.instance().getCard(from.getName()); + } }; private CardDb() { - this(new MtgDataParser()); // I wish cardname.txt parser was be here. + this(new MtgDataParser()); // I wish cardname.txt parser was be here. } private CardDb(final Iterator parser) { while (parser.hasNext()) { addNewCard(parser.next()); } - // TODO: consider using Collections.unmodifiableList wherever possible + // TODO consider using Collections.unmodifiableList wherever possible } + /** + * Adds the new card. + * + * @param card the card + */ public void addNewCard(final CardRules card) { - if (null == card) { return; } // consider that a success - //System.out.println(card.getName()); + if (null == card) { + return; + } // consider that a success + // System.out.println(card.getName()); String cardName = card.getName().toLowerCase(); // 1. register among oracle uniques - //cards.put(cardName, card); + // cards.put(cardName, card); - // 2. Save refs into two lists: one flat and other keyed with sets & name + // 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); + lastAdded = addToLists(card, cardName, s); } - uniqueCards.put(cardName, lastAdded); + uniqueCards.put(cardName, lastAdded); } - + + /** + * Adds the to lists. + * + * @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(); @@ -101,32 +140,43 @@ public final class CardDb { 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()); + lastAdded = CardPrinted.build(card, set, s.getValue().getRarity(), i, card.isAltState(), + card.isDoubleFaced()); allCardsFlat.add(lastAdded); cardCopies[i] = lastAdded; } - + return lastAdded; } - public boolean isCardSupported(final String cardName) { + /** + * Checks if is card supported. + * + * @param cardName the card name + * @return true, if is card supported + */ + public boolean isCardSupported(final String cardName) { ImmutablePair nameWithSet = splitCardName(cardName); - if ( nameWithSet.right == null ) { return uniqueCards.containsKey(nameWithSet.left.toLowerCase()); } + if (nameWithSet.right == null) { + return uniqueCards.containsKey(nameWithSet.left.toLowerCase()); + } // Set exists? Map cardsFromset = allCardsBySet.get(nameWithSet.right.toUpperCase()); - if (cardsFromset == null) return false; + if (cardsFromset == null) { + return false; + } // Card exists? CardPrinted[] cardCopies = cardsFromset.get(nameWithSet.left.toLowerCase()); return cardCopies != null && cardCopies.length > 0; } - + /** - * Splits cardname into Name and set whenever deck line reads as name|set + * Splits cardname into Name and set whenever deck line reads as name|set. */ private static ImmutablePair splitCardName(final String name) { String cardName = name; // .trim() ? int pipePos = cardName.indexOf('|'); - + if (pipePos >= 0) { String setName = cardName.substring(pipePos + 1).trim(); cardName = cardName.substring(0, pipePos); @@ -139,17 +189,47 @@ public final class CardDb { } // Single fetch + /** + * Gets the card. + * + * @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 + // Sometimes they read from decks things like "CardName|Set" - but we + // can handle it ImmutablePair nameWithSet = splitCardName(name); - if (nameWithSet.right != null) { return getCard(nameWithSet.left, nameWithSet.right); } + if (nameWithSet.right != null) { + return getCard(nameWithSet.left, nameWithSet.right); + } // OK, plain name here CardPrinted card = uniqueCards.get(nameWithSet.left.toLowerCase()); - if (card != null) { return card; } + if (card != null) { + return card; + } throw new NoSuchElementException(String.format("Card '%s' not found in our database.", name)); } + // Advanced fetch by name+set - public CardPrinted getCard(final String name, final String set) { return getCard(name, set, 0); } + /** + * Gets the card. + * + * @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); + } + + /** + * Gets the card. + * + * @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()); @@ -164,29 +244,64 @@ public final class CardDb { throw new NoSuchElementException(err); } // 3. Get the proper copy - if (artIndex >= 0 && artIndex <= cardCopies.length) { return cardCopies[artIndex]; } + 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); throw new NoSuchElementException(err); } - // Fetch from Forge's Card instance. Well, there should be no errors, but we'll still check + // Fetch from Forge's Card instance. Well, there should be no errors, but + // we'll still check + /** + * Gets the card. + * + * @param forgeCard the forge card + * @return the card + */ public CardPrinted getCard(final Card forgeCard) { String name = forgeCard.getName(); String set = forgeCard.getCurSetCode(); - if (StringUtils.isNotBlank(set)) { return getCard(name, set); } + if (StringUtils.isNotBlank(set)) { + return getCard(name, set); + } return getCard(name); } // Multiple fetch + /** + * Gets the cards. + * + * @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)); } + for (String name : names) { + result.add(getCard(name)); + } return result; } // returns a list of all cards from their respective latest editions - public Iterable getAllUniqueCards() { return uniqueCards.values(); } - //public Iterable getAllCardRules() { return cards.values(); } // still not needed - public Iterable getAllCards() { return allCardsFlat; } + /** + * Gets the all unique cards. + * + * @return the all unique cards + */ + public Iterable getAllUniqueCards() { + return uniqueCards.values(); + } + + // public Iterable getAllCardRules() { return cards.values(); } + // // still not needed + /** + * Gets the all cards. + * + * @return the all cards + */ + public Iterable getAllCards() { + return allCardsFlat; + } } diff --git a/src/main/java/forge/item/CardPrinted.java b/src/main/java/forge/item/CardPrinted.java index aafe7ff58f8..df2dbc3a2de 100644 --- a/src/main/java/forge/item/CardPrinted.java +++ b/src/main/java/forge/item/CardPrinted.java @@ -3,11 +3,12 @@ package forge.item; import java.util.Arrays; import java.util.List; -import org.apache.commons.lang3.ArrayUtils; - import net.slightlymagic.braids.util.lambda.Lambda1; import net.slightlymagic.maxmtg.Predicate; import net.slightlymagic.maxmtg.PredicateString; + +import org.apache.commons.lang3.ArrayUtils; + import forge.AllZone; import forge.Card; import forge.CardUtil; @@ -15,8 +16,10 @@ import forge.card.CardRarity; import forge.card.CardRules; /** - *

CardReference class.

- * + *

+ * CardReference class. + *

+ * * @author Forge * @version $Id: CardReference.java 9708 2011-08-09 19:34:12Z jendave $ */ @@ -33,35 +36,108 @@ public final class CardPrinted implements Comparable, InventoryItem private final boolean isDoubleFaced; // Calculated fields are below: - private final transient CardRarity rarity; // rarity is given in ctor when set is assigned + private final transient CardRarity rarity; // rarity is given in ctor when + // set is assigned - // need this to be sure that different cased names won't break the system (and create uniqie cardref entries) + // need this to be sure that different cased names won't break the system + // (and create uniqie cardref entries) private final transient String nameLcase; // image filename is calculated only after someone request it private transient String imageFilename = null; // field RO accessors - public String getName() { return name; } - public String getSet() { return cardSet; } - public int getArtIndex() { return artIndex; } - public boolean isFoil() { return foiled; } - public CardRules getCard() { return card; } - public CardRarity getRarity() { return rarity; } + /* (non-Javadoc) + * @see forge.item.InventoryItemFromSet#getName() + */ + /** + * @return String + */ + public String getName() { + return name; + } + + /* (non-Javadoc) + * @see forge.item.InventoryItemFromSet#getSet() + */ + /** + * @return String + */ + public String getSet() { + return cardSet; + } + + /** + * Gets the art index. + * + * @return the art index + */ + public int getArtIndex() { + return artIndex; + } + + /** + * Checks if is foil. + * + * @return true, if is foil + */ + public boolean isFoil() { + return foiled; + } + + /** + * Gets the card. + * + * @return the card + */ + public CardRules getCard() { + return card; + } + + /** + * Gets the rarity. + * + * @return the rarity + */ + public CardRarity getRarity() { + return rarity; + } + + /* (non-Javadoc) + * @see forge.item.InventoryItemFromSet#getImageFilename() + */ + /** + * @return String + */ public String getImageFilename() { - if (imageFilename == null) { imageFilename = CardUtil.buildFilename(this); } + if (imageFilename == null) { + imageFilename = CardUtil.buildFilename(this); + } return imageFilename; } - public String getType() { return card.getType().toString(); } + + /* (non-Javadoc) + * @see forge.item.InventoryItem#getType() + */ + /** + * @return String + */ + public String getType() { + return card.getType().toString(); + } // Lambda to get rules for selects from list of printed cards + /** The Constant fnGetRules. */ public static final Lambda1 fnGetRules = new Lambda1() { - @Override public CardRules apply(final CardPrinted from) { return from.card; } + @Override + public CardRules apply(final CardPrinted from) { + return from.card; + } }; // 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) + 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(); @@ -75,51 +151,98 @@ public final class CardPrinted implements Comparable, InventoryItem } /* package visibility */ - static CardPrinted build(final CardRules c, final String set, final CardRarity rare, final int index, final boolean isAlt, final boolean isDF) { + /** + * 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 + * @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) + { 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 + * @return the card printed + */ public static CardPrinted makeFoiled(final CardPrinted c) { return new CardPrinted(c.card, c.cardSet, c.rarity, c.artIndex, true, c.isAlternate, c.isDoubleFaced); } // Want this class to be a key for HashTable + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ @Override public boolean equals(final Object obj) { - if (this == obj) { return true; } - if (obj == null) { return false; } - if (getClass() != obj.getClass()) { return false; } + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } CardPrinted other = (CardPrinted) obj; - if (!name.equals(other.name)) { return false; } - if (!cardSet.equals(other.cardSet)) { return false; } - if (other.foiled != this.foiled || other.artIndex != this.artIndex) { return false; } + if (!name.equals(other.name)) { + return false; + } + if (!cardSet.equals(other.cardSet)) { + return false; + } + if (other.foiled != this.foiled || other.artIndex != this.artIndex) { + return false; + } return true; } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ @Override public int hashCode() { int code = nameLcase.hashCode() * 11 + cardSet.hashCode() * 59 + artIndex * 2; - if (foiled) { return code + 1; } + if (foiled) { + return code + 1; + } return code; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ @Override public String toString() { return name; // cannot still decide, if this "name|set" format is needed anymore - //return String.format("%s|%s", name, cardSet); + // return String.format("%s|%s", name, cardSet); } + /** + * To forge card. + * + * @return the card + */ public Card toForgeCard() { Card c = AllZone.getCardFactory().getCard(name, null); if (c != null) { c.setCurSetCode(getSet()); - c.setRandomPicture(artIndex+1); + c.setRandomPicture(artIndex + 1); c.setImageFilename(getImageFilename()); - if(c.hasAlternateState()) { + if (c.hasAlternateState()) { c.changeState(); c.setImageFilename(CardUtil.buildFilename(c)); c.changeState(); @@ -129,53 +252,111 @@ public final class CardPrinted implements Comparable, InventoryItem return c; } + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ @Override public int compareTo(final CardPrinted o) { int nameCmp = nameLcase.compareTo(o.nameLcase); - if (0 != nameCmp) { return nameCmp; } - // TODO: compare sets properly + if (0 != nameCmp) { + return nameCmp; + } + // TODO compare sets properly return cardSet.compareTo(o.cardSet); } - + + /** + * Checks if is alternate. + * + * @return true, if is alternate + */ public boolean isAlternate() { return isAlternate; } - + + /** + * Checks if is double faced. + * + * @return true, if is double faced + */ public boolean isDoubleFaced() { return isDoubleFaced; } /** - * Number of filters based on CardPrinted values. + * Number of filters based on CardPrinted values. */ public abstract static class Predicates { - public static Predicate rarity(final boolean isEqual, final CardRarity value) - { + + /** + * Rarity. + * + * @param isEqual the is equal + * @param value the value + * @return the predicate + */ + public static Predicate rarity(final boolean isEqual, final CardRarity value) { return new PredicateRarity(value, isEqual); } - public static Predicate printedInSets(final List value, final boolean shouldContain) - { + + /** + * Printed in sets. + * + * @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()) { return Predicate.getTrue(CardPrinted.class); } return new PredicateSets(value, shouldContain); } + + /** + * Printed in sets. + * + * @param value the value + * @return the predicate + */ public static Predicate printedInSets(final String value) { 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 + * @return the predicate + */ public static Predicate name(final String what) { return new PredicateName(PredicateString.StringOp.EQUALS, what); - } + } + + /** + * Name. + * + * @param op the op + * @param what the what + * @return the predicate + */ public static Predicate name(final PredicateString.StringOp op, final String what) { return new PredicateName(op, what); } + + /** + * Names except. + * + * @param what the what + * @return the predicate + */ public static Predicate namesExcept(final List what) { return new PredicateNamesExcept(what); } - + private static class PredicateNotAlternate extends Predicate { @Override public boolean isTrue(final CardPrinted card) { @@ -201,9 +382,12 @@ public final class CardPrinted implements Comparable, InventoryItem private static class PredicateSets extends Predicate { private final List sets; private final boolean mustContain; - @Override public boolean isTrue(final CardPrinted card) { + + @Override + public boolean isTrue(final CardPrinted card) { return sets.contains(card.cardSet) == mustContain; } + public PredicateSets(final List wantSets, final boolean shouldContain) { sets = wantSets; // maybe should make a copy here? mustContain = shouldContain; @@ -218,46 +402,64 @@ public final class CardPrinted implements Comparable, InventoryItem return op(card.getName(), operand); } - public PredicateName(final PredicateString.StringOp operator, final String operand) - { + public PredicateName(final PredicateString.StringOp operator, final String operand) { super(operator); this.operand = operand; } } - + private static class PredicateNamesExcept extends PredicateString { private final String[] operand; @Override public boolean isTrue(final CardPrinted card) { String cardName = card.getName(); - for(int i = 0; i < operand.length; i++) { - if ( op(cardName, operand[i]) ) return false; + for (int i = 0; i < operand.length; i++) { + if (op(cardName, operand[i])) { + return false; + } } return true; } - public PredicateNamesExcept(final List operand) - { + public PredicateNamesExcept(final List operand) { super(StringOp.EQUALS); this.operand = operand.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } } + /** - * Pre-built predicates are stored here to allow their re-usage and easier access from code. + * Pre-built predicates are stored here to allow their re-usage and + * easier access from code. */ public abstract static class Presets { - // Think twice before using these, since rarity is a prop of printed card. + // 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); + + /** The Constant isUncommon. */ public static final Predicate isUncommon = rarity(true, CardRarity.Uncommon); + + /** The Constant isRare. */ public static final Predicate isRare = rarity(true, CardRarity.Rare); + + /** The Constant isMythicRare. */ public static final Predicate isMythicRare = rarity(true, CardRarity.MythicRare); + + /** The Constant isRareOrMythic. */ public static final Predicate isRareOrMythic = Predicate.or(isRare, isMythicRare); + + /** The Constant isSpecial. */ public static final Predicate isSpecial = rarity(true, CardRarity.Special); + + /** The Constant exceptLands. */ public static final Predicate exceptLands = rarity(false, CardRarity.BasicLand); + /** The Constant isTrue. */ public static final Predicate isTrue = Predicate.getTrue(CardPrinted.class); - + + /** The Constant nonAlternate. */ public static final Predicate nonAlternate = new PredicateNotAlternate(); } } diff --git a/src/main/java/forge/item/CardPrintedCharacteristics.java b/src/main/java/forge/item/CardPrintedCharacteristics.java index 3850edb777c..7499d850ed6 100644 --- a/src/main/java/forge/item/CardPrintedCharacteristics.java +++ b/src/main/java/forge/item/CardPrintedCharacteristics.java @@ -1,34 +1,46 @@ package forge.item; -/** - * TODO: Write javadoc for this type. +/** * + * */ public class CardPrintedCharacteristics { private String name; private String cardSet; + /** + * Gets the name. + * * @return the name */ - public String getName() { + public final String getName() { return name; } + /** + * Sets the name. + * * @param name0 the name to set */ - public void setName(String name0) { - this.name = name0; // TODO: Add 0 to parameter's name. + public final void setName(final String name0) { + this.name = name0; // TODO Add 0 to parameter's name. } + /** + * Gets the card set. + * * @return the cardSet */ - public String getCardSet() { + public final String getCardSet() { return cardSet; } + /** + * Sets the card set. + * * @param cardSet0 the cardSet to set */ - public void setCardSet(String cardSet0) { + 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 fed89ffe542..873cfe0bb7d 100644 --- a/src/main/java/forge/item/InventoryItem.java +++ b/src/main/java/forge/item/InventoryItem.java @@ -1,14 +1,29 @@ package forge.item; -/** - * Interface to define a player's inventory may hold. - * Should include CardPrinted, Booster, Pets, Plants... etc +/** + * Interface to define a player's inventory may hold. Should include + * CardPrinted, Booster, Pets, Plants... etc */ -public interface InventoryItem /* extends Comparable */ { - /** An inventory item has to provide a name. */ +public interface InventoryItem /* extends Comparable */{ + + /** + * An inventory item has to provide a name. + * + * @return the name + */ String getName(); - /** An inventory item has to provide a picture. */ + + /** + * An inventory item has to provide a picture. + * + * @return the image filename + */ String getImageFilename(); - /** Return type as a string */ + + /** + * Return type as a string. + * + * @return the type + */ String getType(); } diff --git a/src/main/java/forge/item/InventoryItemFromSet.java b/src/main/java/forge/item/InventoryItemFromSet.java index b139a3e5b5a..6cc7b50a0a9 100644 --- a/src/main/java/forge/item/InventoryItemFromSet.java +++ b/src/main/java/forge/item/InventoryItemFromSet.java @@ -1,14 +1,29 @@ package forge.item; -/** - * Interface to define a player's inventory may hold. - * Should include CardPrinted, Booster, Pets, Plants... etc +/** + * Interface to define a player's inventory may hold. Should include + * CardPrinted, Booster, Pets, Plants... etc */ public interface InventoryItemFromSet extends InventoryItem { - /** An inventory item has to provide a name. */ + + /** + * An inventory item has to provide a name. + * + * @return the name + */ String getName(); - /** An inventory item has to provide a picture. */ + + /** + * An inventory item has to provide a picture. + * + * @return the image filename + */ String getImageFilename(); - /** An item belonging to a set should return its set as well*/ + + /** + * 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/ItemPoolView.java b/src/main/java/forge/item/ItemPoolView.java index df0bb72de80..6cc22c06279 100644 --- a/src/main/java/forge/item/ItemPoolView.java +++ b/src/main/java/forge/item/ItemPoolView.java @@ -7,120 +7,136 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import net.slightlymagic.braids.util.lambda.Lambda1; import forge.CardList; import forge.card.CardRules; -import net.slightlymagic.braids.util.lambda.Lambda1; - /** - *

CardPoolView class.

+ *

+ * CardPoolView class. + *

* + * @param an InventoryItem * @author Forge * @version $Id: CardPoolView.java 9708 2011-08-09 19:34:12Z jendave $ - * @param an InventoryItem */ public class ItemPoolView implements Iterable> { // Field Accessors for select/aggregate operations with filters. - /** - * - */ - public final Lambda1> fnToCard = - new Lambda1>() { - @Override public CardRules apply(final Entry from) { - T item = from.getKey(); - return item instanceof CardPrinted ? ((CardPrinted) item).getCard() : null; - } - }; + /** The fn to card. */ + public final Lambda1> fnToCard = new Lambda1>() { + @Override + public CardRules apply(final Entry from) { + T item = from.getKey(); + return item instanceof CardPrinted ? ((CardPrinted) item).getCard() : null; + } + }; - /** - * - */ - public final Lambda1> fnToPrinted = - new Lambda1>() { - @Override public T apply(final Entry from) { return from.getKey(); } - }; + /** The fn to printed. */ + public final Lambda1> fnToPrinted = new Lambda1>() { + @Override + public T apply(final Entry from) { + return from.getKey(); + } + }; - /** - * - */ - public final Lambda1> fnToCardName = - new Lambda1>() { - @Override public String apply(final Entry from) { return from.getKey().getName(); } - }; + /** The fn to card name. */ + public final Lambda1> fnToCardName = new Lambda1>() { + @Override + public String apply(final Entry from) { + return from.getKey().getName(); + } + }; - /** - * - */ - public final Lambda1> fnToCount = - new Lambda1>() { - @Override public Integer apply(final Entry from) { return from.getValue(); } - }; + /** The fn to count. */ + public final Lambda1> fnToCount = new Lambda1>() { + @Override + public Integer apply(final Entry from) { + return from.getValue(); + } + }; // Constructors - /** - * - * ItemPoolView. - * @param cls a Class - */ - public ItemPoolView(final Class cls) { cards = new Hashtable(); myClass = cls; } + /** + * + * ItemPoolView. + * + * @param cls + * a Class + */ + public ItemPoolView(final Class cls) { + cards = new Hashtable(); + myClass = cls; + } /** * * ItemPoolView. - * @param inMap a Map - * @param cls a Class + * + * @param inMap + * a Map + * @param cls + * a Class */ - public ItemPoolView(final Map inMap, final Class cls) { cards = inMap; myClass = cls; } + public ItemPoolView(final Map inMap, final Class cls) { + cards = inMap; + myClass = cls; + } // Data members - /** - * - */ + /** The cards. */ protected Map cards; - /** - * - */ - protected final Class myClass; // class does not keep this in runtime by itself + + /** The my class. */ + protected 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) - /** - * - */ - protected List> cardsListOrdered = new ArrayList>(); + // 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>(); - /** - * - */ + /** The is list in sync. */ protected boolean isListInSync = false; /** * iterator. + * * @return Iterator> */ @Override - public final Iterator> iterator() { return cards.entrySet().iterator(); } + public final Iterator> iterator() { + return cards.entrySet().iterator(); + } // Cards read only operations /** * * contains. - * @param card a T + * + * @param card + * a T * @return boolean */ public final boolean contains(final T card) { - if (cards == null) { return false; } + if (cards == null) { + return false; + } return cards.containsKey(card); } /** * * count. - * @param card a T + * + * @param card + * a T * @return int */ public final int count(final T card) { - if (cards == null) { return 0; } + if (cards == null) { + return 0; + } Integer boxed = cards.get(card); return boxed == null ? 0 : boxed.intValue(); } @@ -128,35 +144,49 @@ public class ItemPoolView implements Iterable> */ public final List> getOrderedList() { - if (!isListInSync) { rebuildOrderedList(); } + if (!isListInSync) { + rebuildOrderedList(); + } return cardsListOrdered; } @@ -173,12 +203,15 @@ public class ItemPoolView implements Iterable */ public final List toFlatList() { List result = new ArrayList(); for (Entry e : this) { - for (int i = 0; i < e.getValue(); i++) { result.add(e.getKey()); } + for (int i = 0; i < e.getValue(); i++) { + result.add(e.getKey()); + } } return result; } @@ -186,15 +219,16 @@ public class ItemPoolView implements Iterable e : this) { if (e.getKey() instanceof CardPrinted) { - for (int i = 0; i < e.getValue(); i++) { - result.add(((CardPrinted) e.getKey()).toForgeCard()); - } + for (int i = 0; i < e.getValue(); i++) { + result.add(((CardPrinted) e.getKey()).toForgeCard()); + } } } return result; diff --git a/src/main/java/forge/item/package-info.java b/src/main/java/forge/item/package-info.java index 72766023122..c37d4b7a98c 100644 --- a/src/main/java/forge/item/package-info.java +++ b/src/main/java/forge/item/package-info.java @@ -1,2 +1,2 @@ -/** Forge Card Game */ +/** Forge Card Game. */ package forge.item;