carddb: support for getting foiled cards

This commit is contained in:
Maxmtg
2013-02-19 22:35:30 +00:00
parent 71c8f7a8a9
commit 21ca48e4e1

View File

@@ -54,6 +54,7 @@ public final class CardDb {
private static volatile CardDb commonCards = null; // 'volatile' keyword makes this working
private static volatile CardDb variantCards = null; // 'volatile' keyword makes this working
private final String foilSuffix = " foil";
private final int foilSuffixLength = foilSuffix.length();
/**
* Instance.
@@ -141,7 +142,7 @@ public final class CardDb {
}
private boolean isFoil(final String cardName) {
return cardName.toLowerCase().endsWith(this.foilSuffix) && (cardName.length() > 5);
return cardName.toLowerCase().endsWith(this.foilSuffix) && (cardName.length() > this.foilSuffixLength);
}
/**
@@ -151,7 +152,7 @@ public final class CardDb {
* @return the string
*/
public String removeFoilSuffix(final String cardName) {
return cardName.substring(0, cardName.length() - 5);
return cardName.substring(0, cardName.length() - this.foilSuffixLength);
}
/**
@@ -172,7 +173,12 @@ public final class CardDb {
if (nameWithSet.right == null) {
return this.uniqueCards.get(nameWithSet.left);
}
return tryGetCard(nameWithSet.left, nameWithSet.right);
CardPrinted res = tryGetCard(nameWithSet.left, nameWithSet.right);
if ( null != res && isFoil )
return CardPrinted.makeFoiled(res);
return res;
}
public CardPrinted tryGetCard(final String cardName, String setName) {