adressing issue from http://www.slightlymagic.net/forum/posting.php?mode=quote&f=26&p=69462 (if a card has blank value set that caused an exception)

This commit is contained in:
Maxmtg
2011-09-04 17:14:37 +00:00
parent 150a4dc136
commit 3756976bf5

View File

@@ -102,9 +102,17 @@ public final class CardDb {
public CardPrinted getCard(final String name) { public CardPrinted getCard(final String name) {
// Sometimes they read from decks things like "CardName|Set" - but we can handle it // Sometimes they read from decks things like "CardName|Set" - but we can handle it
int pipePos = name.indexOf('|'); int pipePos = name.indexOf('|');
if (pipePos >= 0) { return getCard(name.substring(0, pipePos), name.substring(pipePos + 1)); } String cardName = name;
if (pipePos >= 0) {
cardName = name.substring(0, pipePos);
String setName = name.substring(pipePos + 1);
// only if set is not blank try to load it
if (StringUtils.isNotBlank(setName)) {
return getCard(cardName, setName);
}
}
// OK, plain name here // OK, plain name here
CardPrinted card = uniqueCards.get(name); CardPrinted card = uniqueCards.get(cardName);
if (card != null) { return card; } if (card != null) { return card; }
throw new NoSuchElementException(String.format("Card '%s' not found in our database.", name)); throw new NoSuchElementException(String.format("Card '%s' not found in our database.", name));
} }