mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18: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();
|
final Iterable<CardPrinted> cardpool = CardDb.instance().getAllUniqueCards();
|
||||||
|
|
||||||
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool,
|
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,
|
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;
|
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);
|
final boolean haveMythics = filterMythics.any(cardpool);
|
||||||
for (int iSlot = 0; haveMythics && (iSlot < numRare); iSlot++) {
|
for (int iSlot = 0; haveMythics && (iSlot < numRare); iSlot++) {
|
||||||
if (MyRandom.getRandom().nextInt(7) < 1) { // a bit higher chance to
|
if (MyRandom.getRandom().nextInt(7) < 1) { // a bit higher chance to
|
||||||
@@ -80,7 +80,7 @@ public final class BoosterUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool,
|
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) {
|
if (nMythics > 0) {
|
||||||
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, filterMythics, nMythics, colorFilters));
|
cards.addAll(BoosterUtils.generateDefinetlyColouredCards(cardpool, filterMythics, nMythics, colorFilters));
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ public final class BoosterUtils {
|
|||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
final Predicate<CardRules> color2 = allowedColors.get(iAttempt % size);
|
final Predicate<CardRules> color2 = allowedColors.get(iAttempt % size);
|
||||||
if (color2 != null) {
|
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;
|
Predicate<CardPrinted> rFilter;
|
||||||
switch (rarity) {
|
switch (rarity) {
|
||||||
case Rare:
|
case Rare:
|
||||||
rFilter = CardPrinted.Predicates.Presets.isRareOrMythic;
|
rFilter = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC;
|
||||||
break;
|
break;
|
||||||
case Common:
|
case Common:
|
||||||
rFilter = CardPrinted.Predicates.Presets.isCommon;
|
rFilter = CardPrinted.Predicates.Presets.IS_COMMON;
|
||||||
break;
|
break;
|
||||||
case Uncommon:
|
case Uncommon:
|
||||||
rFilter = CardPrinted.Predicates.Presets.isUncommon;
|
rFilter = CardPrinted.Predicates.Presets.IS_UNCOMMON;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rFilter = Predicate.getTrue(CardPrinted.class);
|
rFilter = Predicate.getTrue(CardPrinted.class);
|
||||||
@@ -240,7 +240,7 @@ public final class BoosterUtils {
|
|||||||
colorFilter = Predicate.getTrue(CardRules.class);
|
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
|
// 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) {
|
if (null == filter) {
|
||||||
return null;
|
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() {
|
private Predicate<CardPrinted> buildFilterPritned() {
|
||||||
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
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);
|
: CardPrinted.Predicates.printedInSets(this.allowedSetCodes, true);
|
||||||
return Predicate.and(banNames, allowSets);
|
return Predicate.and(banNames, allowSets);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate<CardPrinted> buildFilterRules() {
|
private Predicate<CardPrinted> buildFilterRules() {
|
||||||
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
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
|
||||||
: Predicate.brigde(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.fnGetRules);
|
: Predicate.brigde(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.FN_GET_RULES);
|
||||||
return Predicate.and(banNames, allowSets);
|
return Predicate.and(banNames, allowSets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ public final class DeckEditorCommon extends DeckEditorBase {
|
|||||||
protected Predicate<InventoryItem> buildFilter() {
|
protected Predicate<InventoryItem> buildFilter() {
|
||||||
final Predicate<CardPrinted> cardFilter = Predicate.and(
|
final Predicate<CardPrinted> cardFilter = Predicate.and(
|
||||||
Predicate.and(this.getFilterBoxes().buildFilter(), this.filterNameTypeSet.buildFilter()),
|
Predicate.and(this.getFilterBoxes().buildFilter(), this.filterNameTypeSet.buildFilter()),
|
||||||
CardPrinted.Predicates.Presets.nonAlternate);
|
CardPrinted.Predicates.Presets.NON_ALTERNATE);
|
||||||
return Predicate.instanceOf(cardFilter, CardPrinted.class);
|
return Predicate.instanceOf(cardFilter, CardPrinted.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -205,23 +205,23 @@ public class DeckEditorQuestMenu extends JMenuBar {
|
|||||||
// creatures
|
// creatures
|
||||||
|
|
||||||
sb.append(String.format("%d Creatures%n-------------%n",
|
sb.append(String.format("%d Creatures%n-------------%n",
|
||||||
CardRules.Predicates.Presets.IS_CREATURE.aggregate(all, all.fnToCard, all.fnToCount)));
|
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.fnToCard)) {
|
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()));
|
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// spells
|
// spells
|
||||||
sb.append(String.format("%d Spells%n----------%n",
|
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,
|
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()));
|
sb.append(String.format("%d x %s%n", e.getValue(), e.getKey().getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// lands
|
// lands
|
||||||
sb.append(String.format("%d Land%n--------%n",
|
sb.append(String.format("%d Land%n--------%n",
|
||||||
CardRules.Predicates.Presets.IS_LAND.aggregate(all, all.fnToCard, all.fnToCount)));
|
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.fnToCard)) {
|
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()));
|
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
|
final Predicate<CardRules> filterByType = types.size() == 7 ? CardRules.Predicates.Presets.CONSTANT_TRUE
|
||||||
: Predicate.or(types);
|
: 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())) {
|
if (StringUtils.isNotBlank(this.txtCardType.getText())) {
|
||||||
rules.add(Predicate.brigde(CardRules.Predicates.joinedType(StringOp.CONTAINS, 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())) {
|
if (StringUtils.isNotBlank(this.txtCardRules.getText())) {
|
||||||
rules.add(Predicate.brigde(CardRules.Predicates.rules(StringOp.CONTAINS, 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) {
|
if (this.searchSetCombo.getSelectedIndex() != 0) {
|
||||||
|
|||||||
@@ -171,8 +171,8 @@ public final class TableWithCards {
|
|||||||
*/
|
*/
|
||||||
public static String getStats(final ItemPoolView<InventoryItem> deck) {
|
public static String getStats(final ItemPoolView<InventoryItem> deck) {
|
||||||
final int total = deck.countAll();
|
final int total = deck.countAll();
|
||||||
final int creature = CardRules.Predicates.Presets.IS_CREATURE.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.fnToCard, deck.fnToCount);
|
final int land = CardRules.Predicates.Presets.IS_LAND.aggregate(deck, deck.getFnToCard(), deck.getFnToCount());
|
||||||
|
|
||||||
final StringBuffer show = new StringBuffer();
|
final StringBuffer show = new StringBuffer();
|
||||||
show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ")
|
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 String[] color = Constant.Color.ONLY_COLORS;
|
||||||
final List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.COLORS;
|
final List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.COLORS;
|
||||||
for (int i = 0; i < color.length; ++i) {
|
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();
|
return show.toString();
|
||||||
@@ -344,12 +344,12 @@ public final class TableWithCards {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (useFilter && this.wantUnique) {
|
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) {
|
} 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) {
|
} else if (this.wantUnique) {
|
||||||
this.model.addCards(CardRules.Predicates.Presets.CONSTANT_TRUE.uniqueByLast(this.pool,
|
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();
|
this.model.resort();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import forge.card.CardSet;
|
|||||||
public class BoosterPack implements InventoryItemFromSet {
|
public class BoosterPack implements InventoryItemFromSet {
|
||||||
|
|
||||||
/** The Constant fnFromSet. */
|
/** 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
|
@Override
|
||||||
public BoosterPack apply(final CardSet arg1) {
|
public BoosterPack apply(final CardSet arg1) {
|
||||||
return new BoosterPack(arg1);
|
return new BoosterPack(arg1);
|
||||||
@@ -30,8 +30,9 @@ public class BoosterPack implements InventoryItemFromSet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new booster pack.
|
* Instantiates a new booster pack.
|
||||||
*
|
*
|
||||||
* @param set the set
|
* @param set
|
||||||
|
* the set
|
||||||
*/
|
*/
|
||||||
public BoosterPack(final String set) {
|
public BoosterPack(final String set) {
|
||||||
this(SetUtils.getSetByCodeOrThrow(set));
|
this(SetUtils.getSetByCodeOrThrow(set));
|
||||||
@@ -39,103 +40,122 @@ public class BoosterPack implements InventoryItemFromSet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new booster pack.
|
* Instantiates a new booster pack.
|
||||||
*
|
*
|
||||||
* @param set the set
|
* @param set
|
||||||
|
* the set
|
||||||
*/
|
*/
|
||||||
public BoosterPack(final CardSet set) {
|
public BoosterPack(final CardSet set) {
|
||||||
cardSet = set;
|
this.cardSet = set;
|
||||||
name = cardSet.getName() + " Booster Pack";
|
this.name = this.cardSet.getName() + " Booster Pack";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see forge.item.InventoryItemFromSet#getSet()
|
* @see forge.item.InventoryItemFromSet#getSet()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Gets the sets the.
|
||||||
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final String getSet() {
|
public final String getSet() {
|
||||||
return cardSet.getCode();
|
return this.cardSet.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see forge.item.InventoryItemFromSet#getName()
|
* @see forge.item.InventoryItemFromSet#getName()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Gets the name.
|
||||||
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final String getName() {
|
public final String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see forge.item.InventoryItemFromSet#getImageFilename()
|
* @see forge.item.InventoryItemFromSet#getImageFilename()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Gets the image filename.
|
||||||
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final String getImageFilename() {
|
public final String getImageFilename() {
|
||||||
return "booster/" + cardSet.getCode() + ".png";
|
return "booster/" + this.cardSet.getCode() + ".png";
|
||||||
}
|
}
|
||||||
|
|
||||||
private CardPrinted getRandomBasicLand(final CardSet set) {
|
private CardPrinted getRandomBasicLand(final CardSet set) {
|
||||||
return Predicate.and(CardPrinted.Predicates.printedInSets(set.getCode()),
|
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());
|
CardDb.instance().getAllCards());
|
||||||
}
|
}
|
||||||
|
|
||||||
private CardPrinted getLandFromNearestSet() {
|
private CardPrinted getLandFromNearestSet() {
|
||||||
List<CardSet> sets = SetUtils.getAllSets();
|
final List<CardSet> sets = SetUtils.getAllSets();
|
||||||
int iThisSet = sets.indexOf(cardSet);
|
final int iThisSet = sets.indexOf(this.cardSet);
|
||||||
for (int iSet = iThisSet; iSet < sets.size(); iSet++) {
|
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) {
|
if (null != land) {
|
||||||
return land;
|
return land;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if not found (though that's impossible)
|
// if not found (though that's impossible)
|
||||||
return getRandomBasicLand(SetUtils.getSetByCode("M12"));
|
return this.getRandomBasicLand(SetUtils.getSetByCode("M12"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generate() {
|
private void generate() {
|
||||||
BoosterGenerator gen = new BoosterGenerator(cardSet);
|
final BoosterGenerator gen = new BoosterGenerator(this.cardSet);
|
||||||
cards = gen.getBoosterPack();
|
this.cards = gen.getBoosterPack();
|
||||||
|
|
||||||
int cntLands = cardSet.getBoosterData().getLand();
|
final int cntLands = this.cardSet.getBoosterData().getLand();
|
||||||
if (cntLands > 0) {
|
if (cntLands > 0) {
|
||||||
cards.add(getLandFromNearestSet());
|
this.cards.add(this.getLandFromNearestSet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the cards.
|
* Gets the cards.
|
||||||
*
|
*
|
||||||
* @return the cards
|
* @return the cards
|
||||||
*/
|
*/
|
||||||
public final List<CardPrinted> getCards() {
|
public final List<CardPrinted> getCards() {
|
||||||
if (null == cards) {
|
if (null == this.cards) {
|
||||||
generate();
|
this.generate();
|
||||||
}
|
}
|
||||||
return cards;
|
return this.cards;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#hashCode()
|
* @see java.lang.Object#hashCode()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Hash code.
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final int hashCode() {
|
public final int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((cardSet == null) ? 0 : cardSet.hashCode());
|
result = (prime * result) + ((this.cardSet == null) ? 0 : this.cardSet.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -146,24 +166,28 @@ public class BoosterPack implements InventoryItemFromSet {
|
|||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (this.getClass() != obj.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BoosterPack other = (BoosterPack) obj;
|
final BoosterPack other = (BoosterPack) obj;
|
||||||
if (cardSet == null) {
|
if (this.cardSet == null) {
|
||||||
if (other.cardSet != null) {
|
if (other.cardSet != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!cardSet.equals(other.cardSet)) {
|
} else if (!this.cardSet.equals(other.cardSet)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see forge.item.InventoryItem#getType()
|
* @see forge.item.InventoryItem#getType()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Gets the type.
|
||||||
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -171,16 +195,20 @@ public class BoosterPack implements InventoryItemFromSet {
|
|||||||
return "Booster Pack";
|
return "Booster Pack";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#clone()
|
* @see java.lang.Object#clone()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Clone.
|
||||||
|
*
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final Object clone() {
|
public final Object clone() {
|
||||||
return new BoosterPack(cardSet); // it's ok to share a reference to
|
return new BoosterPack(this.cardSet); // it's ok to share a reference to
|
||||||
// cardSet which is static anyway
|
// cardSet which is static anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,30 +31,32 @@ public final class CardDb {
|
|||||||
// makes this working
|
// makes this working
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance.
|
* Instance.
|
||||||
*
|
*
|
||||||
* @return the card db
|
* @return the card db
|
||||||
*/
|
*/
|
||||||
public static CardDb instance() {
|
public static CardDb instance() {
|
||||||
if (onlyInstance == null) {
|
if (CardDb.onlyInstance == null) {
|
||||||
throw new NullPointerException("CardDb has not yet been initialized, run setup() first");
|
throw new NullPointerException("CardDb has not yet been initialized, run setup() first");
|
||||||
}
|
}
|
||||||
return onlyInstance;
|
return CardDb.onlyInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the up.
|
* Sets the up.
|
||||||
*
|
*
|
||||||
* @param list the new up
|
* @param list
|
||||||
|
* the new up
|
||||||
*/
|
*/
|
||||||
public static void setup(final Iterator<CardRules> list) {
|
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");
|
throw new RuntimeException("CardDb has already been initialized, don't do it twice please");
|
||||||
}
|
}
|
||||||
synchronized (CardDb.class) {
|
synchronized (CardDb.class) {
|
||||||
if (onlyInstance == null) { // It's broken under 1.4 and below, on
|
if (CardDb.onlyInstance == null) { // It's broken under 1.4 and
|
||||||
// 1.5+ works again!
|
// below, on
|
||||||
onlyInstance = new CardDb(list);
|
// 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>();
|
private final Map<String, CardPrinted> uniqueCards = new Hashtable<String, CardPrinted>();
|
||||||
|
|
||||||
// need this to obtain cardReference by name+set+artindex
|
// need this to obtain cardReference by name+set+artindex
|
||||||
private final Map<String, Map<String, CardPrinted[]>> allCardsBySet =
|
private final Map<String, Map<String, CardPrinted[]>> allCardsBySet = new Hashtable<String, Map<String, CardPrinted[]>>();
|
||||||
new Hashtable<String, Map<String, CardPrinted[]>>();
|
|
||||||
// this is the same list in flat storage
|
// this is the same list in flat storage
|
||||||
private final List<CardPrinted> allCardsFlat = new ArrayList<CardPrinted>();
|
private final List<CardPrinted> allCardsFlat = new ArrayList<CardPrinted>();
|
||||||
|
|
||||||
// Lambda to get rules for selects from list of printed cards
|
// Lambda to get rules for selects from list of printed cards
|
||||||
/** The Constant fnGetCardPrintedByForgeCard. */
|
/** The Constant fnGetCardPrintedByForgeCard. */
|
||||||
public static final Lambda1<CardPrinted, Card> fnGetCardPrintedByForgeCard =
|
public static final Lambda1<CardPrinted, Card> FN_GET_CARD_PRINTED_BY_FORGE_CARD = new Lambda1<CardPrinted, Card>() {
|
||||||
new Lambda1<CardPrinted, Card>() {
|
|
||||||
@Override
|
@Override
|
||||||
public CardPrinted apply(final Card from) {
|
public CardPrinted apply(final Card from) {
|
||||||
return CardDb.instance().getCard(from.getName());
|
return CardDb.instance().getCard(from.getName());
|
||||||
@@ -88,22 +88,23 @@ public final class CardDb {
|
|||||||
|
|
||||||
private CardDb(final Iterator<CardRules> parser) {
|
private CardDb(final Iterator<CardRules> parser) {
|
||||||
while (parser.hasNext()) {
|
while (parser.hasNext()) {
|
||||||
addNewCard(parser.next());
|
this.addNewCard(parser.next());
|
||||||
}
|
}
|
||||||
// TODO consider using Collections.unmodifiableList wherever possible
|
// TODO consider using Collections.unmodifiableList wherever possible
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the new card.
|
* Adds the new card.
|
||||||
*
|
*
|
||||||
* @param card the card
|
* @param card
|
||||||
|
* the card
|
||||||
*/
|
*/
|
||||||
public void addNewCard(final CardRules card) {
|
public void addNewCard(final CardRules card) {
|
||||||
if (null == card) {
|
if (null == card) {
|
||||||
return;
|
return;
|
||||||
} // consider that a success
|
} // consider that a success
|
||||||
// System.out.println(card.getName());
|
// System.out.println(card.getName());
|
||||||
String cardName = card.getName().toLowerCase();
|
final String cardName = card.getName().toLowerCase();
|
||||||
|
|
||||||
// 1. register among oracle uniques
|
// 1. register among oracle uniques
|
||||||
// cards.put(cardName, card);
|
// 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 &
|
// 2. Save refs into two lists: one flat and other keyed with sets &
|
||||||
// name
|
// name
|
||||||
CardPrinted lastAdded = null;
|
CardPrinted lastAdded = null;
|
||||||
for (Entry<String, CardInSet> s : card.getSetsPrinted()) {
|
for (final Entry<String, CardInSet> s : card.getSetsPrinted()) {
|
||||||
lastAdded = addToLists(card, cardName, s);
|
lastAdded = this.addToLists(card, cardName, s);
|
||||||
}
|
}
|
||||||
uniqueCards.put(cardName, lastAdded);
|
this.uniqueCards.put(cardName, lastAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the to lists.
|
* Adds the to lists.
|
||||||
*
|
*
|
||||||
* @param card the card
|
* @param card
|
||||||
* @param cardName the card name
|
* the card
|
||||||
* @param s the s
|
* @param cardName
|
||||||
|
* the card name
|
||||||
|
* @param s
|
||||||
|
* the s
|
||||||
* @return the card printed
|
* @return the card printed
|
||||||
*/
|
*/
|
||||||
public CardPrinted addToLists(final CardRules card, final String cardName, final Entry<String, CardInSet> s) {
|
public CardPrinted addToLists(final CardRules card, final String cardName, final Entry<String, CardInSet> s) {
|
||||||
CardPrinted lastAdded = null;
|
CardPrinted lastAdded = null;
|
||||||
String set = s.getKey();
|
final String set = s.getKey();
|
||||||
|
|
||||||
// get this set storage, if not found, create it!
|
// 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) {
|
if (null == setMap) {
|
||||||
setMap = new Hashtable<String, CardPrinted[]>();
|
setMap = new Hashtable<String, CardPrinted[]>();
|
||||||
allCardsBySet.put(set, setMap);
|
this.allCardsBySet.put(set, setMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = s.getValue().getCopiesCount();
|
final int count = s.getValue().getCopiesCount();
|
||||||
CardPrinted[] cardCopies = new CardPrinted[count];
|
final CardPrinted[] cardCopies = new CardPrinted[count];
|
||||||
setMap.put(cardName, cardCopies);
|
setMap.put(cardName, cardCopies);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
lastAdded = CardPrinted.build(card, set, s.getValue().getRarity(), i, card.isAltState(),
|
lastAdded = CardPrinted.build(card, set, s.getValue().getRarity(), i, card.isAltState(),
|
||||||
card.isDoubleFaced());
|
card.isDoubleFaced());
|
||||||
allCardsFlat.add(lastAdded);
|
this.allCardsFlat.add(lastAdded);
|
||||||
cardCopies[i] = lastAdded;
|
cardCopies[i] = lastAdded;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,23 +155,24 @@ public final class CardDb {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is card supported.
|
* Checks if is card supported.
|
||||||
*
|
*
|
||||||
* @param cardName the card name
|
* @param cardName
|
||||||
|
* the card name
|
||||||
* @return true, if is card supported
|
* @return true, if is card supported
|
||||||
*/
|
*/
|
||||||
public boolean isCardSupported(final String cardName) {
|
public boolean isCardSupported(final String cardName) {
|
||||||
ImmutablePair<String, String> nameWithSet = splitCardName(cardName);
|
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(cardName);
|
||||||
if (nameWithSet.right == null) {
|
if (nameWithSet.right == null) {
|
||||||
return uniqueCards.containsKey(nameWithSet.left.toLowerCase());
|
return this.uniqueCards.containsKey(nameWithSet.left.toLowerCase());
|
||||||
}
|
}
|
||||||
// Set exists?
|
// 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) {
|
if (cardsFromset == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Card exists?
|
// Card exists?
|
||||||
CardPrinted[] cardCopies = cardsFromset.get(nameWithSet.left.toLowerCase());
|
final CardPrinted[] cardCopies = cardsFromset.get(nameWithSet.left.toLowerCase());
|
||||||
return cardCopies != null && cardCopies.length > 0;
|
return (cardCopies != null) && (cardCopies.length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,10 +180,10 @@ public final class CardDb {
|
|||||||
*/
|
*/
|
||||||
private static ImmutablePair<String, String> splitCardName(final String name) {
|
private static ImmutablePair<String, String> splitCardName(final String name) {
|
||||||
String cardName = name; // .trim() ?
|
String cardName = name; // .trim() ?
|
||||||
int pipePos = cardName.indexOf('|');
|
final int pipePos = cardName.indexOf('|');
|
||||||
|
|
||||||
if (pipePos >= 0) {
|
if (pipePos >= 0) {
|
||||||
String setName = cardName.substring(pipePos + 1).trim();
|
final String setName = cardName.substring(pipePos + 1).trim();
|
||||||
cardName = cardName.substring(0, pipePos);
|
cardName = cardName.substring(0, pipePos);
|
||||||
// only if set is not blank try to load it
|
// only if set is not blank try to load it
|
||||||
if (StringUtils.isNotBlank(setName) && !"???".equals(setName)) {
|
if (StringUtils.isNotBlank(setName) && !"???".equals(setName)) {
|
||||||
@@ -191,19 +196,20 @@ public final class CardDb {
|
|||||||
// Single fetch
|
// Single fetch
|
||||||
/**
|
/**
|
||||||
* Gets the card.
|
* Gets the card.
|
||||||
*
|
*
|
||||||
* @param name the name
|
* @param name
|
||||||
|
* the name
|
||||||
* @return the card
|
* @return the card
|
||||||
*/
|
*/
|
||||||
public CardPrinted getCard(final String name) {
|
public CardPrinted getCard(final String name) {
|
||||||
// Sometimes they read from decks things like "CardName|Set" - but we
|
// Sometimes they read from decks things like "CardName|Set" - but we
|
||||||
// can handle it
|
// can handle it
|
||||||
ImmutablePair<String, String> nameWithSet = splitCardName(name);
|
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(name);
|
||||||
if (nameWithSet.right != null) {
|
if (nameWithSet.right != null) {
|
||||||
return getCard(nameWithSet.left, nameWithSet.right);
|
return this.getCard(nameWithSet.left, nameWithSet.right);
|
||||||
}
|
}
|
||||||
// OK, plain name here
|
// OK, plain name here
|
||||||
CardPrinted card = uniqueCards.get(nameWithSet.left.toLowerCase());
|
final CardPrinted card = this.uniqueCards.get(nameWithSet.left.toLowerCase());
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
@@ -213,41 +219,49 @@ public final class CardDb {
|
|||||||
// Advanced fetch by name+set
|
// Advanced fetch by name+set
|
||||||
/**
|
/**
|
||||||
* Gets the card.
|
* Gets the card.
|
||||||
*
|
*
|
||||||
* @param name the name
|
* @param name
|
||||||
* @param set the set
|
* the name
|
||||||
|
* @param set
|
||||||
|
* the set
|
||||||
* @return the card
|
* @return the card
|
||||||
*/
|
*/
|
||||||
public CardPrinted getCard(final String name, final String set) {
|
public CardPrinted getCard(final String name, final String set) {
|
||||||
return getCard(name, set, 0);
|
return this.getCard(name, set, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the card.
|
* Gets the card.
|
||||||
*
|
*
|
||||||
* @param name the name
|
* @param name
|
||||||
* @param set the set
|
* the name
|
||||||
* @param artIndex the art index
|
* @param set
|
||||||
|
* the set
|
||||||
|
* @param artIndex
|
||||||
|
* the art index
|
||||||
* @return the card
|
* @return the card
|
||||||
*/
|
*/
|
||||||
public CardPrinted getCard(final String name, final String set, final int artIndex) {
|
public CardPrinted getCard(final String name, final String set, final int artIndex) {
|
||||||
// 1. get set
|
// 1. get set
|
||||||
Map<String, CardPrinted[]> cardsFromset = allCardsBySet.get(set.toUpperCase());
|
final Map<String, CardPrinted[]> cardsFromset = this.allCardsBySet.get(set.toUpperCase());
|
||||||
if (null == cardsFromset) {
|
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);
|
throw new NoSuchElementException(err);
|
||||||
}
|
}
|
||||||
// 2. Find the card itself
|
// 2. Find the card itself
|
||||||
CardPrinted[] cardCopies = cardsFromset.get(name.toLowerCase());
|
final CardPrinted[] cardCopies = cardsFromset.get(name.toLowerCase());
|
||||||
if (null == cardCopies) {
|
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);
|
throw new NoSuchElementException(err);
|
||||||
}
|
}
|
||||||
// 3. Get the proper copy
|
// 3. Get the proper copy
|
||||||
if (artIndex >= 0 && artIndex <= cardCopies.length) {
|
if ((artIndex >= 0) && (artIndex <= cardCopies.length)) {
|
||||||
return cardCopies[artIndex];
|
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);
|
throw new NoSuchElementException(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,30 +269,32 @@ public final class CardDb {
|
|||||||
// we'll still check
|
// we'll still check
|
||||||
/**
|
/**
|
||||||
* Gets the card.
|
* Gets the card.
|
||||||
*
|
*
|
||||||
* @param forgeCard the forge card
|
* @param forgeCard
|
||||||
|
* the forge card
|
||||||
* @return the card
|
* @return the card
|
||||||
*/
|
*/
|
||||||
public CardPrinted getCard(final Card forgeCard) {
|
public CardPrinted getCard(final Card forgeCard) {
|
||||||
String name = forgeCard.getName();
|
final String name = forgeCard.getName();
|
||||||
String set = forgeCard.getCurSetCode();
|
final String set = forgeCard.getCurSetCode();
|
||||||
if (StringUtils.isNotBlank(set)) {
|
if (StringUtils.isNotBlank(set)) {
|
||||||
return getCard(name, set);
|
return this.getCard(name, set);
|
||||||
}
|
}
|
||||||
return getCard(name);
|
return this.getCard(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiple fetch
|
// Multiple fetch
|
||||||
/**
|
/**
|
||||||
* Gets the cards.
|
* Gets the cards.
|
||||||
*
|
*
|
||||||
* @param names the names
|
* @param names
|
||||||
|
* the names
|
||||||
* @return the cards
|
* @return the cards
|
||||||
*/
|
*/
|
||||||
public List<CardPrinted> getCards(final Iterable<String> names) {
|
public List<CardPrinted> getCards(final Iterable<String> names) {
|
||||||
List<CardPrinted> result = new ArrayList<CardPrinted>();
|
final List<CardPrinted> result = new ArrayList<CardPrinted>();
|
||||||
for (String name : names) {
|
for (final String name : names) {
|
||||||
result.add(getCard(name));
|
result.add(this.getCard(name));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -286,22 +302,22 @@ public final class CardDb {
|
|||||||
// returns a list of all cards from their respective latest editions
|
// returns a list of all cards from their respective latest editions
|
||||||
/**
|
/**
|
||||||
* Gets the all unique cards.
|
* Gets the all unique cards.
|
||||||
*
|
*
|
||||||
* @return the all unique cards
|
* @return the all unique cards
|
||||||
*/
|
*/
|
||||||
public Iterable<CardPrinted> getAllUniqueCards() {
|
public Iterable<CardPrinted> getAllUniqueCards() {
|
||||||
return uniqueCards.values();
|
return this.uniqueCards.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Iterable<CardRules> getAllCardRules() { return cards.values(); }
|
// public Iterable<CardRules> getAllCardRules() { return cards.values(); }
|
||||||
// // still not needed
|
// // still not needed
|
||||||
/**
|
/**
|
||||||
* Gets the all cards.
|
* Gets the all cards.
|
||||||
*
|
*
|
||||||
* @return the all cards
|
* @return the all cards
|
||||||
*/
|
*/
|
||||||
public Iterable<CardPrinted> getAllCards() {
|
public Iterable<CardPrinted> getAllCards() {
|
||||||
return allCardsFlat;
|
return this.allCardsFlat;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,88 +47,108 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
private transient String imageFilename = null;
|
private transient String imageFilename = null;
|
||||||
|
|
||||||
// field RO accessors
|
// field RO accessors
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see forge.item.InventoryItemFromSet#getName()
|
* @see forge.item.InventoryItemFromSet#getName()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Gets the name.
|
||||||
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see forge.item.InventoryItemFromSet#getSet()
|
* @see forge.item.InventoryItemFromSet#getSet()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Gets the sets the.
|
||||||
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getSet() {
|
public String getSet() {
|
||||||
return cardSet;
|
return this.cardSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the art index.
|
* Gets the art index.
|
||||||
*
|
*
|
||||||
* @return the art index
|
* @return the art index
|
||||||
*/
|
*/
|
||||||
public int getArtIndex() {
|
public int getArtIndex() {
|
||||||
return artIndex;
|
return this.artIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is foil.
|
* Checks if is foil.
|
||||||
*
|
*
|
||||||
* @return true, if is foil
|
* @return true, if is foil
|
||||||
*/
|
*/
|
||||||
public boolean isFoil() {
|
public boolean isFoil() {
|
||||||
return foiled;
|
return this.foiled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the card.
|
* Gets the card.
|
||||||
*
|
*
|
||||||
* @return the card
|
* @return the card
|
||||||
*/
|
*/
|
||||||
public CardRules getCard() {
|
public CardRules getCard() {
|
||||||
return card;
|
return this.card;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the rarity.
|
* Gets the rarity.
|
||||||
*
|
*
|
||||||
* @return the rarity
|
* @return the rarity
|
||||||
*/
|
*/
|
||||||
public CardRarity getRarity() {
|
public CardRarity getRarity() {
|
||||||
return rarity;
|
return this.rarity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see forge.item.InventoryItemFromSet#getImageFilename()
|
* @see forge.item.InventoryItemFromSet#getImageFilename()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Gets the image filename.
|
||||||
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getImageFilename() {
|
public String getImageFilename() {
|
||||||
if (imageFilename == null) {
|
if (this.imageFilename == null) {
|
||||||
imageFilename = CardUtil.buildFilename(this);
|
this.imageFilename = CardUtil.buildFilename(this);
|
||||||
}
|
}
|
||||||
return imageFilename;
|
return this.imageFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see forge.item.InventoryItem#getType()
|
* @see forge.item.InventoryItem#getType()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
* Gets the type.
|
||||||
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return card.getType().toString();
|
return this.card.getType().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lambda to get rules for selects from list of printed cards
|
// Lambda to get rules for selects from list of printed cards
|
||||||
/** The Constant fnGetRules. */
|
/** 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
|
@Override
|
||||||
public CardRules apply(final CardPrinted from) {
|
public CardRules apply(final CardPrinted from) {
|
||||||
return from.card;
|
return from.card;
|
||||||
@@ -137,42 +157,47 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
// Constructor is private. All non-foiled instances are stored in CardDb
|
// 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,
|
private CardPrinted(final CardRules c, final String set, final CardRarity rare, final int index,
|
||||||
final boolean foil, final boolean isAlt, final boolean isDF)
|
final boolean foil, final boolean isAlt, final boolean isDF) {
|
||||||
{
|
this.card = c;
|
||||||
card = c;
|
this.name = c.getName();
|
||||||
name = c.getName();
|
this.cardSet = set;
|
||||||
cardSet = set;
|
this.artIndex = index;
|
||||||
artIndex = index;
|
this.foiled = foil;
|
||||||
foiled = foil;
|
this.rarity = rare;
|
||||||
rarity = rare;
|
this.isAlternate = isAlt;
|
||||||
isAlternate = isAlt;
|
this.isDoubleFaced = isDF;
|
||||||
isDoubleFaced = isDF;
|
this.nameLcase = this.name.toLowerCase();
|
||||||
nameLcase = name.toLowerCase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package visibility */
|
/* package visibility */
|
||||||
/**
|
/**
|
||||||
* Builds the.
|
* Builds the.
|
||||||
*
|
*
|
||||||
* @param c the c
|
* @param c
|
||||||
* @param set the set
|
* the c
|
||||||
* @param rare the rare
|
* @param set
|
||||||
* @param index the index
|
* the set
|
||||||
* @param isAlt the is alt
|
* @param rare
|
||||||
* @param isDF the is df
|
* the rare
|
||||||
|
* @param index
|
||||||
|
* the index
|
||||||
|
* @param isAlt
|
||||||
|
* the is alt
|
||||||
|
* @param isDF
|
||||||
|
* the is df
|
||||||
* @return the card printed
|
* @return the card printed
|
||||||
*/
|
*/
|
||||||
static CardPrinted build(final CardRules c, final String set, final CardRarity rare, final int index,
|
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);
|
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 */
|
/* foiled don't need to stay in CardDb's structures, so u'r free to create */
|
||||||
/**
|
/**
|
||||||
* Make foiled.
|
* Make foiled.
|
||||||
*
|
*
|
||||||
* @param c the c
|
* @param c
|
||||||
|
* the c
|
||||||
* @return the card printed
|
* @return the card printed
|
||||||
*/
|
*/
|
||||||
public static CardPrinted makeFoiled(final CardPrinted c) {
|
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
|
// Want this class to be a key for HashTable
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#equals(java.lang.Object)
|
* @see java.lang.Object#equals(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -191,57 +218,61 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (this.getClass() != obj.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardPrinted other = (CardPrinted) obj;
|
final CardPrinted other = (CardPrinted) obj;
|
||||||
if (!name.equals(other.name)) {
|
if (!this.name.equals(other.name)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cardSet.equals(other.cardSet)) {
|
if (!this.cardSet.equals(other.cardSet)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (other.foiled != this.foiled || other.artIndex != this.artIndex) {
|
if ((other.foiled != this.foiled) || (other.artIndex != this.artIndex)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#hashCode()
|
* @see java.lang.Object#hashCode()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int code = nameLcase.hashCode() * 11 + cardSet.hashCode() * 59 + artIndex * 2;
|
final int code = (this.nameLcase.hashCode() * 11) + (this.cardSet.hashCode() * 59) + (this.artIndex * 2);
|
||||||
if (foiled) {
|
if (this.foiled) {
|
||||||
return code + 1;
|
return code + 1;
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return this.name;
|
||||||
// cannot still decide, if this "name|set" format is needed anymore
|
// 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.
|
* To forge card.
|
||||||
*
|
*
|
||||||
* @return the card
|
* @return the card
|
||||||
*/
|
*/
|
||||||
public Card toForgeCard() {
|
public Card toForgeCard() {
|
||||||
Card c = AllZone.getCardFactory().getCard(name, null);
|
final Card c = AllZone.getCardFactory().getCard(this.name, null);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
c.setCurSetCode(getSet());
|
c.setCurSetCode(this.getSet());
|
||||||
c.setRandomPicture(artIndex + 1);
|
c.setRandomPicture(this.artIndex + 1);
|
||||||
c.setImageFilename(getImageFilename());
|
c.setImageFilename(this.getImageFilename());
|
||||||
if (c.hasAlternateState()) {
|
if (c.hasAlternateState()) {
|
||||||
c.changeState();
|
c.changeState();
|
||||||
c.setImageFilename(CardUtil.buildFilename(c));
|
c.setImageFilename(CardUtil.buildFilename(c));
|
||||||
@@ -252,35 +283,37 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(final CardPrinted o) {
|
public int compareTo(final CardPrinted o) {
|
||||||
int nameCmp = nameLcase.compareTo(o.nameLcase);
|
final int nameCmp = this.nameLcase.compareTo(o.nameLcase);
|
||||||
if (0 != nameCmp) {
|
if (0 != nameCmp) {
|
||||||
return nameCmp;
|
return nameCmp;
|
||||||
}
|
}
|
||||||
// TODO compare sets properly
|
// TODO compare sets properly
|
||||||
return cardSet.compareTo(o.cardSet);
|
return this.cardSet.compareTo(o.cardSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is alternate.
|
* Checks if is alternate.
|
||||||
*
|
*
|
||||||
* @return true, if is alternate
|
* @return true, if is alternate
|
||||||
*/
|
*/
|
||||||
public boolean isAlternate() {
|
public boolean isAlternate() {
|
||||||
return isAlternate;
|
return this.isAlternate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is double faced.
|
* Checks if is double faced.
|
||||||
*
|
*
|
||||||
* @return true, if is double faced
|
* @return true, if is double faced
|
||||||
*/
|
*/
|
||||||
public boolean isDoubleFaced() {
|
public boolean isDoubleFaced() {
|
||||||
return isDoubleFaced;
|
return this.isDoubleFaced;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -290,9 +323,11 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Rarity.
|
* Rarity.
|
||||||
*
|
*
|
||||||
* @param isEqual the is equal
|
* @param isEqual
|
||||||
* @param value the value
|
* the is equal
|
||||||
|
* @param value
|
||||||
|
* the value
|
||||||
* @return the predicate
|
* @return the predicate
|
||||||
*/
|
*/
|
||||||
public static Predicate<CardPrinted> rarity(final boolean isEqual, final CardRarity value) {
|
public static Predicate<CardPrinted> rarity(final boolean isEqual, final CardRarity value) {
|
||||||
@@ -301,13 +336,15 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Printed in sets.
|
* Printed in sets.
|
||||||
*
|
*
|
||||||
* @param value the value
|
* @param value
|
||||||
* @param shouldContain the should contain
|
* the value
|
||||||
|
* @param shouldContain
|
||||||
|
* the should contain
|
||||||
* @return the predicate
|
* @return the predicate
|
||||||
*/
|
*/
|
||||||
public static Predicate<CardPrinted> printedInSets(final List<String> value, final boolean shouldContain) {
|
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 Predicate.getTrue(CardPrinted.class);
|
||||||
}
|
}
|
||||||
return new PredicateSets(value, shouldContain);
|
return new PredicateSets(value, shouldContain);
|
||||||
@@ -315,21 +352,23 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Printed in sets.
|
* Printed in sets.
|
||||||
*
|
*
|
||||||
* @param value the value
|
* @param value
|
||||||
|
* the value
|
||||||
* @return the predicate
|
* @return the predicate
|
||||||
*/
|
*/
|
||||||
public static Predicate<CardPrinted> printedInSets(final String value) {
|
public static Predicate<CardPrinted> printedInSets(final String value) {
|
||||||
if (value == null || value.isEmpty()) {
|
if ((value == null) || value.isEmpty()) {
|
||||||
return Predicate.getTrue(CardPrinted.class);
|
return Predicate.getTrue(CardPrinted.class);
|
||||||
}
|
}
|
||||||
return new PredicateSets(Arrays.asList(new String[] {value}), true);
|
return new PredicateSets(Arrays.asList(new String[] { value }), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name.
|
* Name.
|
||||||
*
|
*
|
||||||
* @param what the what
|
* @param what
|
||||||
|
* the what
|
||||||
* @return the predicate
|
* @return the predicate
|
||||||
*/
|
*/
|
||||||
public static Predicate<CardPrinted> name(final String what) {
|
public static Predicate<CardPrinted> name(final String what) {
|
||||||
@@ -338,9 +377,11 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Name.
|
* Name.
|
||||||
*
|
*
|
||||||
* @param op the op
|
* @param op
|
||||||
* @param what the what
|
* the op
|
||||||
|
* @param what
|
||||||
|
* the what
|
||||||
* @return the predicate
|
* @return the predicate
|
||||||
*/
|
*/
|
||||||
public static Predicate<CardPrinted> name(final PredicateString.StringOp op, final String what) {
|
public static Predicate<CardPrinted> name(final PredicateString.StringOp op, final String what) {
|
||||||
@@ -349,8 +390,9 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Names except.
|
* Names except.
|
||||||
*
|
*
|
||||||
* @param what the what
|
* @param what
|
||||||
|
* the what
|
||||||
* @return the predicate
|
* @return the predicate
|
||||||
*/
|
*/
|
||||||
public static Predicate<CardPrinted> namesExcept(final List<String> what) {
|
public static Predicate<CardPrinted> namesExcept(final List<String> what) {
|
||||||
@@ -370,12 +412,12 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTrue(final CardPrinted card) {
|
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) {
|
public PredicateRarity(final CardRarity type, final boolean wantEqual) {
|
||||||
operand = type;
|
this.operand = type;
|
||||||
shouldBeEqual = wantEqual;
|
this.shouldBeEqual = wantEqual;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,12 +427,12 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTrue(final CardPrinted card) {
|
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) {
|
public PredicateSets(final List<String> wantSets, final boolean shouldContain) {
|
||||||
sets = wantSets; // maybe should make a copy here?
|
this.sets = wantSets; // maybe should make a copy here?
|
||||||
mustContain = shouldContain;
|
this.mustContain = shouldContain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +441,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTrue(final CardPrinted card) {
|
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) {
|
public PredicateName(final PredicateString.StringOp operator, final String operand) {
|
||||||
@@ -413,9 +455,9 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTrue(final CardPrinted card) {
|
public boolean isTrue(final CardPrinted card) {
|
||||||
String cardName = card.getName();
|
final String cardName = card.getName();
|
||||||
for (int i = 0; i < operand.length; i++) {
|
for (final String element : this.operand) {
|
||||||
if (op(cardName, operand[i])) {
|
if (this.op(cardName, element)) {
|
||||||
return false;
|
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
|
// Think twice before using these, since rarity is a prop of printed
|
||||||
// card.
|
// card.
|
||||||
/** The Constant isCommon. */
|
/** 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. */
|
/** 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. */
|
/** 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. */
|
/** 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. */
|
/** 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. */
|
/** 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. */
|
/** 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. */
|
/** 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. */
|
/** 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;
|
package forge.item;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* The Class CardPrintedCharacteristics.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class CardPrintedCharacteristics {
|
public class CardPrintedCharacteristics {
|
||||||
private String name;
|
private String name;
|
||||||
@@ -10,17 +9,18 @@ public class CardPrintedCharacteristics {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name.
|
* Gets the name.
|
||||||
*
|
*
|
||||||
* @return the name
|
* @return the name
|
||||||
*/
|
*/
|
||||||
public final String getName() {
|
public final String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the name.
|
* Sets the name.
|
||||||
*
|
*
|
||||||
* @param name0 the name to set
|
* @param name0
|
||||||
|
* the name to set
|
||||||
*/
|
*/
|
||||||
public final void setName(final String name0) {
|
public final void setName(final String name0) {
|
||||||
this.name = name0; // TODO Add 0 to parameter's name.
|
this.name = name0; // TODO Add 0 to parameter's name.
|
||||||
@@ -28,17 +28,18 @@ public class CardPrintedCharacteristics {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the card set.
|
* Gets the card set.
|
||||||
*
|
*
|
||||||
* @return the cardSet
|
* @return the cardSet
|
||||||
*/
|
*/
|
||||||
public final String getCardSet() {
|
public final String getCardSet() {
|
||||||
return cardSet;
|
return this.cardSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the card set.
|
* Sets the card set.
|
||||||
*
|
*
|
||||||
* @param cardSet0 the cardSet to set
|
* @param cardSet0
|
||||||
|
* the cardSet to set
|
||||||
*/
|
*/
|
||||||
public final void setCardSet(final String cardSet0) {
|
public final void setCardSet(final String cardSet0) {
|
||||||
this.cardSet = cardSet0; // TODO: Add 0 to parameter's name.
|
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
|
* Interface to define a player's inventory may hold. Should include
|
||||||
* CardPrinted, Booster, Pets, Plants... etc
|
* CardPrinted, Booster, Pets, Plants... etc
|
||||||
*/
|
*/
|
||||||
public interface InventoryItem /* extends Comparable */{
|
public interface InventoryItem {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An inventory item has to provide a name.
|
* An inventory item has to provide a name.
|
||||||
|
|||||||
@@ -8,21 +8,23 @@ public interface InventoryItemFromSet extends InventoryItem {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* An inventory item has to provide a name.
|
* An inventory item has to provide a name.
|
||||||
*
|
*
|
||||||
* @return the name
|
* @return the name
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An inventory item has to provide a picture.
|
* An inventory item has to provide a picture.
|
||||||
*
|
*
|
||||||
* @return the image filename
|
* @return the image filename
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
String getImageFilename();
|
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
|
* @return the sets the
|
||||||
*/
|
*/
|
||||||
String getSet();
|
String getSet();
|
||||||
|
|||||||
@@ -3,51 +3,65 @@ package forge.item;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>CardPool class.</p>
|
* <p>
|
||||||
|
* CardPool class.
|
||||||
|
* </p>
|
||||||
* Represents a list of cards with amount of each
|
* 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
|
// Constructors here
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* ItemPool Constructor.
|
* 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.
|
* 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) {
|
public ItemPool(final Iterable<String> names, final Class<T> cls) {
|
||||||
super(cls);
|
super(cls);
|
||||||
addAllCards((Iterable<T>) CardDb.instance().getCards(names));
|
this.addAllCards((Iterable<T>) CardDb.instance().getCards(names));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* createFrom method.
|
* createFrom method.
|
||||||
* @param from a Tin
|
*
|
||||||
* @param clsHint a Tout
|
* @param <Tin>
|
||||||
* @param <Tin> an InventoryItem
|
* an InventoryItem
|
||||||
* @param <Tout> an InventoryItem
|
* @param <Tout>
|
||||||
|
* an InventoryItem
|
||||||
|
* @param from
|
||||||
|
* a Tin
|
||||||
|
* @param clsHint
|
||||||
|
* a Tout
|
||||||
* @return InventoryItem
|
* @return InventoryItem
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
|
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(
|
||||||
createFrom(final ItemPoolView<Tin> from, final Class<Tout> clsHint)
|
final ItemPoolView<Tin> from, final Class<Tout> clsHint) {
|
||||||
{
|
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||||
ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
|
||||||
if (from != null) {
|
if (from != null) {
|
||||||
for (Entry<Tin, Integer> e : from) {
|
for (final Entry<Tin, Integer> e : from) {
|
||||||
Tin srcKey = e.getKey();
|
final Tin srcKey = e.getKey();
|
||||||
if (clsHint.isInstance(srcKey)) {
|
if (clsHint.isInstance(srcKey)) {
|
||||||
result.put((Tout) srcKey, e.getValue());
|
result.put((Tout) srcKey, e.getValue());
|
||||||
}
|
}
|
||||||
@@ -57,21 +71,24 @@ public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* createFrom method.
|
* 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
|
* @return <Tin> an InventoryItem
|
||||||
* @param <Tin> an InventoryItem
|
|
||||||
* @param <Tout> an InventoryItem
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
|
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(
|
||||||
createFrom(final Iterable<Tin> from, final Class<Tout> clsHint)
|
final Iterable<Tin> from, final Class<Tout> clsHint) {
|
||||||
{
|
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||||
ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
|
||||||
if (from != null) {
|
if (from != null) {
|
||||||
for (Tin srcKey : from) {
|
for (final Tin srcKey : from) {
|
||||||
if (clsHint.isInstance(srcKey)) {
|
if (clsHint.isInstance(srcKey)) {
|
||||||
result.put((Tout) srcKey, Integer.valueOf(1));
|
result.put((Tout) srcKey, Integer.valueOf(1));
|
||||||
}
|
}
|
||||||
@@ -84,99 +101,136 @@ public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Get item view.
|
* Get item view.
|
||||||
|
*
|
||||||
* @return a ItemPoolView
|
* @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
|
// Cards manipulation
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Add Card.
|
* Add Card.
|
||||||
* @param card a T
|
*
|
||||||
|
* @param card
|
||||||
|
* a T
|
||||||
*/
|
*/
|
||||||
public void add(final T card) {
|
public void add(final T card) {
|
||||||
add(card, 1);
|
this.add(card, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* add method.
|
* 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) {
|
public void add(final T card, final int amount) {
|
||||||
if (amount <= 0) { return; }
|
if (amount <= 0) {
|
||||||
cards.put(card, count(card) + amount);
|
return;
|
||||||
isListInSync = false;
|
}
|
||||||
|
this.getCards().put(card, this.count(card) + amount);
|
||||||
|
this.setListInSync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void put(final T card, final int amount) {
|
private void put(final T card, final int amount) {
|
||||||
cards.put(card, amount);
|
this.getCards().put(card, amount);
|
||||||
isListInSync = false;
|
this.setListInSync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* addAllCards.
|
* addAllCards.
|
||||||
* @param cards a Iterable<U>
|
*
|
||||||
* @param <U> a InventoryItem
|
* @param <U>
|
||||||
|
* a InventoryItem
|
||||||
|
* @param cards
|
||||||
|
* a Iterable<U>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <U extends InventoryItem> void addAllCards(final Iterable<U> cards) {
|
public <U extends InventoryItem> void addAllCards(final Iterable<U> cards) {
|
||||||
for (U cr : cards) { if (myClass.isInstance(cr)) { add((T) cr); } }
|
for (final U cr : cards) {
|
||||||
isListInSync = false;
|
if (this.getMyClass().isInstance(cr)) {
|
||||||
|
this.add((T) cr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setListInSync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* addAll.
|
* 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")
|
@SuppressWarnings("unchecked")
|
||||||
public <U extends InventoryItem> void addAll(final Iterable<Entry<U, Integer>> map) {
|
public <U extends InventoryItem> void addAll(final Iterable<Entry<U, Integer>> map) {
|
||||||
for (Entry<U, Integer> e : map) {
|
for (final Entry<U, Integer> e : map) {
|
||||||
if (myClass.isInstance(e.getKey())) {
|
if (this.getMyClass().isInstance(e.getKey())) {
|
||||||
add((T) e.getKey(), e.getValue());
|
this.add((T) e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isListInSync = false;
|
this.setListInSync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Remove.
|
* Remove.
|
||||||
* @param card a T
|
*
|
||||||
|
* @param card
|
||||||
|
* a T
|
||||||
*/
|
*/
|
||||||
public void remove(final T card) {
|
public void remove(final T card) {
|
||||||
remove(card, 1);
|
this.remove(card, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Remove.
|
* 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) {
|
public void remove(final T card, final int amount) {
|
||||||
int count = count(card);
|
final int count = this.count(card);
|
||||||
if (count == 0 || amount <= 0) { return; }
|
if ((count == 0) || (amount <= 0)) {
|
||||||
if (count <= amount) { cards.remove(card); }
|
return;
|
||||||
else { cards.put(card, count - amount); }
|
}
|
||||||
isListInSync = false;
|
if (count <= amount) {
|
||||||
|
this.getCards().remove(card);
|
||||||
|
} else {
|
||||||
|
this.getCards().put(card, count - amount);
|
||||||
|
}
|
||||||
|
this.setListInSync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* RemoveAll.
|
* RemoveAll.
|
||||||
* @param map a T
|
*
|
||||||
|
* @param map
|
||||||
|
* a T
|
||||||
*/
|
*/
|
||||||
public void removeAll(final Iterable<Entry<T, Integer>> map) {
|
public void removeAll(final Iterable<Entry<T, Integer>> map) {
|
||||||
for (Entry<T, Integer> e : map) { remove(e.getKey(), e.getValue()); }
|
for (final Entry<T, Integer> e : map) {
|
||||||
isListInSync = false;
|
this.remove(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
this.setListInSync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Clear.
|
* Clear.
|
||||||
*/
|
*/
|
||||||
public void clear() { cards.clear(); isListInSync = false; }
|
public void clear() {
|
||||||
|
this.getCards().clear();
|
||||||
|
this.setListInSync(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ import forge.card.CardRules;
|
|||||||
* <p>
|
* <p>
|
||||||
* CardPoolView class.
|
* CardPoolView class.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param <T> an InventoryItem
|
* @param <T>
|
||||||
|
* an InventoryItem
|
||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id: CardPoolView.java 9708 2011-08-09 19:34:12Z jendave $
|
* @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.
|
// Field Accessors for select/aggregate operations with filters.
|
||||||
/** The fn to card. */
|
/** 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
|
@Override
|
||||||
public CardRules apply(final Entry<T, Integer> from) {
|
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;
|
return item instanceof CardPrinted ? ((CardPrinted) item).getCard() : null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** The fn to printed. */
|
/** 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
|
@Override
|
||||||
public T apply(final Entry<T, Integer> from) {
|
public T apply(final Entry<T, Integer> from) {
|
||||||
return from.getKey();
|
return from.getKey();
|
||||||
@@ -41,7 +42,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** The fn to card name. */
|
/** 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
|
@Override
|
||||||
public String apply(final Entry<T, Integer> from) {
|
public String apply(final Entry<T, Integer> from) {
|
||||||
return from.getKey().getName();
|
return from.getKey().getName();
|
||||||
@@ -49,7 +50,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** The fn to count. */
|
/** 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
|
@Override
|
||||||
public Integer apply(final Entry<T, Integer> from) {
|
public Integer apply(final Entry<T, Integer> from) {
|
||||||
return from.getValue();
|
return from.getValue();
|
||||||
@@ -65,8 +66,8 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
* a Class<T>
|
* a Class<T>
|
||||||
*/
|
*/
|
||||||
public ItemPoolView(final Class<T> cls) {
|
public ItemPoolView(final Class<T> cls) {
|
||||||
cards = new Hashtable<T, Integer>();
|
this.setCards(new Hashtable<T, Integer>());
|
||||||
myClass = cls;
|
this.myClass = cls;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,25 +80,25 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
* a Class<T>
|
* a Class<T>
|
||||||
*/
|
*/
|
||||||
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) {
|
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) {
|
||||||
cards = inMap;
|
this.setCards(inMap);
|
||||||
myClass = cls;
|
this.myClass = cls;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data members
|
// Data members
|
||||||
/** The cards. */
|
/** The cards. */
|
||||||
protected Map<T, Integer> cards;
|
private Map<T, Integer> cards;
|
||||||
|
|
||||||
/** The my class. */
|
/** 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
|
// itself
|
||||||
|
|
||||||
// same thing as above, it was copied to provide sorting (needed by table
|
// same thing as above, it was copied to provide sorting (needed by table
|
||||||
// views in deck editors)
|
// views in deck editors)
|
||||||
/** The cards list ordered. */
|
/** 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. */
|
/** The is list in sync. */
|
||||||
protected boolean isListInSync = false;
|
private boolean isListInSync = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* iterator.
|
* iterator.
|
||||||
@@ -106,7 +107,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final Iterator<Entry<T, Integer>> iterator() {
|
public final Iterator<Entry<T, Integer>> iterator() {
|
||||||
return cards.entrySet().iterator();
|
return this.getCards().entrySet().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cards read only operations
|
// Cards read only operations
|
||||||
@@ -119,10 +120,10 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public final boolean contains(final T card) {
|
public final boolean contains(final T card) {
|
||||||
if (cards == null) {
|
if (this.getCards() == null) {
|
||||||
return false;
|
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
|
* @return int
|
||||||
*/
|
*/
|
||||||
public final int count(final T card) {
|
public final int count(final T card) {
|
||||||
if (cards == null) {
|
if (this.getCards() == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Integer boxed = cards.get(card);
|
final Integer boxed = this.getCards().get(card);
|
||||||
return boxed == null ? 0 : boxed.intValue();
|
return boxed == null ? 0 : boxed.intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,8 +150,8 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
*/
|
*/
|
||||||
public final int countAll() {
|
public final int countAll() {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (cards != null) {
|
if (this.getCards() != null) {
|
||||||
for (Integer n : cards.values()) {
|
for (final Integer n : this.getCards().values()) {
|
||||||
result += n;
|
result += n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +165,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public final int countDistinct() {
|
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
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public final boolean isEmpty() {
|
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>>
|
* @return List<Entry<T, Integer>>
|
||||||
*/
|
*/
|
||||||
public final List<Entry<T, Integer>> getOrderedList() {
|
public final List<Entry<T, Integer>> getOrderedList() {
|
||||||
if (!isListInSync) {
|
if (!this.isListInSync()) {
|
||||||
rebuildOrderedList();
|
this.rebuildOrderedList();
|
||||||
}
|
}
|
||||||
return cardsListOrdered;
|
return this.cardsListOrdered;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rebuildOrderedList() {
|
private void rebuildOrderedList() {
|
||||||
cardsListOrdered.clear();
|
this.cardsListOrdered.clear();
|
||||||
if (cards != null) {
|
if (this.getCards() != null) {
|
||||||
for (Entry<T, Integer> e : cards.entrySet()) {
|
for (final Entry<T, Integer> e : this.getCards().entrySet()) {
|
||||||
cardsListOrdered.add(e);
|
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>
|
* @return List<T>
|
||||||
*/
|
*/
|
||||||
public final List<T> toFlatList() {
|
public final List<T> toFlatList() {
|
||||||
List<T> result = new ArrayList<T>();
|
final List<T> result = new ArrayList<T>();
|
||||||
for (Entry<T, Integer> e : this) {
|
for (final Entry<T, Integer> e : this) {
|
||||||
for (int i = 0; i < e.getValue(); i++) {
|
for (int i = 0; i < e.getValue(); i++) {
|
||||||
result.add(e.getKey());
|
result.add(e.getKey());
|
||||||
}
|
}
|
||||||
@@ -223,8 +224,8 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
* @return CardList
|
* @return CardList
|
||||||
*/
|
*/
|
||||||
public final CardList toForgeCardList() {
|
public final CardList toForgeCardList() {
|
||||||
CardList result = new CardList();
|
final CardList result = new CardList();
|
||||||
for (Entry<T, Integer> e : this) {
|
for (final Entry<T, Integer> e : this) {
|
||||||
if (e.getKey() instanceof CardPrinted) {
|
if (e.getKey() instanceof CardPrinted) {
|
||||||
for (int i = 0; i < e.getValue(); i++) {
|
for (int i = 0; i < e.getValue(); i++) {
|
||||||
result.add(((CardPrinted) e.getKey()).toForgeCard());
|
result.add(((CardPrinted) e.getKey()).toForgeCard());
|
||||||
@@ -233,4 +234,67 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
}
|
}
|
||||||
return result;
|
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. */
|
/** Forge Card Game. */
|
||||||
package forge.item;
|
package forge.item;
|
||||||
|
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public final class QuestData {
|
|||||||
setDifficulty(diff);
|
setDifficulty(diff);
|
||||||
|
|
||||||
Predicate<CardPrinted> filter = Predicate.and(standardStart ? SetUtils.getStandard().getFilterPrinted()
|
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);
|
myCards.setupNewGameCardPool(filter, diff);
|
||||||
credits = QuestPreferences.getStartingCredits();
|
credits = QuestPreferences.getStartingCredits();
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public final class QuestUtilCards {
|
|||||||
q.newCardList.add(card);
|
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.
|
* Adds the random rare.
|
||||||
@@ -283,7 +283,7 @@ public final class QuestUtilCards {
|
|||||||
int rollD100 = MyRandom.getRandom().nextInt(100);
|
int rollD100 = MyRandom.getRandom().nextInt(100);
|
||||||
Predicate<CardSet> filter = rollD100 < 40 ? filterT2booster : (rollD100 < 75 ? filterExtButT2
|
Predicate<CardSet> filter = rollD100 < 40 ? filterT2booster : (rollD100 < 75 ? filterExtButT2
|
||||||
: filterNotExt);
|
: 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);
|
addBasicLands(q.shopList, 10, 5);
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ public class QuestWinLoseHandler extends WinLoseModeHandler {
|
|||||||
GameFormat selected = ch.getSelectedValue();
|
GameFormat selected = ch.getSelectedValue();
|
||||||
|
|
||||||
List<CardPrinted> cardsWon = model.qData.getCards().addCards(
|
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.
|
// Generate Swing components and attach.
|
||||||
lblTemp1 = new TitleLabel("Bonus booster pack from the \"" + selected.getName() + "\" format!");
|
lblTemp1 = new TitleLabel("Bonus booster pack from the \"" + selected.getName() + "\" format!");
|
||||||
|
|||||||
Reference in New Issue
Block a user