mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
- CheckStyle.
This commit is contained in:
@@ -48,7 +48,7 @@ import forge.card.MtgDataParser;
|
|||||||
public final class CardDb {
|
public final class CardDb {
|
||||||
private static volatile CardDb onlyInstance = null; // 'volatile' keyword
|
private static volatile CardDb onlyInstance = null; // 'volatile' keyword
|
||||||
// makes this working
|
// makes this working
|
||||||
private final String FOIL_SUFFIX = " foil";
|
private final String FOIL_SUFFIX = " foil";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance.
|
* Instance.
|
||||||
@@ -178,7 +178,7 @@ public final class CardDb {
|
|||||||
private static ImmutablePair<String, String> splitCardName(final String name) {
|
private static ImmutablePair<String, String> splitCardName(final String name) {
|
||||||
String cardName = name; // .trim() ?
|
String cardName = name; // .trim() ?
|
||||||
final int pipePos = cardName.indexOf('|');
|
final int pipePos = cardName.indexOf('|');
|
||||||
|
|
||||||
if (pipePos >= 0) {
|
if (pipePos >= 0) {
|
||||||
final String setName = cardName.substring(pipePos + 1).trim();
|
final String setName = cardName.substring(pipePos + 1).trim();
|
||||||
cardName = cardName.substring(0, pipePos);
|
cardName = cardName.substring(0, pipePos);
|
||||||
@@ -190,20 +190,18 @@ public final class CardDb {
|
|||||||
return new ImmutablePair<String, String>(cardName, null);
|
return new ImmutablePair<String, String>(cardName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFoil(String cardName)
|
private boolean isFoil(String cardName) {
|
||||||
{
|
|
||||||
return cardName.toLowerCase().endsWith(FOIL_SUFFIX) && cardName.length() > 5;
|
return cardName.toLowerCase().endsWith(FOIL_SUFFIX) && cardName.length() > 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String removeFoilSuffix(String cardName)
|
public String removeFoilSuffix(String cardName) {
|
||||||
{
|
|
||||||
return cardName.substring(0, cardName.length() - 5);
|
return cardName.substring(0, cardName.length() - 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is card supported.
|
* Checks if is card supported.
|
||||||
*
|
*
|
||||||
* @param cardName
|
* @param cardName0
|
||||||
* the card name
|
* the card name
|
||||||
* @return true, if is card supported
|
* @return true, if is card supported
|
||||||
*/
|
*/
|
||||||
@@ -325,8 +323,8 @@ public final class CardDb {
|
|||||||
result.add(this.getCard(name, true));
|
result.add(this.getCard(name, true));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a list of all cards from their respective latest editions
|
// returns a list of all cards from their respective latest editions
|
||||||
/**
|
/**
|
||||||
* Gets the all unique cards.
|
* Gets the all unique cards.
|
||||||
@@ -352,41 +350,44 @@ public final class CardDb {
|
|||||||
public CardPrinted getCard(String name0, boolean fromLatestSet) {
|
public CardPrinted getCard(String name0, boolean fromLatestSet) {
|
||||||
// Sometimes they read from decks things like "CardName|Set" - but we
|
// Sometimes they read from decks things like "CardName|Set" - but we
|
||||||
// can handle it
|
// can handle it
|
||||||
|
|
||||||
boolean isFoil = isFoil(name0);
|
boolean isFoil = isFoil(name0);
|
||||||
String name = isFoil ? removeFoilSuffix(name0) : name0;
|
String name = isFoil ? removeFoilSuffix(name0) : name0;
|
||||||
CardPrinted result = null;
|
CardPrinted result = null;
|
||||||
|
|
||||||
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(name);
|
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(name);
|
||||||
if (nameWithSet.right != null) {
|
if (nameWithSet.right != null) {
|
||||||
result = this.getCard(nameWithSet.left, nameWithSet.right);
|
result = this.getCard(nameWithSet.left, nameWithSet.right);
|
||||||
} else {
|
} else {
|
||||||
if( !fromLatestSet ) {
|
if (!fromLatestSet) {
|
||||||
result = this.uniqueCards.get(nameWithSet.left.toLowerCase());
|
result = this.uniqueCards.get(nameWithSet.left.toLowerCase());
|
||||||
if ( null == result )
|
if (null == result) {
|
||||||
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));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// OK, plain name here
|
// OK, plain name here
|
||||||
Predicate<CardPrinted> predicate = CardPrinted.Predicates.name(nameWithSet.left);
|
Predicate<CardPrinted> predicate = CardPrinted.Predicates.name(nameWithSet.left);
|
||||||
List<CardPrinted> namedCards = predicate.select(this.allCardsFlat);
|
List<CardPrinted> namedCards = predicate.select(this.allCardsFlat);
|
||||||
if ( namedCards.isEmpty() )
|
if (namedCards.isEmpty()) {
|
||||||
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));
|
||||||
|
}
|
||||||
|
|
||||||
// Find card with maximal set index
|
// Find card with maximal set index
|
||||||
result = namedCards.get(0);
|
result = namedCards.get(0);
|
||||||
int resIndex = SetUtils.getSetByCode((result).getSet()).getIndex();
|
int resIndex = SetUtils.getSetByCode((result).getSet()).getIndex();
|
||||||
for(CardPrinted card : namedCards)
|
for (CardPrinted card : namedCards) {
|
||||||
{
|
|
||||||
int thisIndex = SetUtils.getSetByCode((card).getSet()).getIndex();
|
int thisIndex = SetUtils.getSetByCode((card).getSet()).getIndex();
|
||||||
if ( thisIndex > resIndex ) {
|
if (thisIndex > resIndex) {
|
||||||
result = card;
|
result = card;
|
||||||
resIndex = thisIndex;
|
resIndex = thisIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( isFoil )
|
if (isFoil) {
|
||||||
result = CardPrinted.makeFoiled(result);
|
result = CardPrinted.makeFoiled(result);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import forge.util.SectionUtil;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class PreconDeck implements InventoryItemFromSet {
|
public class PreconDeck implements InventoryItemFromSet {
|
||||||
|
|
||||||
private final Deck deck;
|
private final Deck deck;
|
||||||
private final String imageFilename;
|
private final String imageFilename;
|
||||||
private final String set;
|
private final String set;
|
||||||
@@ -39,25 +39,26 @@ public class PreconDeck implements InventoryItemFromSet {
|
|||||||
return "Prebuilt Deck";
|
return "Prebuilt Deck";
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreconDeck(final File f)
|
public PreconDeck(final File f) {
|
||||||
{
|
|
||||||
List<String> deckLines = FileUtil.readFile(f);
|
List<String> deckLines = FileUtil.readFile(f);
|
||||||
Map<String, List<String>> sections = SectionUtil.parseSections(deckLines);
|
Map<String, List<String>> sections = SectionUtil.parseSections(deckLines);
|
||||||
deck = DeckIO.readDeck(deckLines);
|
deck = DeckIO.readDeck(deckLines);
|
||||||
|
|
||||||
String filenameProxy = null;
|
String filenameProxy = null;
|
||||||
String setProxy = "n/a";
|
String setProxy = "n/a";
|
||||||
List<String> metadata = sections.get("metadata");
|
List<String> metadata = sections.get("metadata");
|
||||||
if ( null != metadata && !metadata.isEmpty() ) for(String s : metadata) {
|
if (null != metadata && !metadata.isEmpty()) for (String s : metadata) {
|
||||||
String[] kv = s.split("=");
|
String[] kv = s.split("=");
|
||||||
if( "Image".equalsIgnoreCase(kv[0]))
|
if ("Image".equalsIgnoreCase(kv[0])) {
|
||||||
filenameProxy = kv[1];
|
filenameProxy = kv[1];
|
||||||
if( "set".equalsIgnoreCase(kv[0]) && SetUtils.getSetByCode(kv[1].toUpperCase()) != null )
|
}
|
||||||
|
if ("set".equalsIgnoreCase(kv[0]) && SetUtils.getSetByCode(kv[1].toUpperCase()) != null) {
|
||||||
setProxy = kv[1];
|
setProxy = kv[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
imageFilename = filenameProxy;
|
imageFilename = filenameProxy;
|
||||||
set = setProxy;
|
set = setProxy;
|
||||||
recommendedDeals = new SellRules(sections.get("shop"));
|
recommendedDeals = new SellRules(sections.get("shop"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user