Fixed some exception problems (deck layout, mana symbols).

This commit is contained in:
LevelX2 2016-10-04 23:57:11 +02:00
parent db31264538
commit 7c4b40073c
3 changed files with 47 additions and 49 deletions

View file

@ -1,16 +1,16 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,18 +20,16 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.cards;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.*;
import mage.cards.decks.DeckCardInfo;
import mage.cards.decks.DeckCardLayout;
import mage.cards.decks.DeckCardLists;
@ -41,7 +39,6 @@ import mage.cards.repository.CardRepository;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.util.ClassScanner;
import mage.util.RandomUtil;
import org.apache.log4j.Logger;
@ -52,7 +49,7 @@ import org.apache.log4j.Logger;
public class Sets extends HashMap<String, ExpansionSet> {
private static final Logger logger = Logger.getLogger(Sets.class);
private static final Sets fINSTANCE = new Sets();
private static final Sets fINSTANCE = new Sets();
public static Sets getInstance() {
return fINSTANCE;
@ -72,9 +69,13 @@ public class Sets extends HashMap<String, ExpansionSet> {
}
public void addSet(ExpansionSet set) {
if(containsKey(set.getCode())) throw new IllegalArgumentException("Set code "+set.getCode()+" already exists.");
if (containsKey(set.getCode())) {
throw new IllegalArgumentException("Set code " + set.getCode() + " already exists.");
}
this.put(set.getCode(), set);
if(set.isCustomSet()) customSets.add(set.getCode());
if (set.isCustomSet()) {
customSets.add(set.getCode());
}
}
public static boolean isCustomSet(String setCode) {
@ -82,7 +83,8 @@ public class Sets extends HashMap<String, ExpansionSet> {
}
/**
* Generates card pool of cardsCount cards that have manacost of allowed colors.
* Generates card pool of cardsCount cards that have manacost of allowed
* colors.
*
* @param cardsCount
* @param allowedColors
@ -149,29 +151,27 @@ public class Sets extends HashMap<String, ExpansionSet> {
if (deck.getAuthor() != null && deck.getAuthor().length() > 0) {
out.println("AUTHOR:" + deck.getAuthor());
}
for (DeckCardInfo deckCardInfo: deck.getCards()) {
for (DeckCardInfo deckCardInfo : deck.getCards()) {
if (deckCards.containsKey(deckCardInfo.getCardKey())) {
deckCards.put(deckCardInfo.getCardKey(), deckCards.get(deckCardInfo.getCardKey()).increaseQuantity());
}
else {
} else {
deckCards.put(deckCardInfo.getCardKey(), deckCardInfo);
}
}
for (DeckCardInfo deckCardInfo: deck.getSideboard()) {
for (DeckCardInfo deckCardInfo : deck.getSideboard()) {
if (sideboard.containsKey(deckCardInfo.getCardKey())) {
sideboard.put(deckCardInfo.getCardKey(), sideboard.get(deckCardInfo.getCardKey()).increaseQuantity());
}
else {
} else {
sideboard.put(deckCardInfo.getCardKey(), deckCardInfo);
}
}
// Write out all of the cards
for (Map.Entry<String, DeckCardInfo> entry: deckCards.entrySet()) {
for (Map.Entry<String, DeckCardInfo> entry : deckCards.entrySet()) {
out.printf("%d [%s:%s] %s%n", entry.getValue().getQuantity(), entry.getValue().getSetCode(), entry.getValue().getCardNum(), entry.getValue().getCardName());
}
for (Map.Entry<String, DeckCardInfo> entry: sideboard.entrySet()) {
for (Map.Entry<String, DeckCardInfo> entry : sideboard.entrySet()) {
out.printf("SB: %d [%s:%s] %s%n", entry.getValue().getQuantity(), entry.getValue().getSetCode(), entry.getValue().getCardNum(), entry.getValue().getCardName());
}
@ -182,13 +182,15 @@ public class Sets extends HashMap<String, ExpansionSet> {
out.print("LAYOUT SIDEBOARD:");
writeCardLayout(out, deck.getSideboardLayout());
out.print("\n");
}
finally {
} finally {
out.close();
}
}
private static void writeCardLayout(PrintWriter out, DeckCardLayout layout) {
if (layout == null) {
return;
}
List<List<List<DeckCardInfo>>> cardGrid = layout.getCards();
int height = cardGrid.size();
int width = (height > 0) ? cardGrid.get(0).size() : 0;