moved that infiniteStock field from ItemPool to more approriate place

This commit is contained in:
Maxmtg
2013-02-08 00:01:50 +00:00
parent 63edb1601f
commit 41b78e7313
11 changed files with 31 additions and 69 deletions

View File

@@ -252,7 +252,7 @@ public final class BoosterDraft implements IBoosterDraft {
}
this.computerChoose();
return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), CardPrinted.class, false);
return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), CardPrinted.class);
}
/**

View File

@@ -110,7 +110,7 @@ public class CustomLimited extends DeckBase {
final String deckName = data.get("DeckFile");
final Deck deckCube = cubes.get(deckName);
cd.cardPool = deckCube == null ? ItemPool.createFrom(
CardDb.instance().getAllUniqueCards(), CardPrinted.class, false)
CardDb.instance().getAllUniqueCards(), CardPrinted.class)
: deckCube.getMain();
return cd;

View File

@@ -131,7 +131,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
@Override
public void resetTables() {
// Constructed mode can use all cards, no limitations.
this.getTableCatalog().setDeck(ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), CardPrinted.class, true));
this.getTableCatalog().setDeck(ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), CardPrinted.class), true);
this.getTableDeck().setDeck(this.controller.getModel().getMain());
}
@@ -159,7 +159,7 @@ public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
} else {
lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY));
this.getTableCatalog().setAvailableColumns(lstCatalogCols);
this.getTableCatalog().setDeck(ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), CardPrinted.class, true));
this.getTableCatalog().setDeck(ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), CardPrinted.class), true);
this.getTableDeck().setDeck(this.controller.getModel().getMain());
}

View File

@@ -94,7 +94,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
private ItemPoolView<InventoryItem> cardsForSale;
private final ItemPool<InventoryItem> fullCatalogCards =
ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), InventoryItem.class, true);
ItemPool.createFrom(CardDb.instance().getAllTraditionalCards(), InventoryItem.class);
private boolean showingFullCatalog = false;
// get pricelist:
@@ -137,7 +137,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
showingFullCatalog = !showingFullCatalog;
if (showingFullCatalog) {
this.getTableCatalog().setDeck(fullCatalogCards);
this.getTableCatalog().setDeck(fullCatalogCards, true);
VCardCatalog.SINGLETON_INSTANCE.getBtnAdd().setEnabled(false);
VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove().setEnabled(false);
VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove4().setEnabled(false);
@@ -342,7 +342,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
final PreconDeck deck = (PreconDeck) item;
this.questData.getCards().buyPreconDeck(deck, value);
final ItemPool<InventoryItem> newInventory =
ItemPool.createFrom(deck.getDeck().getMain(), InventoryItem.class, false);
ItemPool.createFrom(deck.getDeck().getMain(), InventoryItem.class);
getTableDeck().addCards(newInventory);
JOptionPane.showMessageDialog(null, String.format(
"Deck '%s' was added to your decklist.%n%nCards from it were also added to your pool.",

View File

@@ -130,7 +130,7 @@ public final class CEditorVariant extends ACEditorBase<CardPrinted, Deck> {
Iterable<CardPrinted> allNT = CardDb.instance().getAllNonTraditionalCards();
allNT = Iterables.filter(allNT, cardPoolCondition);
this.getTableCatalog().setDeck(ItemPool.createFrom(allNT, CardPrinted.class, true));
this.getTableCatalog().setDeck(ItemPool.createFrom(allNT, CardPrinted.class), true);
this.getTableDeck().setDeck(this.controller.getModel().getSideboard());
}

View File

@@ -63,8 +63,7 @@ public enum CProbabilities implements ICDoc {
final ACEditorBase<T, TModel> ed = (ACEditorBase<T, TModel>)
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(
ed.getTableDeck().getCards(), CardPrinted.class, false);
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(ed.getTableDeck().getCards(), CardPrinted.class);
final List<String> cardProbabilities = new ArrayList<String>();

View File

@@ -73,8 +73,7 @@ public enum CStatistics implements ICDoc {
if (ed == null) { return; }
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(
ed.getTableDeck().getCards(), CardPrinted.class, false);
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(ed.getTableDeck().getCards(), CardPrinted.class);
int total = deck.countAll();

View File

@@ -67,6 +67,7 @@ public final class EditorTableView<T extends InventoryItem> {
private boolean alwaysNonUnique = false;
private final Class<T> genericType;
private boolean infiniteSupply;
/**
*
@@ -278,7 +279,8 @@ public final class EditorTableView<T extends InventoryItem> {
* an Iterable<InventoryITem>
*/
public void setDeck(final Iterable<InventoryItem> cards) {
this.setDeckImpl(ItemPool.createFrom(cards, this.genericType, false));
this.setDeckImpl(ItemPool.createFrom(cards, this.genericType));
this.infiniteSupply = false;
}
/**
@@ -287,10 +289,13 @@ public final class EditorTableView<T extends InventoryItem> {
* @param poolView
* an ItemPoolView
*/
public void setDeck(final ItemPoolView<T> poolView) {
this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType, false));
public void setDeck(final ItemPoolView<T> poolView, boolean infinite) {
this.setDeckImpl(ItemPool.createFrom(poolView, this.genericType));
this.infiniteSupply = infinite;
}
public void setDeck(final ItemPoolView<T> poolView) {
this.setDeck(poolView, false);
}
/**
* Sets the deck.
*
@@ -299,6 +304,7 @@ public final class EditorTableView<T extends InventoryItem> {
*/
public void setDeck(final ItemPool<T> pool) {
this.setDeckImpl(pool);
this.infiniteSupply = false;
}
/**
@@ -426,7 +432,7 @@ public final class EditorTableView<T extends InventoryItem> {
}
public int getCardCount(final T card) {
return this.pool.count(card);
return infiniteSupply ? Integer.MAX_VALUE : this.pool.count(card);
}
public Predicate<T> getFilter() {

View File

@@ -43,27 +43,10 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
super(cls);
}
public ItemPool(final Class<T> cls, boolean infiniteStock) {
super(cls, infiniteStock);
}
/**
* createFrom method.
*
* @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, boolean infiniteStock) {
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint, infiniteStock);
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 (final Entry<Tin, Integer> e : from) {
final Tin srcKey = e.getKey();
@@ -75,23 +58,10 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
return result;
}
/**
* createFrom method.
*
* @param <Tin>
* an InventoryItem
* @param <Tout>
* an InventoryItem
* @param from
* a Iterable<Tin>
* @param clsHint
* a Class<Tout>
* @return <Tin> an InventoryItem
*/
@SuppressWarnings("unchecked")
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(
final Iterable<Tin> from, final Class<Tout> clsHint, boolean infiniteStock) {
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint, infiniteStock);
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 (final Tin srcKey : from) {
if (clsHint.isInstance(srcKey)) {
@@ -138,7 +108,7 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
if (amount <= 0) {
return;
}
this.getCards().put(card, this.count(card) + amount);
this.getCards().put(card, Integer.valueOf(this.count(card) + amount));
this.setListInSync(false);
}

View File

@@ -77,27 +77,15 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
// Constructors
public ItemPoolView(final Class<T> cls) {
this(cls, false);
}
public ItemPoolView(final Class<T> cls, boolean infiniteStock) {
this(new Hashtable<T, Integer>(), cls, infiniteStock);
this(new Hashtable<T, Integer>(), cls);
}
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) {
this(inMap, cls, false);
}
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls, boolean infiniteStock) {
this.cards = inMap;
this.myClass = cls;
this.infiniteStock = infiniteStock;
}
// Data members
// if this is true, queries for card count will return INT_MAX
private final boolean infiniteStock;
/** The cards. */
private final Map<T, Integer> cards;
@@ -152,7 +140,7 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
return 0;
}
final Integer boxed = this.getCards().get(card);
return boxed == null ? 0 : (infiniteStock ? Integer.MAX_VALUE : boxed.intValue());
return boxed == null ? 0 : boxed.intValue();
}
/**

View File

@@ -51,7 +51,7 @@ public class BoosterDraftTest implements IBoosterDraft {
this.n--;
BoosterData booster = Singletons.getModel().getBoosters().get("M11");
final BoosterGenerator pack = new BoosterGenerator(booster.getEditionFilter());
return ItemPool.createFrom(pack.getBoosterPack(booster), CardPrinted.class, false);
return ItemPool.createFrom(pack.getBoosterPack(booster), CardPrinted.class);
}
/** {@inheritDoc} */