mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
checkstyle and refactor
This commit is contained in:
@@ -63,12 +63,12 @@ public final class BoosterUtils {
|
||||
final Iterable<CardPrinted> 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<CardPrinted> filterMythics = Predicate.and(filter, CardPrinted.Predicates.Presets.isMythicRare);
|
||||
final Predicate<CardPrinted> 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<CardRules> 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<CardPrinted> 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<CardPrinted> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,15 +38,15 @@ public final class GameFormat {
|
||||
|
||||
private Predicate<CardPrinted> buildFilterPritned() {
|
||||
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
||||
final Predicate<CardPrinted> allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue
|
||||
final Predicate<CardPrinted> 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<CardPrinted> buildFilterRules() {
|
||||
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
||||
final Predicate<CardPrinted> allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue
|
||||
: Predicate.brigde(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.fnGetRules);
|
||||
final Predicate<CardPrinted> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
||||
protected Predicate<InventoryItem> buildFilter() {
|
||||
final Predicate<CardPrinted> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_CREATURE.select(all, all.fnToCard)) {
|
||||
CardRules.Predicates.Presets.IS_CREATURE.aggregate(all, all.getFnToCard(), all.getFnToCount())));
|
||||
for (final Entry<CardPrinted, Integer> 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<CardPrinted, Integer> 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<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_LAND.select(all, all.fnToCard)) {
|
||||
CardRules.Predicates.Presets.IS_LAND.aggregate(all, all.getFnToCard(), all.getFnToCount())));
|
||||
for (final Entry<CardPrinted, Integer> e : CardRules.Predicates.Presets.IS_LAND.select(all, all.getFnToCard())) {
|
||||
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ class FilterCheckBoxes {
|
||||
final Predicate<CardRules> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -171,8 +171,8 @@ public final class TableWithCards {
|
||||
*/
|
||||
public static String getStats(final ItemPoolView<InventoryItem> 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<Predicate<CardRules>> 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();
|
||||
|
||||
@@ -16,7 +16,7 @@ import forge.card.CardSet;
|
||||
public class BoosterPack implements InventoryItemFromSet {
|
||||
|
||||
/** The Constant fnFromSet. */
|
||||
public static final Lambda1<BoosterPack, CardSet> fnFromSet = new Lambda1<BoosterPack, CardSet>() {
|
||||
public static final Lambda1<BoosterPack, CardSet> FN_FROM_SET = new Lambda1<BoosterPack, CardSet>() {
|
||||
@Override
|
||||
public BoosterPack apply(final CardSet arg1) {
|
||||
return new BoosterPack(arg1);
|
||||
@@ -31,7 +31,8 @@ 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));
|
||||
@@ -40,72 +41,85 @@ 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<CardSet> sets = SetUtils.getAllSets();
|
||||
int iThisSet = sets.indexOf(cardSet);
|
||||
final List<CardSet> 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,27 +129,33 @@ public class BoosterPack implements InventoryItemFromSet {
|
||||
* @return the cards
|
||||
*/
|
||||
public final List<CardPrinted> 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<CardRules> 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<String, CardPrinted> uniqueCards = new Hashtable<String, CardPrinted>();
|
||||
|
||||
// need this to obtain cardReference by name+set+artindex
|
||||
private final Map<String, Map<String, CardPrinted[]>> allCardsBySet =
|
||||
new Hashtable<String, Map<String, CardPrinted[]>>();
|
||||
private final Map<String, Map<String, CardPrinted[]>> allCardsBySet = new Hashtable<String, Map<String, CardPrinted[]>>();
|
||||
// this is the same list in flat storage
|
||||
private final List<CardPrinted> allCardsFlat = new ArrayList<CardPrinted>();
|
||||
|
||||
// Lambda to get rules for selects from list of printed cards
|
||||
/** The Constant fnGetCardPrintedByForgeCard. */
|
||||
public static final Lambda1<CardPrinted, Card> fnGetCardPrintedByForgeCard =
|
||||
new Lambda1<CardPrinted, Card>() {
|
||||
public static final Lambda1<CardPrinted, Card> FN_GET_CARD_PRINTED_BY_FORGE_CARD = new Lambda1<CardPrinted, Card>() {
|
||||
@Override
|
||||
public CardPrinted apply(final Card from) {
|
||||
return CardDb.instance().getCard(from.getName());
|
||||
@@ -88,7 +88,7 @@ public final class CardDb {
|
||||
|
||||
private CardDb(final Iterator<CardRules> parser) {
|
||||
while (parser.hasNext()) {
|
||||
addNewCard(parser.next());
|
||||
this.addNewCard(parser.next());
|
||||
}
|
||||
// TODO consider using Collections.unmodifiableList wherever possible
|
||||
}
|
||||
@@ -96,14 +96,15 @@ public final class CardDb {
|
||||
/**
|
||||
* 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<String, CardInSet> s : card.getSetsPrinted()) {
|
||||
lastAdded = addToLists(card, cardName, s);
|
||||
for (final Entry<String, CardInSet> 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<String, CardInSet> s) {
|
||||
CardPrinted lastAdded = null;
|
||||
String set = s.getKey();
|
||||
final String set = s.getKey();
|
||||
|
||||
// get this set storage, if not found, create it!
|
||||
Map<String, CardPrinted[]> setMap = allCardsBySet.get(set);
|
||||
Map<String, CardPrinted[]> setMap = this.allCardsBySet.get(set);
|
||||
if (null == setMap) {
|
||||
setMap = new Hashtable<String, CardPrinted[]>();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -152,22 +156,23 @@ 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<String, String> nameWithSet = splitCardName(cardName);
|
||||
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(cardName);
|
||||
if (nameWithSet.right == null) {
|
||||
return uniqueCards.containsKey(nameWithSet.left.toLowerCase());
|
||||
return this.uniqueCards.containsKey(nameWithSet.left.toLowerCase());
|
||||
}
|
||||
// Set exists?
|
||||
Map<String, CardPrinted[]> cardsFromset = allCardsBySet.get(nameWithSet.right.toUpperCase());
|
||||
final Map<String, CardPrinted[]> 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<String, String> 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)) {
|
||||
@@ -192,18 +197,19 @@ public final class CardDb {
|
||||
/**
|
||||
* 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<String, String> nameWithSet = splitCardName(name);
|
||||
final ImmutablePair<String, String> 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;
|
||||
}
|
||||
@@ -214,40 +220,48 @@ public final class CardDb {
|
||||
/**
|
||||
* 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<String, CardPrinted[]> cardsFromset = allCardsBySet.get(set.toUpperCase());
|
||||
final Map<String, CardPrinted[]> 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);
|
||||
}
|
||||
|
||||
@@ -256,29 +270,31 @@ public final class CardDb {
|
||||
/**
|
||||
* 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<CardPrinted> getCards(final Iterable<String> names) {
|
||||
List<CardPrinted> result = new ArrayList<CardPrinted>();
|
||||
for (String name : names) {
|
||||
result.add(getCard(name));
|
||||
final List<CardPrinted> result = new ArrayList<CardPrinted>();
|
||||
for (final String name : names) {
|
||||
result.add(this.getCard(name));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -290,7 +306,7 @@ public final class CardDb {
|
||||
* @return the all unique cards
|
||||
*/
|
||||
public Iterable<CardPrinted> getAllUniqueCards() {
|
||||
return uniqueCards.values();
|
||||
return this.uniqueCards.values();
|
||||
}
|
||||
|
||||
// public Iterable<CardRules> getAllCardRules() { return cards.values(); }
|
||||
@@ -301,7 +317,7 @@ public final class CardDb {
|
||||
* @return the all cards
|
||||
*/
|
||||
public Iterable<CardPrinted> getAllCards() {
|
||||
return allCardsFlat;
|
||||
return this.allCardsFlat;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,24 +47,34 @@ public final class CardPrinted implements Comparable<CardPrinted>, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +83,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
* @return the art index
|
||||
*/
|
||||
public int getArtIndex() {
|
||||
return artIndex;
|
||||
return this.artIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +92,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
* @return true, if is foil
|
||||
*/
|
||||
public boolean isFoil() {
|
||||
return foiled;
|
||||
return this.foiled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +101,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
* @return the card
|
||||
*/
|
||||
public CardRules getCard() {
|
||||
return card;
|
||||
return this.card;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,35 +110,45 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
* @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<CardRules, CardPrinted> fnGetRules = new Lambda1<CardRules, CardPrinted>() {
|
||||
public static final Lambda1<CardRules, CardPrinted> FN_GET_RULES = new Lambda1<CardRules, CardPrinted>() {
|
||||
@Override
|
||||
public CardRules apply(final CardPrinted from) {
|
||||
return from.card;
|
||||
@@ -137,34 +157,38 @@ public final class CardPrinted implements Comparable<CardPrinted>, 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);
|
||||
}
|
||||
|
||||
@@ -172,7 +196,8 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
/**
|
||||
* 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<CardPrinted>, InventoryItem
|
||||
}
|
||||
|
||||
// Want this class to be a key for HashTable
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@@ -191,42 +218,46 @@ public final class CardPrinted implements Comparable<CardPrinted>, 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);
|
||||
}
|
||||
@@ -237,11 +268,11 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
* @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,17 +283,19 @@ public final class CardPrinted implements Comparable<CardPrinted>, 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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,7 +304,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
* @return true, if is alternate
|
||||
*/
|
||||
public boolean isAlternate() {
|
||||
return isAlternate;
|
||||
return this.isAlternate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +313,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
* @return true, if is double faced
|
||||
*/
|
||||
public boolean isDoubleFaced() {
|
||||
return isDoubleFaced;
|
||||
return this.isDoubleFaced;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,8 +324,10 @@ public final class CardPrinted implements Comparable<CardPrinted>, 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<CardPrinted> rarity(final boolean isEqual, final CardRarity value) {
|
||||
@@ -302,12 +337,14 @@ public final class CardPrinted implements Comparable<CardPrinted>, 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<CardPrinted> printedInSets(final List<String> value, final boolean shouldContain) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
if ((value == null) || value.isEmpty()) {
|
||||
return Predicate.getTrue(CardPrinted.class);
|
||||
}
|
||||
return new PredicateSets(value, shouldContain);
|
||||
@@ -316,20 +353,22 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
/**
|
||||
* Printed in sets.
|
||||
*
|
||||
* @param value the value
|
||||
* @param value
|
||||
* the value
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardPrinted> 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<CardPrinted> name(final String what) {
|
||||
@@ -339,8 +378,10 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
/**
|
||||
* Name.
|
||||
*
|
||||
* @param op the op
|
||||
* @param what the what
|
||||
* @param op
|
||||
* the op
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardPrinted> name(final PredicateString.StringOp op, final String what) {
|
||||
@@ -350,7 +391,8 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
/**
|
||||
* Names except.
|
||||
*
|
||||
* @param what the what
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardPrinted> namesExcept(final List<String> what) {
|
||||
@@ -370,12 +412,12 @@ public final class CardPrinted implements Comparable<CardPrinted>, 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<CardPrinted>, 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<String> 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<CardPrinted>, 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<CardPrinted>, 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<CardPrinted>, InventoryItem
|
||||
// Think twice before using these, since rarity is a prop of printed
|
||||
// card.
|
||||
/** The Constant isCommon. */
|
||||
public static final Predicate<CardPrinted> isCommon = rarity(true, CardRarity.Common);
|
||||
public static final Predicate<CardPrinted> IS_COMMON = Predicates.rarity(true, CardRarity.Common);
|
||||
|
||||
/** The Constant isUncommon. */
|
||||
public static final Predicate<CardPrinted> isUncommon = rarity(true, CardRarity.Uncommon);
|
||||
public static final Predicate<CardPrinted> IS_UNCOMMON = Predicates.rarity(true, CardRarity.Uncommon);
|
||||
|
||||
/** The Constant isRare. */
|
||||
public static final Predicate<CardPrinted> isRare = rarity(true, CardRarity.Rare);
|
||||
public static final Predicate<CardPrinted> IS_RARE = Predicates.rarity(true, CardRarity.Rare);
|
||||
|
||||
/** The Constant isMythicRare. */
|
||||
public static final Predicate<CardPrinted> isMythicRare = rarity(true, CardRarity.MythicRare);
|
||||
public static final Predicate<CardPrinted> IS_MYTHIC_RARE = Predicates.rarity(true, CardRarity.MythicRare);
|
||||
|
||||
/** The Constant isRareOrMythic. */
|
||||
public static final Predicate<CardPrinted> isRareOrMythic = Predicate.or(isRare, isMythicRare);
|
||||
public static final Predicate<CardPrinted> IS_RARE_OR_MYTHIC = Predicate.or(Presets.IS_RARE,
|
||||
Presets.IS_MYTHIC_RARE);
|
||||
|
||||
/** The Constant isSpecial. */
|
||||
public static final Predicate<CardPrinted> isSpecial = rarity(true, CardRarity.Special);
|
||||
public static final Predicate<CardPrinted> IS_SPECIAL = Predicates.rarity(true, CardRarity.Special);
|
||||
|
||||
/** The Constant exceptLands. */
|
||||
public static final Predicate<CardPrinted> exceptLands = rarity(false, CardRarity.BasicLand);
|
||||
public static final Predicate<CardPrinted> EXCEPT_LANDS = Predicates.rarity(false, CardRarity.BasicLand);
|
||||
|
||||
/** The Constant isTrue. */
|
||||
public static final Predicate<CardPrinted> isTrue = Predicate.getTrue(CardPrinted.class);
|
||||
public static final Predicate<CardPrinted> IS_TRUE = Predicate.getTrue(CardPrinted.class);
|
||||
|
||||
/** The Constant nonAlternate. */
|
||||
public static final Predicate<CardPrinted> nonAlternate = new PredicateNotAlternate();
|
||||
public static final Predicate<CardPrinted> NON_ALTERNATE = new PredicateNotAlternate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package forge.item;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* The Class CardPrintedCharacteristics.
|
||||
*/
|
||||
public class CardPrintedCharacteristics {
|
||||
private String name;
|
||||
@@ -14,13 +13,14 @@ public class CardPrintedCharacteristics {
|
||||
* @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.
|
||||
@@ -32,13 +32,14 @@ public class CardPrintedCharacteristics {
|
||||
* @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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -11,6 +11,7 @@ public interface InventoryItemFromSet extends InventoryItem {
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
@Override
|
||||
String getName();
|
||||
|
||||
/**
|
||||
@@ -18,6 +19,7 @@ public interface InventoryItemFromSet extends InventoryItem {
|
||||
*
|
||||
* @return the image filename
|
||||
*/
|
||||
@Override
|
||||
String getImageFilename();
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,51 +3,65 @@ package forge.item;
|
||||
import java.util.Collections;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
/**
|
||||
* <p>CardPool class.</p>
|
||||
* <p>
|
||||
* CardPool class.
|
||||
* </p>
|
||||
* Represents a list of cards with amount of each
|
||||
* @param <T> an Object
|
||||
*
|
||||
* @param <T>
|
||||
* an Object
|
||||
*/
|
||||
public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
||||
public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
||||
|
||||
// Constructors here
|
||||
/**
|
||||
*
|
||||
* ItemPool Constructor.
|
||||
* @param cls a T
|
||||
*
|
||||
* @param cls
|
||||
* a T
|
||||
*/
|
||||
public ItemPool(final Class<T> cls) { super(cls); }
|
||||
public ItemPool(final Class<T> 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<String> names, final Class<T> cls) {
|
||||
super(cls);
|
||||
addAllCards((Iterable<T>) CardDb.instance().getCards(names));
|
||||
}
|
||||
this.addAllCards((Iterable<T>) CardDb.instance().getCards(names));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* createFrom method.
|
||||
* @param from a Tin
|
||||
* @param clsHint a Tout
|
||||
* @param <Tin> an InventoryItem
|
||||
* @param <Tout> an InventoryItem
|
||||
*
|
||||
* @param <Tin>
|
||||
* an InventoryItem
|
||||
* @param <Tout>
|
||||
* an InventoryItem
|
||||
* @param from
|
||||
* a Tin
|
||||
* @param clsHint
|
||||
* a Tout
|
||||
* @return InventoryItem
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
|
||||
createFrom(final ItemPoolView<Tin> from, final Class<Tout> clsHint)
|
||||
{
|
||||
ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(
|
||||
final ItemPoolView<Tin> from, final Class<Tout> clsHint) {
|
||||
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||
if (from != null) {
|
||||
for (Entry<Tin, Integer> e : from) {
|
||||
Tin srcKey = e.getKey();
|
||||
for (final Entry<Tin, Integer> 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<T extends InventoryItem> extends ItemPoolView<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* createFrom method.
|
||||
* @param from a Iterable<Tin>
|
||||
* @param clsHint a Class<Tout>
|
||||
*
|
||||
* @param <Tin>
|
||||
* an InventoryItem
|
||||
* @param <Tout>
|
||||
* an InventoryItem
|
||||
* @param from
|
||||
* a Iterable<Tin>
|
||||
* @param clsHint
|
||||
* a Class<Tout>
|
||||
* @return <Tin> an InventoryItem
|
||||
* @param <Tin> an InventoryItem
|
||||
* @param <Tout> an InventoryItem
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
|
||||
createFrom(final Iterable<Tin> from, final Class<Tout> clsHint)
|
||||
{
|
||||
ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(
|
||||
final Iterable<Tin> from, final Class<Tout> clsHint) {
|
||||
final ItemPool<Tout> result = new ItemPool<Tout>(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<T extends InventoryItem> extends ItemPoolView<T> {
|
||||
/**
|
||||
*
|
||||
* Get item view.
|
||||
*
|
||||
* @return a ItemPoolView
|
||||
*/
|
||||
public ItemPoolView<T> getView() { return new ItemPoolView<T>(Collections.unmodifiableMap(cards), myClass); }
|
||||
public ItemPoolView<T> getView() {
|
||||
return new ItemPoolView<T>(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<U>
|
||||
* @param <U> a InventoryItem
|
||||
*
|
||||
* @param <U>
|
||||
* a InventoryItem
|
||||
* @param cards
|
||||
* a Iterable<U>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <U extends InventoryItem> void addAllCards(final Iterable<U> 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<Entry<U, Integer>>
|
||||
* @param <U> an InventoryItem
|
||||
*
|
||||
* @param <U>
|
||||
* an InventoryItem
|
||||
* @param map
|
||||
* a Iterable<Entry<U, Integer>>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <U extends InventoryItem> void addAll(final Iterable<Entry<U, Integer>> map) {
|
||||
for (Entry<U, Integer> e : map) {
|
||||
if (myClass.isInstance(e.getKey())) {
|
||||
add((T) e.getKey(), e.getValue());
|
||||
for (final Entry<U, Integer> 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<Entry<T, Integer>> map) {
|
||||
for (Entry<T, Integer> e : map) { remove(e.getKey(), e.getValue()); }
|
||||
isListInSync = false;
|
||||
for (final Entry<T, Integer> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ import forge.card.CardRules;
|
||||
* CardPoolView class.
|
||||
* </p>
|
||||
*
|
||||
* @param <T> an InventoryItem
|
||||
* @param <T>
|
||||
* an InventoryItem
|
||||
* @author Forge
|
||||
* @version $Id: CardPoolView.java 9708 2011-08-09 19:34:12Z jendave $
|
||||
*/
|
||||
@@ -24,16 +25,16 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
|
||||
// Field Accessors for select/aggregate operations with filters.
|
||||
/** The fn to card. */
|
||||
public final Lambda1<CardRules, Entry<T, Integer>> fnToCard = new Lambda1<CardRules, Entry<T, Integer>>() {
|
||||
private final Lambda1<CardRules, Entry<T, Integer>> fnToCard = new Lambda1<CardRules, Entry<T, Integer>>() {
|
||||
@Override
|
||||
public CardRules apply(final Entry<T, Integer> 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<T, Entry<T, Integer>> fnToPrinted = new Lambda1<T, Entry<T, Integer>>() {
|
||||
private final Lambda1<T, Entry<T, Integer>> fnToPrinted = new Lambda1<T, Entry<T, Integer>>() {
|
||||
@Override
|
||||
public T apply(final Entry<T, Integer> from) {
|
||||
return from.getKey();
|
||||
@@ -41,7 +42,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
};
|
||||
|
||||
/** The fn to card name. */
|
||||
public final Lambda1<String, Entry<T, Integer>> fnToCardName = new Lambda1<String, Entry<T, Integer>>() {
|
||||
private final Lambda1<String, Entry<T, Integer>> fnToCardName = new Lambda1<String, Entry<T, Integer>>() {
|
||||
@Override
|
||||
public String apply(final Entry<T, Integer> from) {
|
||||
return from.getKey().getName();
|
||||
@@ -49,7 +50,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
};
|
||||
|
||||
/** The fn to count. */
|
||||
public final Lambda1<Integer, Entry<T, Integer>> fnToCount = new Lambda1<Integer, Entry<T, Integer>>() {
|
||||
private final Lambda1<Integer, Entry<T, Integer>> fnToCount = new Lambda1<Integer, Entry<T, Integer>>() {
|
||||
@Override
|
||||
public Integer apply(final Entry<T, Integer> from) {
|
||||
return from.getValue();
|
||||
@@ -65,8 +66,8 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* a Class<T>
|
||||
*/
|
||||
public ItemPoolView(final Class<T> cls) {
|
||||
cards = new Hashtable<T, Integer>();
|
||||
myClass = cls;
|
||||
this.setCards(new Hashtable<T, Integer>());
|
||||
this.myClass = cls;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,25 +80,25 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* a Class<T>
|
||||
*/
|
||||
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) {
|
||||
cards = inMap;
|
||||
myClass = cls;
|
||||
this.setCards(inMap);
|
||||
this.myClass = cls;
|
||||
}
|
||||
|
||||
// Data members
|
||||
/** The cards. */
|
||||
protected Map<T, Integer> cards;
|
||||
private Map<T, Integer> cards;
|
||||
|
||||
/** The my class. */
|
||||
protected final Class<T> myClass; // class does not keep this in runtime by
|
||||
private final Class<T> 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<Entry<T, Integer>> cardsListOrdered = new ArrayList<Map.Entry<T, Integer>>();
|
||||
private List<Entry<T, Integer>> cardsListOrdered = new ArrayList<Map.Entry<T, Integer>>();
|
||||
|
||||
/** The is list in sync. */
|
||||
protected boolean isListInSync = false;
|
||||
private boolean isListInSync = false;
|
||||
|
||||
/**
|
||||
* iterator.
|
||||
@@ -106,7 +107,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
*/
|
||||
@Override
|
||||
public final Iterator<Entry<T, Integer>> iterator() {
|
||||
return cards.entrySet().iterator();
|
||||
return this.getCards().entrySet().iterator();
|
||||
}
|
||||
|
||||
// Cards read only operations
|
||||
@@ -119,10 +120,10 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean contains(final T card) {
|
||||
if (cards == null) {
|
||||
if (this.getCards() == null) {
|
||||
return false;
|
||||
}
|
||||
return cards.containsKey(card);
|
||||
return this.getCards().containsKey(card);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,10 +135,10 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* @return int
|
||||
*/
|
||||
public final int count(final T card) {
|
||||
if (cards == null) {
|
||||
if (this.getCards() == null) {
|
||||
return 0;
|
||||
}
|
||||
Integer boxed = cards.get(card);
|
||||
final Integer boxed = this.getCards().get(card);
|
||||
return boxed == null ? 0 : boxed.intValue();
|
||||
}
|
||||
|
||||
@@ -149,8 +150,8 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
*/
|
||||
public final int countAll() {
|
||||
int result = 0;
|
||||
if (cards != null) {
|
||||
for (Integer n : cards.values()) {
|
||||
if (this.getCards() != null) {
|
||||
for (final Integer n : this.getCards().values()) {
|
||||
result += n;
|
||||
}
|
||||
}
|
||||
@@ -164,7 +165,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* @return int
|
||||
*/
|
||||
public final int countDistinct() {
|
||||
return cards.size();
|
||||
return this.getCards().size();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +175,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean isEmpty() {
|
||||
return cards == null || cards.isEmpty();
|
||||
return (this.getCards() == null) || this.getCards().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,20 +185,20 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* @return List<Entry<T, Integer>>
|
||||
*/
|
||||
public final List<Entry<T, Integer>> getOrderedList() {
|
||||
if (!isListInSync) {
|
||||
rebuildOrderedList();
|
||||
if (!this.isListInSync()) {
|
||||
this.rebuildOrderedList();
|
||||
}
|
||||
return cardsListOrdered;
|
||||
return this.cardsListOrdered;
|
||||
}
|
||||
|
||||
private void rebuildOrderedList() {
|
||||
cardsListOrdered.clear();
|
||||
if (cards != null) {
|
||||
for (Entry<T, Integer> e : cards.entrySet()) {
|
||||
cardsListOrdered.add(e);
|
||||
this.cardsListOrdered.clear();
|
||||
if (this.getCards() != null) {
|
||||
for (final Entry<T, Integer> e : this.getCards().entrySet()) {
|
||||
this.cardsListOrdered.add(e);
|
||||
}
|
||||
}
|
||||
isListInSync = true;
|
||||
this.setListInSync(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,8 +208,8 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* @return List<T>
|
||||
*/
|
||||
public final List<T> toFlatList() {
|
||||
List<T> result = new ArrayList<T>();
|
||||
for (Entry<T, Integer> e : this) {
|
||||
final List<T> result = new ArrayList<T>();
|
||||
for (final Entry<T, Integer> e : this) {
|
||||
for (int i = 0; i < e.getValue(); i++) {
|
||||
result.add(e.getKey());
|
||||
}
|
||||
@@ -223,8 +224,8 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
* @return CardList
|
||||
*/
|
||||
public final CardList toForgeCardList() {
|
||||
CardList result = new CardList();
|
||||
for (Entry<T, Integer> e : this) {
|
||||
final CardList result = new CardList();
|
||||
for (final Entry<T, Integer> 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<T extends InventoryItem> implements Iterable<Entry<T,
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cards
|
||||
*/
|
||||
public Map<T, Integer> getCards() {
|
||||
return cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cards the cards to set
|
||||
*/
|
||||
public void setCards(Map<T, Integer> cards) {
|
||||
this.cards = cards; // TODO: Add 0 to parameter's name.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the myClass
|
||||
*/
|
||||
public Class<T> 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<CardRules, Entry<T, Integer>> getFnToCard() {
|
||||
return fnToCard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fnToCardName
|
||||
*/
|
||||
public Lambda1<String, Entry<T, Integer>> getFnToCardName() {
|
||||
return fnToCardName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fnToCount
|
||||
*/
|
||||
public Lambda1<Integer, Entry<T, Integer>> getFnToCount() {
|
||||
return fnToCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fnToPrinted
|
||||
*/
|
||||
public Lambda1<T, Entry<T, Integer>> getFnToPrinted() {
|
||||
return fnToPrinted;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
/** Forge Card Game. */
|
||||
package forge.item;
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ public final class QuestData {
|
||||
setDifficulty(diff);
|
||||
|
||||
Predicate<CardPrinted> 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();
|
||||
|
||||
@@ -113,7 +113,7 @@ public final class QuestUtilCards {
|
||||
q.newCardList.add(card);
|
||||
}
|
||||
|
||||
private static final Predicate<CardPrinted> rarePredicate = CardPrinted.Predicates.Presets.isRareOrMythic;
|
||||
private static final Predicate<CardPrinted> 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<CardSet> 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);
|
||||
|
||||
@@ -427,7 +427,7 @@ public class QuestWinLoseHandler extends WinLoseModeHandler {
|
||||
GameFormat selected = ch.getSelectedValue();
|
||||
|
||||
List<CardPrinted> 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!");
|
||||
|
||||
Reference in New Issue
Block a user