removed list or items from CardPool that had to be kept in sync with the main map, since no other class but ItemManagerModel used it (I wanted to do that for too long already!)

This commit is contained in:
Maxmtg
2014-01-20 08:49:52 +00:00
parent 3b8d779b27
commit 85e5b0ff13
6 changed files with 34 additions and 43 deletions

View File

@@ -32,6 +32,8 @@ import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import forge.StaticData;
import forge.card.CardDb;
@@ -209,7 +211,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
}
private static List<String> writeCardPool(final ItemPoolView<PaperCard> pool) {
final List<Entry<PaperCard, Integer>> main2sort = pool.getOrderedList();
List<Entry<PaperCard, Integer>> main2sort = Lists.newArrayList(pool);
Collections.sort(main2sort, ItemPoolSorter.BY_NAME_THEN_SET);
final List<String> out = new ArrayList<String>();
for (final Entry<PaperCard, Integer> e : main2sort) {

View File

@@ -33,8 +33,6 @@ import forge.item.InventoryItem;
*/
public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
// Constructors here
/**
*
@@ -47,7 +45,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
super(cls);
}
@SuppressWarnings("unchecked")
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);
@@ -113,7 +110,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
return;
}
this.items.put(item, Integer.valueOf(this.count(item) + amount));
this.isListInSync = false;
}
/**
@@ -131,7 +127,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
this.add((T) cr);
}
}
this.isListInSync = false;
}
/**
@@ -150,7 +145,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
this.add((T) e.getKey(), e.getValue());
}
}
this.isListInSync = false;
}
/**
@@ -183,7 +177,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
} else {
this.items.put(item, count - amount);
}
this.isListInSync = false;
return true;
}
@@ -223,6 +216,5 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
*/
public void clear() {
this.items.clear();
this.isListInSync = false;
}
}

View File

@@ -84,14 +84,6 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
private final Class<T> myClass; // class does not keep this in runtime by
// itself
// same thing as above, it was copied to provide sorting (needed by table
// views in deck editors)
/** The items ordered. */
private final transient List<Entry<T, Integer>> itemsOrdered = new ArrayList<Map.Entry<T, Integer>>();
/** Whether list is in sync. */
protected transient boolean isListInSync = false;
/**
* iterator.
*
@@ -183,29 +175,6 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
return (this.items == null) || this.items.isEmpty();
}
/**
*
* getOrderedList.
*
* @return List<Entry<T, Integer>>
*/
public final List<Entry<T, Integer>> getOrderedList() {
if (!this.isListInSync) {
this.rebuildOrderedList();
}
return this.itemsOrdered;
}
private void rebuildOrderedList() {
this.itemsOrdered.clear();
if (this.items != null) {
for (final Entry<T, Integer> e : this.items.entrySet()) {
this.itemsOrdered.add(e);
}
}
this.isListInSync = true;
}
/**
*
* toFlatList.

View File

@@ -1,7 +1,7 @@
Name:Back from the Brink
ManaCost:4 U U
Types:Enchantment
A:AB$ CopyPermanent | Cost$ ExileAndPay | Defined$ Exiled | SorcerySpeed$ True | SpellDescription$ Put a token onto the battlefield that's a copy of that card. Activate this ability only any time you could cast a sorcery.
A:AB$ CopyPermanent | Cost$ ExileFromGrave<1/Creature> Mana<X\Remembered> | Defined$ Exiled | SorcerySpeed$ True | SpellDescription$ Put a token onto the battlefield that's a copy of that card. Activate this ability only any time you could cast a sorcery.
SVar:NonStackingEffect:True
SVar:Picture:http://www.wizards.com/global/images/magic/general/back_from_the_brink.jpg
Oracle:Exile a creature card from your graveyard and pay its mana cost: Put a token onto the battlefield that's a copy of that card. Activate this ability only any time you could cast a sorcery.

View File

@@ -81,7 +81,7 @@ public class DeckHtmlSerializer {
}
final TreeMap<String, Integer> map = new TreeMap<String, Integer>();
for (final Entry<PaperCard, Integer> entry : d.getMain().getOrderedList()) {
for (final Entry<PaperCard, Integer> entry : d.getMain()) {
map.put(entry.getKey().getName(), entry.getValue());
// System.out.println(entry.getValue() + " " +
// entry.getKey().getName());

View File

@@ -17,7 +17,9 @@
*/
package forge.gui.toolbox.itemmanager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import forge.item.InventoryItem;
@@ -63,10 +65,33 @@ public final class ItemManagerModel<T extends InventoryItem> {
*
* @return List<Entry<T, Integer>>
*/
// same thing as above, it was copied to provide sorting (needed by table
// views in deck editors)
/** The items ordered. */
private final transient List<Entry<T, Integer>> itemsOrdered = new ArrayList<Map.Entry<T, Integer>>();
/** Whether list is in sync. */
protected transient boolean isListInSync = false;
public final List<Entry<T, Integer>> getOrderedList() {
return this.data.getOrderedList();
if (!this.isListInSync) {
this.rebuildOrderedList();
}
return this.itemsOrdered;
}
private void rebuildOrderedList() {
this.itemsOrdered.clear();
if (this.data != null) {
for (final Entry<T, Integer> e : this.data) {
this.itemsOrdered.add(e);
}
}
this.isListInSync = true;
}
/**
*
* countDistinct.
@@ -97,6 +122,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
final boolean wasThere = this.data.count(item0) > 0;
if (wasThere) {
this.data.remove(item0, qty);
isListInSync = false;
this.itemManager.getTable().getTableModel().fireTableDataChanged();
}
}
@@ -108,6 +134,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
*/
public void addItem(final T item0, int qty) {
this.data.add(item0, qty);
isListInSync = false;
this.itemManager.getTable().getTableModel().fireTableDataChanged();
}
@@ -118,6 +145,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
*/
public void addItems(final Iterable<Entry<T, Integer>> items0) {
this.data.addAll(items0);
isListInSync = false;
this.itemManager.getTable().getTableModel().fireTableDataChanged();
}