mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
remove ItemPoolView class, instead a read-only pool will be an instance of same class, but backed with an unmodifiable map
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -92,7 +92,6 @@ forge-core/src/main/java/forge/util/IItemReader.java -text
|
|||||||
forge-core/src/main/java/forge/util/IItemSerializer.java -text
|
forge-core/src/main/java/forge/util/IItemSerializer.java -text
|
||||||
forge-core/src/main/java/forge/util/ItemPool.java -text
|
forge-core/src/main/java/forge/util/ItemPool.java -text
|
||||||
forge-core/src/main/java/forge/util/ItemPoolSorter.java -text
|
forge-core/src/main/java/forge/util/ItemPoolSorter.java -text
|
||||||
forge-core/src/main/java/forge/util/ItemPoolView.java -text
|
|
||||||
forge-core/src/main/java/forge/util/Lang.java -text
|
forge-core/src/main/java/forge/util/Lang.java -text
|
||||||
forge-core/src/main/java/forge/util/MyRandom.java svneol=native#text/plain
|
forge-core/src/main/java/forge/util/MyRandom.java svneol=native#text/plain
|
||||||
forge-core/src/main/java/forge/util/PredicateString.java -text
|
forge-core/src/main/java/forge/util/PredicateString.java -text
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import com.google.common.collect.Iterables;
|
|||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.item.SealedProduct;
|
import forge.item.SealedProduct;
|
||||||
import forge.util.ItemPoolView;
|
import forge.util.ItemPool;
|
||||||
|
|
||||||
|
|
||||||
public class UnOpenedProduct implements IUnOpenedProduct {
|
public class UnOpenedProduct implements IUnOpenedProduct {
|
||||||
@@ -38,7 +38,7 @@ public class UnOpenedProduct implements IUnOpenedProduct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Invoke this constructor only if you are sure that the pool is not equal to deafult carddb
|
// Invoke this constructor only if you are sure that the pool is not equal to deafult carddb
|
||||||
public UnOpenedProduct(SealedProduct.Template template, ItemPoolView<PaperCard> pool) {
|
public UnOpenedProduct(SealedProduct.Template template, ItemPool<PaperCard> pool) {
|
||||||
this(template, pool.toFlatList());
|
this(template, pool.toFlatList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,9 @@ import forge.item.PaperCard;
|
|||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
import forge.util.FileSection;
|
import forge.util.FileSection;
|
||||||
import forge.util.FileUtil;
|
import forge.util.FileUtil;
|
||||||
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolSorter;
|
import forge.util.ItemPoolSorter;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -210,7 +211,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> writeCardPool(final ItemPoolView<PaperCard> pool) {
|
private static List<String> writeCardPool(final ItemPool<PaperCard> pool) {
|
||||||
List<Entry<PaperCard, Integer>> main2sort = Lists.newArrayList(pool);
|
List<Entry<PaperCard, Integer>> main2sort = Lists.newArrayList(pool);
|
||||||
Collections.sort(main2sort, ItemPoolSorter.BY_NAME_THEN_SET);
|
Collections.sort(main2sort, ItemPoolSorter.BY_NAME_THEN_SET);
|
||||||
final List<String> out = new ArrayList<String>();
|
final List<String> out = new ArrayList<String>();
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ import com.google.common.collect.Lists;
|
|||||||
import forge.card.ColorSet;
|
import forge.card.ColorSet;
|
||||||
import forge.card.ICardDatabase;
|
import forge.card.ICardDatabase;
|
||||||
import forge.card.MagicColor;
|
import forge.card.MagicColor;
|
||||||
import forge.item.PaperCard;
|
import forge.deck.CardPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -88,7 +87,7 @@ public class DeckGenerator2Color extends DeckGeneratorBase {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ItemPoolView<PaperCard> getDeck(final int size, final boolean forAi) {
|
public final CardPool getDeck(final int size, final boolean forAi) {
|
||||||
addCreaturesAndSpells(size, cmcRelativeWeights, forAi);
|
addCreaturesAndSpells(size, cmcRelativeWeights, forAi);
|
||||||
|
|
||||||
// Add lands
|
// Add lands
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ import com.google.common.collect.Lists;
|
|||||||
import forge.card.ColorSet;
|
import forge.card.ColorSet;
|
||||||
import forge.card.ICardDatabase;
|
import forge.card.ICardDatabase;
|
||||||
import forge.card.MagicColor;
|
import forge.card.MagicColor;
|
||||||
import forge.item.PaperCard;
|
import forge.deck.CardPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +96,7 @@ public class DeckGenerator3Color extends DeckGeneratorBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ItemPoolView<PaperCard> getDeck(final int size, final boolean forAi) {
|
public final CardPool getDeck(final int size, final boolean forAi) {
|
||||||
addCreaturesAndSpells(size, cmcLevels, forAi);
|
addCreaturesAndSpells(size, cmcLevels, forAi);
|
||||||
|
|
||||||
// Add lands
|
// Add lands
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ import com.google.common.collect.Lists;
|
|||||||
|
|
||||||
import forge.card.ColorSet;
|
import forge.card.ColorSet;
|
||||||
import forge.card.ICardDatabase;
|
import forge.card.ICardDatabase;
|
||||||
import forge.item.PaperCard;
|
import forge.deck.CardPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -60,7 +59,7 @@ public class DeckGenerator5Color extends DeckGeneratorBase {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ItemPoolView<PaperCard> getDeck(final int size, final boolean forAi) {
|
public final CardPool getDeck(final int size, final boolean forAi) {
|
||||||
addCreaturesAndSpells(size, cmcLevels, forAi);
|
addCreaturesAndSpells(size, cmcLevels, forAi);
|
||||||
|
|
||||||
// Add lands
|
// Add lands
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ import forge.card.ColorSet;
|
|||||||
import forge.card.ICardDatabase;
|
import forge.card.ICardDatabase;
|
||||||
import forge.card.MagicColor;
|
import forge.card.MagicColor;
|
||||||
import forge.card.mana.ManaCost;
|
import forge.card.mana.ManaCost;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,7 +59,7 @@ public abstract class DeckGeneratorBase {
|
|||||||
protected boolean useArtifacts = true;
|
protected boolean useArtifacts = true;
|
||||||
|
|
||||||
protected ColorSet colors;
|
protected ColorSet colors;
|
||||||
protected final ItemPool<PaperCard> tDeck = new ItemPool<PaperCard>(PaperCard.class);
|
protected final CardPool tDeck = new CardPool();
|
||||||
protected final ICardDatabase cardDb;
|
protected final ICardDatabase cardDb;
|
||||||
|
|
||||||
// 2-colored deck generator has its own constants. The rest works fine with these ones
|
// 2-colored deck generator has its own constants. The rest works fine with these ones
|
||||||
@@ -100,7 +100,7 @@ public abstract class DeckGeneratorBase {
|
|||||||
tmpDeck.append(String.format("Current deck size: %d... should be %f%n", tDeck.countAll(), size * (getCreatPercentage() + getSpellPercentage())));
|
tmpDeck.append(String.format("Current deck size: %d... should be %f%n", tDeck.countAll(), size * (getCreatPercentage() + getSpellPercentage())));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemPoolView<PaperCard> getDeck(final int size, final boolean forAi) {
|
public CardPool getDeck(final int size, final boolean forAi) {
|
||||||
return null; // all but theme deck do override this method
|
return null; // all but theme deck do override this method
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ import com.google.common.collect.Lists;
|
|||||||
import forge.card.ColorSet;
|
import forge.card.ColorSet;
|
||||||
import forge.card.ICardDatabase;
|
import forge.card.ICardDatabase;
|
||||||
import forge.card.MagicColor;
|
import forge.card.MagicColor;
|
||||||
import forge.item.PaperCard;
|
import forge.deck.CardPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -79,7 +78,7 @@ public class DeckGeneratorMonoColor extends DeckGeneratorBase {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ItemPoolView<PaperCard> getDeck(final int size, final boolean forAi) {
|
public final CardPool getDeck(final int size, final boolean forAi) {
|
||||||
addCreaturesAndSpells(size, cmcLevels, forAi);
|
addCreaturesAndSpells(size, cmcLevels, forAi);
|
||||||
|
|
||||||
// Add lands
|
// Add lands
|
||||||
|
|||||||
@@ -17,9 +17,17 @@
|
|||||||
*/
|
*/
|
||||||
package forge.util;
|
package forge.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +39,31 @@ import forge.item.InventoryItem;
|
|||||||
* @param <T>
|
* @param <T>
|
||||||
* an Object
|
* an Object
|
||||||
*/
|
*/
|
||||||
public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
public class ItemPool<T extends InventoryItem> implements Iterable<Entry<T, Integer>> {
|
||||||
|
|
||||||
|
/** The fn to printed. */
|
||||||
|
public final transient Function<Entry<T, Integer>, T> FN_GET_KEY = new Function<Entry<T, Integer>, T>() {
|
||||||
|
@Override
|
||||||
|
public T apply(final Entry<T, Integer> from) {
|
||||||
|
return from.getKey();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** The fn to item name. */
|
||||||
|
public final transient Function<Entry<T, Integer>, String> FN_GET_NAME = new Function<Entry<T, Integer>, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(final Entry<T, Integer> from) {
|
||||||
|
return from.getKey().getName();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** The fn to count. */
|
||||||
|
public final transient Function<Entry<T, Integer>, Integer> FN_GET_COUNT = new Function<Entry<T, Integer>, Integer>() {
|
||||||
|
@Override
|
||||||
|
public Integer apply(final Entry<T, Integer> from) {
|
||||||
|
return from.getValue();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Constructors here
|
// Constructors here
|
||||||
/**
|
/**
|
||||||
@@ -42,11 +74,11 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
* a T
|
* a T
|
||||||
*/
|
*/
|
||||||
public ItemPool(final Class<T> cls) {
|
public ItemPool(final Class<T> cls) {
|
||||||
super(cls);
|
this(new Hashtable<T, Integer>(), cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(final ItemPoolView<Tin> from, final Class<Tout> clsHint) {
|
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(final ItemPool<Tin> from, final Class<Tout> clsHint) {
|
||||||
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||||
if (from != null) {
|
if (from != null) {
|
||||||
for (final Entry<Tin, Integer> e : from) {
|
for (final Entry<Tin, Integer> e : from) {
|
||||||
@@ -73,6 +105,135 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ItemPool(final Map<T, Integer> inMap, final Class<T> cls) {
|
||||||
|
this.items = inMap;
|
||||||
|
this.myClass = cls;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data members
|
||||||
|
/** The items. */
|
||||||
|
protected final Map<T, Integer> items;
|
||||||
|
|
||||||
|
/** The my class. */
|
||||||
|
private final Class<T> myClass; // class does not keep this in runtime by
|
||||||
|
// itself
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iterator.
|
||||||
|
*
|
||||||
|
* @return Iterator<Entry<T, Integer>>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public final Iterator<Entry<T, Integer>> iterator() {
|
||||||
|
return this.items.entrySet().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Items read only operations
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* contains.
|
||||||
|
*
|
||||||
|
* @param item
|
||||||
|
* a T
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public final boolean contains(final T item) {
|
||||||
|
if (this.items == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.items.containsKey(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* count.
|
||||||
|
*
|
||||||
|
* @param item
|
||||||
|
* a T
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public final int count(final T item) {
|
||||||
|
if (this.items == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
final Integer boxed = this.items.get(item);
|
||||||
|
return boxed == null ? 0 : boxed.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* countAll.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public final int countAll() {
|
||||||
|
return countAll(null, myClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int countAll(Predicate<T> condition) {
|
||||||
|
return countAll(condition, myClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final <U extends InventoryItem> int countAll(Predicate<U> condition, Class<U> cls) {
|
||||||
|
int result = 0;
|
||||||
|
if (this.items != null) {
|
||||||
|
final boolean isSameClass = cls == myClass;
|
||||||
|
for (final Entry<T, Integer> kv : this) {
|
||||||
|
final T key = kv.getKey();
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final U castKey = isSameClass || cls.isInstance(key) ? (U)key : null;
|
||||||
|
if (null == condition || castKey != null && condition.apply(castKey))
|
||||||
|
result += kv.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* countDistinct.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public final int countDistinct() {
|
||||||
|
return this.items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* isEmpty.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public final boolean isEmpty() {
|
||||||
|
return (this.items == null) || this.items.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* toFlatList.
|
||||||
|
*
|
||||||
|
* @return List<T>
|
||||||
|
*/
|
||||||
|
public final List<T> toFlatList() {
|
||||||
|
final List<T> result = new ArrayList<T>();
|
||||||
|
for (final Entry<T, Integer> e : this) {
|
||||||
|
for (int i = 0; i < e.getValue(); i++) {
|
||||||
|
result.add(e.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the my class.
|
||||||
|
*
|
||||||
|
* @return the myClass
|
||||||
|
*/
|
||||||
|
public Class<T> getMyClass() {
|
||||||
|
return this.myClass;
|
||||||
|
}
|
||||||
|
|
||||||
// get
|
// get
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -80,8 +241,8 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
*
|
*
|
||||||
* @return a ItemPoolView
|
* @return a ItemPoolView
|
||||||
*/
|
*/
|
||||||
public ItemPoolView<T> getView() {
|
public ItemPool<T> getView() {
|
||||||
return new ItemPoolView<T>(Collections.unmodifiableMap(this.items), this.getMyClass());
|
return new ItemPool<T>(Collections.unmodifiableMap(this.items), this.getMyClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Items manipulation
|
// Items manipulation
|
||||||
|
|||||||
@@ -1,216 +0,0 @@
|
|||||||
/*
|
|
||||||
* Forge: Play Magic: the Gathering.
|
|
||||||
* Copyright (C) 2011 Forge Team
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package forge.util;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
|
|
||||||
import forge.item.InventoryItem;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* ItemPoolView class.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* an InventoryItem
|
|
||||||
* @author Forge
|
|
||||||
* @version $Id: ItemPoolView.java 9708 2011-08-09 19:34:12Z jendave $
|
|
||||||
*/
|
|
||||||
public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T, Integer>> {
|
|
||||||
|
|
||||||
/** The fn to printed. */
|
|
||||||
public final transient Function<Entry<T, Integer>, T> FN_GET_KEY = new Function<Entry<T, Integer>, T>() {
|
|
||||||
@Override
|
|
||||||
public T apply(final Entry<T, Integer> from) {
|
|
||||||
return from.getKey();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** The fn to item name. */
|
|
||||||
public final transient Function<Entry<T, Integer>, String> FN_GET_NAME = new Function<Entry<T, Integer>, String>() {
|
|
||||||
@Override
|
|
||||||
public String apply(final Entry<T, Integer> from) {
|
|
||||||
return from.getKey().getName();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** The fn to count. */
|
|
||||||
public final transient Function<Entry<T, Integer>, Integer> FN_GET_COUNT = new Function<Entry<T, Integer>, Integer>() {
|
|
||||||
@Override
|
|
||||||
public Integer apply(final Entry<T, Integer> from) {
|
|
||||||
return from.getValue();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
public ItemPoolView(final Class<T> cls) {
|
|
||||||
this(new Hashtable<T, Integer>(), cls);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) {
|
|
||||||
this.items = inMap;
|
|
||||||
this.myClass = cls;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Data members
|
|
||||||
/** The items. */
|
|
||||||
protected final Map<T, Integer> items;
|
|
||||||
|
|
||||||
/** The my class. */
|
|
||||||
private final Class<T> myClass; // class does not keep this in runtime by
|
|
||||||
// itself
|
|
||||||
|
|
||||||
/**
|
|
||||||
* iterator.
|
|
||||||
*
|
|
||||||
* @return Iterator<Entry<T, Integer>>
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public final Iterator<Entry<T, Integer>> iterator() {
|
|
||||||
return this.items.entrySet().iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Items read only operations
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* contains.
|
|
||||||
*
|
|
||||||
* @param item
|
|
||||||
* a T
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public final boolean contains(final T item) {
|
|
||||||
if (this.items == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return this.items.containsKey(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* count.
|
|
||||||
*
|
|
||||||
* @param item
|
|
||||||
* a T
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public final int count(final T item) {
|
|
||||||
if (this.items == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
final Integer boxed = this.items.get(item);
|
|
||||||
return boxed == null ? 0 : boxed.intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* countAll.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public final int countAll() {
|
|
||||||
return countAll(null, myClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final int countAll(Predicate<T> condition) {
|
|
||||||
return countAll(condition, myClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final <U extends InventoryItem> int countAll(Predicate<U> condition, Class<U> cls) {
|
|
||||||
int result = 0;
|
|
||||||
if (this.items != null) {
|
|
||||||
final boolean isSameClass = cls == myClass;
|
|
||||||
for (final Entry<T, Integer> kv : this) {
|
|
||||||
final T key = kv.getKey();
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final U castKey = isSameClass || cls.isInstance(key) ? (U)key : null;
|
|
||||||
if (null == condition || castKey != null && condition.apply(castKey))
|
|
||||||
result += kv.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* countDistinct.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public final int countDistinct() {
|
|
||||||
return this.items.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* isEmpty.
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public final boolean isEmpty() {
|
|
||||||
return (this.items == null) || this.items.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* toFlatList.
|
|
||||||
*
|
|
||||||
* @return List<T>
|
|
||||||
*/
|
|
||||||
public final List<T> toFlatList() {
|
|
||||||
final List<T> result = new ArrayList<T>();
|
|
||||||
for (final Entry<T, Integer> e : this) {
|
|
||||||
for (int i = 0; i < e.getValue(); i++) {
|
|
||||||
result.add(e.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the my class.
|
|
||||||
*
|
|
||||||
* @return the myClass
|
|
||||||
*/
|
|
||||||
public Class<T> getMyClass() {
|
|
||||||
return this.myClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To item list string.
|
|
||||||
*
|
|
||||||
* @return the iterable
|
|
||||||
*/
|
|
||||||
public Iterable<String> toItemListString() {
|
|
||||||
final List<String> list = new ArrayList<String>();
|
|
||||||
for (final Entry<T, Integer> e : this.items.entrySet()) {
|
|
||||||
list.add(String.format("%d x %s", e.getValue(), e.getKey().getName()));
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,6 @@ import forge.quest.QuestEvent;
|
|||||||
import forge.quest.QuestEventChallenge;
|
import forge.quest.QuestEventChallenge;
|
||||||
import forge.quest.QuestEventDuel;
|
import forge.quest.QuestEventDuel;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.Lang;
|
import forge.util.Lang;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
@@ -72,7 +71,7 @@ public class DeckgenUtil {
|
|||||||
}
|
}
|
||||||
gen.setSingleton(Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_SINGLETONS));
|
gen.setSingleton(Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_SINGLETONS));
|
||||||
gen.setUseArtifacts(Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS));
|
gen.setUseArtifacts(Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS));
|
||||||
ItemPoolView<PaperCard> cards = gen == null ? null : gen.getDeck(60, forAi);
|
CardPool cards = gen == null ? null : gen.getDeck(60, forAi);
|
||||||
|
|
||||||
if (null == deckName) {
|
if (null == deckName) {
|
||||||
deckName = Lang.joinHomogenous(Arrays.asList(selection));
|
deckName = Lang.joinHomogenous(Arrays.asList(selection));
|
||||||
|
|||||||
@@ -23,11 +23,10 @@ import java.util.List;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.deck.generation.DeckGeneratorBase;
|
import forge.deck.generation.DeckGeneratorBase;
|
||||||
import forge.error.BugReporter;
|
import forge.error.BugReporter;
|
||||||
import forge.item.PaperCard;
|
|
||||||
import forge.util.FileUtil;
|
import forge.util.FileUtil;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,7 +94,7 @@ public class GenerateThemeDeck extends DeckGeneratorBase {
|
|||||||
* a int.
|
* a int.
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
public final ItemPoolView<PaperCard> getThemeDeck(final String themeName, final int size) {
|
public final CardPool getThemeDeck(final String themeName, final int size) {
|
||||||
String s = "";
|
String s = "";
|
||||||
|
|
||||||
// read theme file
|
// read theme file
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import forge.gui.toolbox.itemmanager.views.SColumnUtil;
|
|||||||
import forge.gui.toolbox.itemmanager.views.ItemColumn;
|
import forge.gui.toolbox.itemmanager.views.ItemColumn;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Child controller for constructed deck editor UI.
|
* Child controller for constructed deck editor UI.
|
||||||
@@ -60,8 +59,8 @@ public final class CEditorCommander extends ACEditorBase<PaperCard, Deck> {
|
|||||||
private DragCell deckGenParent = null;
|
private DragCell deckGenParent = null;
|
||||||
|
|
||||||
private List<DeckSection> allSections = new ArrayList<DeckSection>();
|
private List<DeckSection> allSections = new ArrayList<DeckSection>();
|
||||||
private final ItemPoolView<PaperCard> commanderPool;
|
private final ItemPool<PaperCard> commanderPool;
|
||||||
private final ItemPoolView<PaperCard> normalPool;
|
private final ItemPool<PaperCard> normalPool;
|
||||||
|
|
||||||
//=========== Constructor
|
//=========== Constructor
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import forge.gui.toolbox.itemmanager.views.SColumnUtil;
|
|||||||
import forge.gui.toolbox.itemmanager.views.ItemColumn;
|
import forge.gui.toolbox.itemmanager.views.ItemColumn;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Child controller for constructed deck editor UI.
|
* Child controller for constructed deck editor UI.
|
||||||
@@ -54,7 +53,7 @@ import forge.util.ItemPoolView;
|
|||||||
public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
|
public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
|
||||||
private final DeckController<Deck> controller;
|
private final DeckController<Deck> controller;
|
||||||
private final List<DeckSection> allSections = new ArrayList<DeckSection>();
|
private final List<DeckSection> allSections = new ArrayList<DeckSection>();
|
||||||
private final ItemPoolView<PaperCard> normalPool, avatarPool, planePool, schemePool;
|
private final ItemPool<PaperCard> normalPool, avatarPool, planePool, schemePool;
|
||||||
|
|
||||||
//=========== Constructor
|
//=========== Constructor
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import forge.gui.toolbox.itemmanager.views.SColumnUtil;
|
|||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.limited.BoosterDraft;
|
import forge.limited.BoosterDraft;
|
||||||
import forge.limited.IBoosterDraft;
|
import forge.limited.IBoosterDraft;
|
||||||
import forge.util.ItemPoolView;
|
import forge.util.ItemPool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the deck editor UI as necessary draft selection mode.
|
* Updates the deck editor UI as necessary draft selection mode.
|
||||||
@@ -132,7 +132,7 @@ public class CEditorDraftingProcess extends ACEditorBase<PaperCard, DeckGroup> {
|
|||||||
* @param list
|
* @param list
|
||||||
* a {@link forge.CardList} object.
|
* a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
private void showChoices(final ItemPoolView<PaperCard> list) {
|
private void showChoices(final ItemPool<PaperCard> list) {
|
||||||
int packNumber = ((BoosterDraft) boosterDraft).getCurrentBoosterIndex() + 1;
|
int packNumber = ((BoosterDraft) boosterDraft).getCurrentBoosterIndex() + 1;
|
||||||
|
|
||||||
this.getCatalogManager().setCaption("Pack " + packNumber + " - Cards");
|
this.getCatalogManager().setCaption("Pack " + packNumber + " - Cards");
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ import forge.item.TournamentPack;
|
|||||||
import forge.quest.QuestController;
|
import forge.quest.QuestController;
|
||||||
import forge.quest.io.ReadPriceList;
|
import forge.quest.io.ReadPriceList;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Child controller for quest card shop UI.
|
* Child controller for quest card shop UI.
|
||||||
@@ -97,7 +96,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
|||||||
private double multiplier;
|
private double multiplier;
|
||||||
private final QuestController questData;
|
private final QuestController questData;
|
||||||
|
|
||||||
private ItemPoolView<InventoryItem> cardsForSale;
|
private ItemPool<InventoryItem> cardsForSale;
|
||||||
private final ItemPool<InventoryItem> fullCatalogCards =
|
private final ItemPool<InventoryItem> fullCatalogCards =
|
||||||
ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), InventoryItem.class);
|
ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), InventoryItem.class);
|
||||||
private boolean showingFullCatalog = false;
|
private boolean showingFullCatalog = false;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import forge.gui.framework.ICDoc;
|
|||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,7 +67,7 @@ public enum CProbabilities implements ICDoc {
|
|||||||
|
|
||||||
if (ed == null) { return new ArrayList<String>(); }
|
if (ed == null) { return new ArrayList<String>(); }
|
||||||
|
|
||||||
final ItemPoolView<PaperCard> deck = ItemPool.createFrom(ed.getDeckManager().getPool(), PaperCard.class);
|
final ItemPool<PaperCard> deck = ItemPool.createFrom(ed.getDeckManager().getPool(), PaperCard.class);
|
||||||
|
|
||||||
final List<String> cardProbabilities = new ArrayList<String>();
|
final List<String> cardProbabilities = new ArrayList<String>();
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import forge.gui.toolbox.itemmanager.SItemManagerUtil;
|
|||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +56,7 @@ public enum CStatistics implements ICDoc {
|
|||||||
analyze();
|
analyze();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLabelValue(JLabel label, ItemPoolView<PaperCard> deck, Predicate<CardRules> predicate, int total) {
|
private void setLabelValue(JLabel label, ItemPool<PaperCard> deck, Predicate<CardRules> predicate, int total) {
|
||||||
int tmp = deck.countAll(Predicates.compose(predicate, PaperCard.FN_GET_RULES));
|
int tmp = deck.countAll(Predicates.compose(predicate, PaperCard.FN_GET_RULES));
|
||||||
label.setText(tmp + " (" + SItemManagerUtil.calculatePercentage(tmp, total) + "%)");
|
label.setText(tmp + " (" + SItemManagerUtil.calculatePercentage(tmp, total) + "%)");
|
||||||
}
|
}
|
||||||
@@ -70,7 +69,7 @@ public enum CStatistics implements ICDoc {
|
|||||||
|
|
||||||
if (ed == null) { return; }
|
if (ed == null) { return; }
|
||||||
|
|
||||||
final ItemPoolView<PaperCard> deck = ItemPool.createFrom(ed.getDeckManager().getPool(), PaperCard.class);
|
final ItemPool<PaperCard> deck = ItemPool.createFrom(ed.getDeckManager().getPool(), PaperCard.class);
|
||||||
|
|
||||||
int total = deck.countAll();
|
int total = deck.countAll();
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ import forge.gui.toolbox.itemmanager.views.ItemView;
|
|||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.ReflectionUtil;
|
import forge.util.ReflectionUtil;
|
||||||
|
|
||||||
|
|
||||||
@@ -383,7 +382,7 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
|||||||
*
|
*
|
||||||
* @return ItemPoolView
|
* @return ItemPoolView
|
||||||
*/
|
*/
|
||||||
public ItemPoolView<T> getPool() {
|
public ItemPool<T> getPool() {
|
||||||
return this.pool;
|
return this.pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,15 +396,6 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
|||||||
this.setPool(ItemPool.createFrom(items, this.genericType), false);
|
this.setPool(ItemPool.createFrom(items, this.genericType), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Sets the item pool.
|
|
||||||
*
|
|
||||||
* @param poolView
|
|
||||||
*/
|
|
||||||
public void setPool(final ItemPoolView<T> poolView) {
|
|
||||||
this.setPool(poolView, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -414,17 +404,11 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
|||||||
* @param poolView
|
* @param poolView
|
||||||
* @param infinite
|
* @param infinite
|
||||||
*/
|
*/
|
||||||
public void setPool(final ItemPoolView<T> poolView, boolean infinite) {
|
public void setPool(final ItemPool<T> poolView, boolean infinite) {
|
||||||
this.setPoolImpl(ItemPool.createFrom(poolView, this.genericType), infinite);
|
this.setPoolImpl(ItemPool.createFrom(poolView, this.genericType), infinite);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Sets the item pool.
|
|
||||||
*
|
|
||||||
* @param pool0
|
|
||||||
*/
|
|
||||||
public void setPool(final ItemPool<T> pool0) {
|
public void setPool(final ItemPool<T> pool0) {
|
||||||
this.setPoolImpl(pool0, false);
|
this.setPoolImpl(pool0, false);
|
||||||
}
|
}
|
||||||
@@ -708,7 +692,7 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel {
|
|||||||
*
|
*
|
||||||
* @return ItemPoolView<T>
|
* @return ItemPoolView<T>
|
||||||
*/
|
*/
|
||||||
public ItemPoolView<T> getFilteredItems() {
|
public ItemPool<T> getFilteredItems() {
|
||||||
return this.model.getItems();
|
return this.model.getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import java.util.Map.Entry;
|
|||||||
|
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -107,7 +106,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
|||||||
*
|
*
|
||||||
* @return ItemPoolView<T>
|
* @return ItemPoolView<T>
|
||||||
*/
|
*/
|
||||||
public ItemPoolView<T> getItems() {
|
public ItemPool<T> getItems() {
|
||||||
return this.data.getView();
|
return this.data.getView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import forge.deck.Deck;
|
|||||||
import forge.gui.toolbox.itemmanager.ItemManager;
|
import forge.gui.toolbox.itemmanager.ItemManager;
|
||||||
import forge.gui.toolbox.itemmanager.SItemManagerUtil.StatTypes;
|
import forge.gui.toolbox.itemmanager.SItemManagerUtil.StatTypes;
|
||||||
import forge.util.BinaryUtil;
|
import forge.util.BinaryUtil;
|
||||||
import forge.util.ItemPoolView;
|
import forge.util.ItemPool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Write javadoc for this type.
|
* TODO: Write javadoc for this type.
|
||||||
@@ -121,7 +121,7 @@ public class DeckColorFilter extends StatTypeFilter<Deck> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterFiltersApplied() {
|
public void afterFiltersApplied() {
|
||||||
final ItemPoolView<? super Deck> items = itemManager.getFilteredItems();
|
final ItemPool<? super Deck> items = itemManager.getFilteredItems();
|
||||||
|
|
||||||
buttonMap.get(StatTypes.DECK_WHITE).setText(String.valueOf(items.countAll(IS_WHITE, Deck.class)));
|
buttonMap.get(StatTypes.DECK_WHITE).setText(String.valueOf(items.countAll(IS_WHITE, Deck.class)));
|
||||||
buttonMap.get(StatTypes.DECK_BLUE).setText(String.valueOf(items.countAll(IS_BLUE, Deck.class)));
|
buttonMap.get(StatTypes.DECK_BLUE).setText(String.valueOf(items.countAll(IS_BLUE, Deck.class)));
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import forge.gui.toolbox.itemmanager.ItemManager;
|
|||||||
import forge.gui.toolbox.itemmanager.SItemManagerUtil;
|
import forge.gui.toolbox.itemmanager.SItemManagerUtil;
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.ItemPoolView;
|
import forge.util.ItemPool;
|
||||||
|
|
||||||
public abstract class DeckStatTypeFilter extends StatTypeFilter<Deck> {
|
public abstract class DeckStatTypeFilter extends StatTypeFilter<Deck> {
|
||||||
public DeckStatTypeFilter(ItemManager<? super Deck> itemManager0) {
|
public DeckStatTypeFilter(ItemManager<? super Deck> itemManager0) {
|
||||||
@@ -24,7 +24,7 @@ public abstract class DeckStatTypeFilter extends StatTypeFilter<Deck> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterFiltersApplied() {
|
public void afterFiltersApplied() {
|
||||||
final ItemPoolView<? super Deck> items = itemManager.getFilteredItems();
|
final ItemPool<? super Deck> items = itemManager.getFilteredItems();
|
||||||
|
|
||||||
for (Map.Entry<SItemManagerUtil.StatTypes, FLabel> btn : buttonMap.entrySet()) {
|
for (Map.Entry<SItemManagerUtil.StatTypes, FLabel> btn : buttonMap.entrySet()) {
|
||||||
if (btn.getKey().predicate != null) {
|
if (btn.getKey().predicate != null) {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import forge.gui.toolbox.itemmanager.SItemManagerUtil.StatTypes;
|
|||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.item.ItemPredicate;
|
import forge.item.ItemPredicate;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.ItemPoolView;
|
import forge.util.ItemPool;
|
||||||
|
|
||||||
public abstract class StatTypeFilter<T extends InventoryItem> extends ToggleButtonsFilter<T> {
|
public abstract class StatTypeFilter<T extends InventoryItem> extends ToggleButtonsFilter<T> {
|
||||||
protected final Map<SItemManagerUtil.StatTypes, FLabel> buttonMap;
|
protected final Map<SItemManagerUtil.StatTypes, FLabel> buttonMap;
|
||||||
@@ -118,7 +118,7 @@ public abstract class StatTypeFilter<T extends InventoryItem> extends ToggleButt
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterFiltersApplied() {
|
public void afterFiltersApplied() {
|
||||||
final ItemPoolView<? super T> items = itemManager.getFilteredItems();
|
final ItemPool<? super T> items = itemManager.getFilteredItems();
|
||||||
|
|
||||||
FLabel btnPackOrDeck = buttonMap.get(StatTypes.PACK_OR_DECK);
|
FLabel btnPackOrDeck = buttonMap.get(StatTypes.PACK_OR_DECK);
|
||||||
if (btnPackOrDeck != null) { //support special pack/deck case
|
if (btnPackOrDeck != null) { //support special pack/deck case
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import forge.card.CardRarity;
|
|||||||
import forge.card.CardRules;
|
import forge.card.CardRules;
|
||||||
import forge.card.ColorSet;
|
import forge.card.ColorSet;
|
||||||
import forge.card.mana.ManaCost;
|
import forge.card.mana.ManaCost;
|
||||||
import forge.deck.CardPool;
|
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckSection;
|
import forge.deck.DeckSection;
|
||||||
import forge.game.GameFormat;
|
import forge.game.GameFormat;
|
||||||
@@ -491,7 +490,7 @@ public class ItemColumn extends TableColumn {
|
|||||||
private static final Pattern AE_FINDER = Pattern.compile("AE", Pattern.LITERAL);
|
private static final Pattern AE_FINDER = Pattern.compile("AE", Pattern.LITERAL);
|
||||||
|
|
||||||
private static String toType(final InventoryItem i) {
|
private static String toType(final InventoryItem i) {
|
||||||
return i instanceof PaperCard ? ((IPaperCard)i).getRules().getType().toString() : i.getItemType();
|
return i instanceof IPaperCard ? ((IPaperCard)i).getRules().getType().toString() : i.getItemType();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IPaperCard toCard(final InventoryItem i) {
|
private static IPaperCard toCard(final InventoryItem i) {
|
||||||
@@ -551,12 +550,7 @@ public class ItemColumn extends TableColumn {
|
|||||||
}
|
}
|
||||||
private static int toDeckCount(final InventoryItem i, DeckSection section) {
|
private static int toDeckCount(final InventoryItem i, DeckSection section) {
|
||||||
Deck deck = toDeck(i);
|
Deck deck = toDeck(i);
|
||||||
if (deck == null) { return -1; }
|
return deck != null && deck.has(section) ? deck.get(section).countAll() : -1;
|
||||||
CardPool cards = deck.get(section);
|
|
||||||
if (cards == null) { return -1; }
|
|
||||||
int count = cards.countAll();
|
|
||||||
if (count == 0) { return -1; }
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import forge.Singletons;
|
|||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
import forge.card.IUnOpenedProduct;
|
import forge.card.IUnOpenedProduct;
|
||||||
import forge.card.UnOpenedProduct;
|
import forge.card.UnOpenedProduct;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.gui.GuiChoose;
|
import forge.gui.GuiChoose;
|
||||||
@@ -48,7 +49,6 @@ import forge.properties.NewConstants;
|
|||||||
import forge.util.FileUtil;
|
import forge.util.FileUtil;
|
||||||
import forge.util.HttpUtil;
|
import forge.util.HttpUtil;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,7 +153,7 @@ public final class BoosterDraft implements IBoosterDraft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupCustomDraft(final CustomLimited draft) {
|
private void setupCustomDraft(final CustomLimited draft) {
|
||||||
final ItemPoolView<PaperCard> dPool = draft.getCardPool();
|
final ItemPool<PaperCard> dPool = draft.getCardPool();
|
||||||
if (dPool == null) {
|
if (dPool == null) {
|
||||||
throw new RuntimeException("BoosterGenerator : deck not found");
|
throw new RuntimeException("BoosterGenerator : deck not found");
|
||||||
}
|
}
|
||||||
@@ -203,13 +203,15 @@ public final class BoosterDraft implements IBoosterDraft {
|
|||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemPoolView<PaperCard> nextChoice() {
|
public CardPool nextChoice() {
|
||||||
if (this.pack.get(this.getCurrentBoosterIndex()).size() == 0) {
|
if (this.pack.get(this.getCurrentBoosterIndex()).size() == 0) {
|
||||||
this.pack = this.get8BoosterPack();
|
this.pack = this.get8BoosterPack();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.computerChoose();
|
this.computerChoose();
|
||||||
return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), PaperCard.class);
|
CardPool result = new CardPool();
|
||||||
|
result.addAllFlat(this.pack.get(this.getCurrentBoosterIndex()));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import forge.item.PaperCard;
|
|||||||
import forge.item.SealedProduct;
|
import forge.item.SealedProduct;
|
||||||
import forge.util.FileSection;
|
import forge.util.FileSection;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.TextUtil;
|
import forge.util.TextUtil;
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
|
|
||||||
@@ -63,7 +62,7 @@ public class CustomLimited extends DeckBase {
|
|||||||
/** The Num packs. */
|
/** The Num packs. */
|
||||||
private int numPacks = 3;
|
private int numPacks = 3;
|
||||||
|
|
||||||
private transient ItemPoolView<PaperCard> cardPool;
|
private transient ItemPool<PaperCard> cardPool;
|
||||||
|
|
||||||
/** The Land set code. */
|
/** The Land set code. */
|
||||||
private String landSetCode = CardEdition.Predicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions()).getCode();
|
private String landSetCode = CardEdition.Predicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions()).getCode();
|
||||||
@@ -153,7 +152,7 @@ public class CustomLimited extends DeckBase {
|
|||||||
*
|
*
|
||||||
* @see forge.item.CardCollectionBase#getCardPool()
|
* @see forge.item.CardCollectionBase#getCardPool()
|
||||||
*/
|
*/
|
||||||
public ItemPoolView<PaperCard> getCardPool() {
|
public ItemPool<PaperCard> getCardPool() {
|
||||||
return this.cardPool;
|
return this.cardPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
package forge.limited;
|
package forge.limited;
|
||||||
|
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -38,7 +38,7 @@ public interface IBoosterDraft {
|
|||||||
*
|
*
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
ItemPoolView<PaperCard> nextChoice();
|
CardPool nextChoice();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import forge.deck.DeckSection;
|
|||||||
import forge.deck.generation.DeckGeneratorBase;
|
import forge.deck.generation.DeckGeneratorBase;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +96,7 @@ public class LimitedDeckBuilder extends DeckGeneratorBase{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemPoolView<PaperCard> getDeck(int size, boolean forAi) {
|
public CardPool getDeck(int size, boolean forAi) {
|
||||||
return buildDeck().getMain();
|
return buildDeck().getMain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
|||||||
import forge.quest.data.QuestPreferences.QPref;
|
import forge.quest.data.QuestPreferences.QPref;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +86,7 @@ public final class QuestUtilCards {
|
|||||||
* @param usedFormat currently enforced game format, if any
|
* @param usedFormat currently enforced game format, if any
|
||||||
* @return the item pool view
|
* @return the item pool view
|
||||||
*/
|
*/
|
||||||
public static ItemPoolView<PaperCard> generateBasicLands(final int nBasic, final int nSnow, final GameFormatQuest usedFormat) {
|
public static ItemPool<PaperCard> generateBasicLands(final int nBasic, final int nSnow, final GameFormatQuest usedFormat) {
|
||||||
final ICardDatabase db = Singletons.getMagicDb().getCommonCards();
|
final ICardDatabase db = Singletons.getMagicDb().getCommonCards();
|
||||||
final ItemPool<PaperCard> pool = new ItemPool<PaperCard>(PaperCard.class);
|
final ItemPool<PaperCard> pool = new ItemPool<PaperCard>(PaperCard.class);
|
||||||
|
|
||||||
@@ -591,7 +590,7 @@ public final class QuestUtilCards {
|
|||||||
*
|
*
|
||||||
* @return the shop list
|
* @return the shop list
|
||||||
*/
|
*/
|
||||||
public ItemPoolView<InventoryItem> getShopList() {
|
public ItemPool<InventoryItem> getShopList() {
|
||||||
if (this.qa.getShopList().isEmpty()) {
|
if (this.qa.getShopList().isEmpty()) {
|
||||||
this.generateCardsInShop();
|
this.generateCardsInShop();
|
||||||
}
|
}
|
||||||
@@ -603,7 +602,7 @@ public final class QuestUtilCards {
|
|||||||
*
|
*
|
||||||
* @return the new cards
|
* @return the new cards
|
||||||
*/
|
*/
|
||||||
public ItemPoolView<InventoryItem> getNewCards() {
|
public ItemPool<InventoryItem> getNewCards() {
|
||||||
return this.qa.getNewCardList();
|
return this.qa.getNewCardList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import forge.quest.QuestUtilCards;
|
|||||||
import forge.quest.bazaar.QuestItemType;
|
import forge.quest.bazaar.QuestItemType;
|
||||||
import forge.quest.data.QuestPreferences.QPref;
|
import forge.quest.data.QuestPreferences.QPref;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
public class QuestAssets {
|
public class QuestAssets {
|
||||||
@@ -171,7 +170,7 @@ public class QuestAssets {
|
|||||||
if (useFormat != null && !useFormat.hasSnowLands()) {
|
if (useFormat != null && !useFormat.hasSnowLands()) {
|
||||||
snowLands = 0;
|
snowLands = 0;
|
||||||
}
|
}
|
||||||
final ItemPoolView<PaperCard> lands = QuestUtilCards.generateBasicLands(
|
final ItemPool<PaperCard> lands = QuestUtilCards.generateBasicLands(
|
||||||
prefs.getPrefInt(QPref.STARTING_BASIC_LANDS), snowLands, useFormat);
|
prefs.getPrefInt(QPref.STARTING_BASIC_LANDS), snowLands, useFormat);
|
||||||
this.getCardPool().addAll(lands);
|
this.getCardPool().addAll(lands);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ package forge;
|
|||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import forge.item.PaperCard;
|
import forge.deck.CardPool;
|
||||||
import forge.limited.BoosterDraft;
|
import forge.limited.BoosterDraft;
|
||||||
import forge.limited.LimitedPoolType;
|
import forge.limited.LimitedPoolType;
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
@@ -23,7 +22,7 @@ public class BoosterDraft1Test {
|
|||||||
public void boosterDraft1Test1() throws Exception {
|
public void boosterDraft1Test1() throws Exception {
|
||||||
final BoosterDraft draft = new BoosterDraft(LimitedPoolType.Full);
|
final BoosterDraft draft = new BoosterDraft(LimitedPoolType.Full);
|
||||||
while (draft.hasNextChoice()) {
|
while (draft.hasNextChoice()) {
|
||||||
final ItemPoolView<PaperCard> list = draft.nextChoice();
|
final CardPool list = draft.nextChoice();
|
||||||
System.out.println(list.countAll());
|
System.out.println(list.countAll());
|
||||||
draft.setChoice(list.toFlatList().get(0));
|
draft.setChoice(list.toFlatList().get(0));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import java.util.List;
|
|||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import forge.card.BoosterGenerator;
|
import forge.card.BoosterGenerator;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.item.SealedProduct;
|
import forge.item.SealedProduct;
|
||||||
import forge.limited.IBoosterDraft;
|
import forge.limited.IBoosterDraft;
|
||||||
import forge.util.ItemPool;
|
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -48,10 +47,12 @@ public class BoosterDraftTest implements IBoosterDraft {
|
|||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemPoolView<PaperCard> nextChoice() {
|
public CardPool nextChoice() {
|
||||||
this.n--;
|
this.n--;
|
||||||
SealedProduct.Template booster = Singletons.getMagicDb().getBoosters().get("M11");
|
SealedProduct.Template booster = Singletons.getMagicDb().getBoosters().get("M11");
|
||||||
return ItemPool.createFrom(BoosterGenerator.getBoosterPack(booster), PaperCard.class);
|
CardPool result = new CardPool();
|
||||||
|
result.addAllFlat(BoosterGenerator.getBoosterPack(booster));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import forge.Singletons;
|
|||||||
import forge.card.CardDb;
|
import forge.card.CardDb;
|
||||||
import forge.deck.generation.DeckGenerator2Color;
|
import forge.deck.generation.DeckGenerator2Color;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.ItemPoolView;
|
import forge.util.ItemPool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA. User: dhudson
|
* Created by IntelliJ IDEA. User: dhudson
|
||||||
@@ -22,7 +22,7 @@ public class Generate2ColorDeckTest {
|
|||||||
public void generate2ColorDeckTest1() {
|
public void generate2ColorDeckTest1() {
|
||||||
CardDb cardDb = Singletons.getMagicDb().getCommonCards();
|
CardDb cardDb = Singletons.getMagicDb().getCommonCards();
|
||||||
final DeckGenerator2Color gen = new DeckGenerator2Color(cardDb, "white", "blue");
|
final DeckGenerator2Color gen = new DeckGenerator2Color(cardDb, "white", "blue");
|
||||||
final ItemPoolView<PaperCard> cardList = gen.getDeck(60, false);
|
final ItemPool<PaperCard> cardList = gen.getDeck(60, false);
|
||||||
Assert.assertNotNull(cardList);
|
Assert.assertNotNull(cardList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import org.testng.annotations.Test;
|
|||||||
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.CardDb;
|
import forge.card.CardDb;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.deck.generation.DeckGenerator3Color;
|
import forge.deck.generation.DeckGenerator3Color;
|
||||||
import forge.item.PaperCard;
|
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA. User: dhudson
|
* Created by IntelliJ IDEA. User: dhudson
|
||||||
@@ -22,7 +21,7 @@ public class Generate3ColorDeckTest {
|
|||||||
public void generate3ColorDeckTest1() {
|
public void generate3ColorDeckTest1() {
|
||||||
CardDb cardDb = Singletons.getMagicDb().getCommonCards();
|
CardDb cardDb = Singletons.getMagicDb().getCommonCards();
|
||||||
final DeckGenerator3Color gen = new DeckGenerator3Color(cardDb, "white", "blue", "black");
|
final DeckGenerator3Color gen = new DeckGenerator3Color(cardDb, "white", "blue", "black");
|
||||||
final ItemPoolView<PaperCard> cardList = gen.getDeck(60, false);
|
final CardPool cardList = gen.getDeck(60, false);
|
||||||
Assert.assertNotNull(cardList);
|
Assert.assertNotNull(cardList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import org.testng.annotations.Test;
|
|||||||
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.CardDb;
|
import forge.card.CardDb;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.deck.generation.DeckGenerator5Color;
|
import forge.deck.generation.DeckGenerator5Color;
|
||||||
import forge.item.PaperCard;
|
|
||||||
import forge.util.ItemPoolView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by IntelliJ IDEA. User: dhudson
|
* Created by IntelliJ IDEA. User: dhudson
|
||||||
@@ -22,7 +21,7 @@ public class Generate5ColorDeckTest {
|
|||||||
public void generate5ColorDeckTest1() {
|
public void generate5ColorDeckTest1() {
|
||||||
CardDb cardDb = Singletons.getMagicDb().getCommonCards();
|
CardDb cardDb = Singletons.getMagicDb().getCommonCards();
|
||||||
final DeckGenerator5Color gen = new DeckGenerator5Color(cardDb);
|
final DeckGenerator5Color gen = new DeckGenerator5Color(cardDb);
|
||||||
final ItemPoolView<PaperCard> cardList = gen.getDeck(60, false);
|
final CardPool cardList = gen.getDeck(60, false);
|
||||||
Assert.assertNotNull(cardList);
|
Assert.assertNotNull(cardList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user