Fix proxy generator cardlist

This commit is contained in:
jendave
2011-10-23 06:57:37 +00:00
parent b3a5860066
commit 1b3445f325
3 changed files with 103 additions and 7 deletions

View File

@@ -666,12 +666,19 @@ public class DeckManager {
//System.out.println(card.getSets().get(card.getSets().size() - 1).URL);
nameList.add(card.getName());
}
Map<String, Integer> map = new HashMap<String, Integer>();
for (Entry<CardPrinted, Integer> entry : d.getMain().getOrderedList()) {
map.put(entry.getKey().getName(), entry.getValue());
System.out.println(entry.getValue() + " " + entry.getKey().getName());
}
root.put("urls", list);
root.put("cardBorder", cardBorder);
root.put("height", height);
root.put("width", width);
root.put("cardlistWidth", width - 11);
root.put("nameList", nameList);
root.put("cardList", map);
/* Merge data-model with template */
//StringWriter sw = new StringWriter();

View File

@@ -21,6 +21,9 @@ import net.slightlymagic.braids.util.lambda.Lambda1;
public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T, Integer>> {
// Field Accessors for select/aggregate operations with filters.
/**
*
*/
public final Lambda1<CardRules, Entry<T, Integer>> fnToCard =
new Lambda1<CardRules, Entry<T, Integer>>() {
@Override public CardRules apply(final Entry<T, Integer> from) {
@@ -28,52 +31,129 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
return item instanceof CardPrinted ? ((CardPrinted) item).getCard() : null;
}
};
/**
*
*/
public final Lambda1<T, Entry<T, Integer>> fnToPrinted =
new Lambda1<T, Entry<T, Integer>>() {
@Override public T apply(final Entry<T, Integer> from) { return from.getKey(); }
};
/**
*
*/
public final Lambda1<String, Entry<T, Integer>> fnToCardName =
new Lambda1<String, Entry<T, Integer>>() {
@Override public String apply(final Entry<T, Integer> from) { return from.getKey().getName(); }
};
/**
*
*/
public final Lambda1<Integer, Entry<T, Integer>> fnToCount =
new Lambda1<Integer, Entry<T, Integer>>() {
@Override public Integer apply(final Entry<T, Integer> from) { return from.getValue(); }
};
// Constructors
/**
*
* ItemPoolView.
* @param cls a Class<T>
*/
public ItemPoolView(final Class<T> cls) { cards = new Hashtable<T, Integer>(); myClass = cls; }
/**
*
* ItemPoolView.
* @param inMap a Map<T, Integer>
* @param cls a Class<T>
*/
public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) { cards = inMap; myClass = cls; }
// Data members
/**
*
*/
protected Map<T, Integer> cards;
/**
*
*/
protected 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)
/**
*
*/
protected List<Entry<T, Integer>> cardsListOrdered = new ArrayList<Map.Entry<T,Integer>>();
/**
*
*/
protected boolean isListInSync = false;
/**
* iterator.
* @return Iterator<Entry<T, Integer>>
*/
@Override
public final Iterator<Entry<T, Integer>> iterator() { return cards.entrySet().iterator(); }
// Cards read only operations
/**
*
* contains.
* @param card a T
* @return boolean
*/
public final boolean contains(final T card) {
if (cards == null) { return false; }
return cards.containsKey(card);
}
/**
*
* count.
* @param card a T
* @return int
*/
public final int count(final T card) {
if (cards == null) { return 0; }
Integer boxed = cards.get(card);
return boxed == null ? 0 : boxed.intValue();
}
/**
*
* countAll.
* @return int
*/
public final int countAll() {
int result = 0;
if (cards != null) { for (Integer n : cards.values()) { result += n; } }
return result;
}
/**
*
* countDistinct.
* @return int
*/
public final int countDistinct() { return cards.size(); }
/**
*
* isEmpty.
* @return boolean
*/
public final boolean isEmpty() { return cards == null || cards.isEmpty(); }
/**
*
* getOrderedList.
* @return List<Entry<T, Integer>>
*/
public final List<Entry<T, Integer>> getOrderedList() {
if (!isListInSync) { rebuildOrderedList(); }
return cardsListOrdered;
@@ -89,6 +169,11 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
isListInSync = true;
}
/**
*
* toFlatList.
* @return List<T>
*/
public final List<T> toFlatList() {
List<T> result = new ArrayList<T>();
for (Entry<T, Integer> e : this) {
@@ -97,11 +182,15 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
return result;
}
/**
*
* toForgeCardList.
* @return CardList
*/
public final CardList toForgeCardList() {
CardList result = new CardList();
for (Entry<T, Integer> e : this) {
if ( e.getKey() instanceof CardPrinted )
{
if (e.getKey() instanceof CardPrinted) {
for (int i = 0; i < e.getValue(); i++) {
result.add(((CardPrinted) e.getKey()).toForgeCard());
}

View File

@@ -21,9 +21,9 @@
<table style="font-size:10px;" border=1 cellpadding="5" cellspacing="1">
<tr>
<td width="${cardlistWidth}">
<#list nameList as name>
${name}<br>
</#list>
<#list cardList?keys as key>
${cardList[key]} ${key}<br>
</#list>
</td>
</tr>
</table>