forked from External/mage
All 1-character strings converted to primitives
"b" + "r" now changed to 'b' + 'w'. It's more straight-forward, and may cause perfomance improvements - character primitives allocation is faster and less expensive than string creation.
This commit is contained in:
parent
31589778ca
commit
f60ebfbb1f
451 changed files with 989 additions and 978 deletions
|
|
@ -22,5 +22,5 @@ public class Constants {
|
|||
String IMAGE_PROPERTIES_FILE = "image.url.properties";
|
||||
}
|
||||
|
||||
public static final String CARD_IMAGE_PATH_TEMPLATE = "." + File.separator + "plugins" + File.separator + "images/{set}/{name}.{collector}.full.jpg";
|
||||
public static final String CARD_IMAGE_PATH_TEMPLATE = '.' + File.separator + "plugins" + File.separator + "images/{set}/{name}.{collector}.full.jpg";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ public class DownloadJob extends AbstractLaternaBean {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return proxy != null ? proxy.type().toString() + " " : "" + url;
|
||||
return proxy != null ? proxy.type().toString() + ' ' : "" + url;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -196,7 +196,7 @@ public class DownloadJob extends AbstractLaternaBean {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return proxy != null ? proxy.type().toString() + " " : "" + url;
|
||||
return proxy != null ? proxy.type().toString() + ' ' : "" + url;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ public class CardFrames implements Iterable<DownloadJob> {
|
|||
|
||||
private DownloadJob generateDownloadJob(String dirName, String name) {
|
||||
File dst = new File(outDir, name + ".png");
|
||||
String url = BASE_DOWNLOAD_URL + dirName + "/" + name + ".png";
|
||||
return new DownloadJob("frames-" + dirName + "-" + name, fromURL(url), toFile(dst));
|
||||
String url = BASE_DOWNLOAD_URL + dirName + '/' + name + ".png";
|
||||
return new DownloadJob("frames-" + dirName + '-' + name, fromURL(url), toFile(dst));
|
||||
}
|
||||
|
||||
private void useDefaultDir() {
|
||||
|
|
|
|||
|
|
@ -163,12 +163,12 @@ public class GathererSets implements Iterable<DownloadJob> {
|
|||
}
|
||||
|
||||
private DownloadJob generateDownloadJob(String set, String rarity, String urlRarity) {
|
||||
File dst = new File(outDir, set + "-" + rarity + ".jpg");
|
||||
File dst = new File(outDir, set + '-' + rarity + ".jpg");
|
||||
if (symbolsReplacements.containsKey(set)) {
|
||||
set = symbolsReplacements.get(set);
|
||||
}
|
||||
String url = "http://gatherer.wizards.com/Handlers/Image.ashx?type=symbol&set=" + set + "&size=small&rarity=" + urlRarity;
|
||||
return new DownloadJob(set + "-" + rarity, fromURL(url), toFile(dst));
|
||||
return new DownloadJob(set + '-' + rarity, fromURL(url), toFile(dst));
|
||||
}
|
||||
|
||||
private void changeOutDir(String path) {
|
||||
|
|
|
|||
|
|
@ -54,62 +54,64 @@ public class GathererSymbols implements Iterable<DownloadJob> {
|
|||
|
||||
@Override
|
||||
protected DownloadJob computeNext() {
|
||||
String sym;
|
||||
if (symIndex < symbols.length) {
|
||||
sym = symbols[symIndex++];
|
||||
} else if (numeric <= maxNumeric) {
|
||||
sym = "" + (numeric++);
|
||||
} else {
|
||||
sizeIndex++;
|
||||
if (sizeIndex == sizes.length) {
|
||||
return endOfData();
|
||||
while (true) {
|
||||
String sym;
|
||||
if (symIndex < symbols.length) {
|
||||
sym = symbols[symIndex++];
|
||||
} else if (numeric <= maxNumeric) {
|
||||
sym = "" + (numeric++);
|
||||
} else {
|
||||
sizeIndex++;
|
||||
if (sizeIndex == sizes.length) {
|
||||
return endOfData();
|
||||
}
|
||||
|
||||
symIndex = 0;
|
||||
numeric = 0;
|
||||
dir = new File(outDir, sizes[sizeIndex]);
|
||||
continue;
|
||||
}
|
||||
String symbol = sym.replaceAll("/", "");
|
||||
File dst = new File(dir, symbol + ".gif");
|
||||
|
||||
/**
|
||||
* Handle a bug on Gatherer where a few symbols are missing at the large size.
|
||||
* Fall back to using the medium symbol for those cases.
|
||||
*/
|
||||
int modSizeIndex = sizeIndex;
|
||||
if (sizeIndex == 2) {
|
||||
switch (sym) {
|
||||
case "WP":
|
||||
case "UP":
|
||||
case "BP":
|
||||
case "RP":
|
||||
case "GP":
|
||||
case "E":
|
||||
case "C":
|
||||
modSizeIndex = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Nothing to do, symbol is available in the large size
|
||||
}
|
||||
}
|
||||
|
||||
symIndex = 0;
|
||||
numeric = 0;
|
||||
dir = new File(outDir, sizes[sizeIndex]);
|
||||
return computeNext();
|
||||
}
|
||||
String symbol = sym.replaceAll("/", "");
|
||||
File dst = new File(dir, symbol + ".gif");
|
||||
|
||||
/**
|
||||
* Handle a bug on Gatherer where a few symbols are missing at the large size.
|
||||
* Fall back to using the medium symbol for those cases.
|
||||
*/
|
||||
int modSizeIndex = sizeIndex;
|
||||
if (sizeIndex == 2) {
|
||||
switch (sym) {
|
||||
case "WP":
|
||||
case "UP":
|
||||
case "BP":
|
||||
case "RP":
|
||||
case "GP":
|
||||
case "E":
|
||||
case "C":
|
||||
modSizeIndex = 1;
|
||||
switch (symbol) {
|
||||
case "T":
|
||||
symbol = "tap";
|
||||
break;
|
||||
case "Q":
|
||||
symbol = "untap";
|
||||
break;
|
||||
case "S":
|
||||
symbol = "snow";
|
||||
break;
|
||||
|
||||
default:
|
||||
// Nothing to do, symbol is available in the large size
|
||||
}
|
||||
|
||||
String url = format(urlFmt, sizes[modSizeIndex], symbol);
|
||||
|
||||
return new DownloadJob(sym, fromURL(url), toFile(dst));
|
||||
}
|
||||
|
||||
switch (symbol) {
|
||||
case "T":
|
||||
symbol = "tap";
|
||||
break;
|
||||
case "Q":
|
||||
symbol = "untap";
|
||||
break;
|
||||
case "S":
|
||||
symbol = "snow";
|
||||
break;
|
||||
}
|
||||
|
||||
String url = format(urlFmt, sizes[modSizeIndex], symbol);
|
||||
|
||||
return new DownloadJob(sym, fromURL(url), toFile(dst));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,20 +174,20 @@ public class MagicCardsImageSource implements CardImageSource {
|
|||
|
||||
String preferedLanguage = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PREF_LANGUAGE, "en");
|
||||
|
||||
StringBuilder url = new StringBuilder("http://magiccards.info/scans/").append(preferedLanguage).append("/");
|
||||
url.append(set.toLowerCase()).append("/").append(collectorId);
|
||||
StringBuilder url = new StringBuilder("http://magiccards.info/scans/").append(preferedLanguage).append('/');
|
||||
url.append(set.toLowerCase()).append('/').append(collectorId);
|
||||
|
||||
if (card.isTwoFacedCard()) {
|
||||
url.append(card.isSecondSide() ? "b" : "a");
|
||||
}
|
||||
if (card.isSplitCard()) {
|
||||
url.append("a");
|
||||
url.append('a');
|
||||
}
|
||||
if (card.isFlipCard()) {
|
||||
if (card.isFlippedSide()) { // download rotated by 180 degree image
|
||||
url.append("b");
|
||||
url.append('b');
|
||||
} else {
|
||||
url.append("a");
|
||||
url.append('a');
|
||||
}
|
||||
}
|
||||
url.append(".jpg");
|
||||
|
|
@ -200,16 +200,16 @@ public class MagicCardsImageSource implements CardImageSource {
|
|||
String name = card.getName();
|
||||
// add type to name if it's not 0
|
||||
if (card.getType() > 0) {
|
||||
name = name + " " + card.getType();
|
||||
name = name + ' ' + card.getType();
|
||||
}
|
||||
name = name.replaceAll(" ", "-").replace(",", "").toLowerCase();
|
||||
String set = "not-supported-set";
|
||||
if (setNameTokenReplacement.containsKey(card.getSet())) {
|
||||
set = setNameTokenReplacement.get(card.getSet());
|
||||
} else {
|
||||
set += "-" + card.getSet();
|
||||
set += '-' + card.getSet();
|
||||
}
|
||||
return "http://magiccards.info/extras/token/" + set + "/" + name + ".jpg";
|
||||
return "http://magiccards.info/extras/token/" + set + '/' + name + ".jpg";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class MagidexImageSource implements CardImageSource {
|
|||
}
|
||||
|
||||
// This will properly escape the url
|
||||
URI uri = new URI("http", "magidex.com", "/extstatic/card/" + cardSet + "/" + cardDownloadName + ".jpg", null, null);
|
||||
URI uri = new URI("http", "magidex.com", "/extstatic/card/" + cardSet + '/' + cardDownloadName + ".jpg", null, null);
|
||||
return uri.toASCIIString();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class MtgImageSource implements CardImageSource {
|
|||
throw new Exception("Wrong parameters for image: collector id: " + collectorId + ",card set: " + cardSet);
|
||||
}
|
||||
StringBuilder url = new StringBuilder("http://mtgimage.com/set/");
|
||||
url.append(cardSet.toUpperCase()).append("/");
|
||||
url.append(cardSet.toUpperCase()).append('/');
|
||||
|
||||
if (card.isSplitCard()) {
|
||||
url.append(card.getDownloadName().replaceAll(" // ", ""));
|
||||
|
|
@ -86,9 +86,9 @@ public class MtgImageSource implements CardImageSource {
|
|||
}
|
||||
if (card.isFlipCard()) {
|
||||
if (card.isFlippedSide()) { // download rotated by 180 degree image
|
||||
url.append("b");
|
||||
url.append('b');
|
||||
} else {
|
||||
url.append("a");
|
||||
url.append('a');
|
||||
}
|
||||
}
|
||||
url.append(".jpg");
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class MythicspoilerComSource implements CardImageSource {
|
|||
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||
for (String setName : setNames.split("\\^")) {
|
||||
String URLSetName = URLEncoder.encode(setName, "UTF-8");
|
||||
String baseUrl = "http://mythicspoiler.com/" + URLSetName + "/";
|
||||
String baseUrl = "http://mythicspoiler.com/" + URLSetName + '/';
|
||||
|
||||
Map<String, String> pageLinks = getSetLinksFromPage(cardSet, aliasesStart, prefs, proxyType, baseUrl, baseUrl);
|
||||
setLinks.putAll(pageLinks);
|
||||
|
|
@ -166,7 +166,7 @@ public class MythicspoilerComSource implements CardImageSource {
|
|||
Elements cardsImages = doc.select("img[src^=cards/]"); // starts with cards/
|
||||
if (!aliasesStart.isEmpty()) {
|
||||
for (String text : aliasesStart) {
|
||||
cardsImages.addAll(doc.select("img[src^=" + text + "]"));
|
||||
cardsImages.addAll(doc.select("img[src^=" + text + ']'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -179,8 +179,8 @@ public class MythicspoilerComSource implements CardImageSource {
|
|||
cardName = cardLink.substring(0, cardLink.length() - 4);
|
||||
}
|
||||
if (cardName != null && !cardName.isEmpty()) {
|
||||
if (cardNameAliases.containsKey(cardSet + "-" + cardName)) {
|
||||
cardName = cardNameAliases.get(cardSet + "-" + cardName);
|
||||
if (cardNameAliases.containsKey(cardSet + '-' + cardName)) {
|
||||
cardName = cardNameAliases.get(cardSet + '-' + cardName);
|
||||
} else if (cardName.endsWith("1") || cardName.endsWith("2") || cardName.endsWith("3") || cardName.endsWith("4") || cardName.endsWith("5")) {
|
||||
if (!cardName.startsWith("forest")
|
||||
&& !cardName.startsWith("swamp")
|
||||
|
|
|
|||
|
|
@ -162,19 +162,19 @@ public class TokensMtgImageSource implements CardImageSource {
|
|||
TokenData tokenData;
|
||||
if (type == 0) {
|
||||
if (matchedTokens.size() > 1) {
|
||||
logger.info("Multiple images were found for token " + name + ", set " + set + ".");
|
||||
logger.info("Multiple images were found for token " + name + ", set " + set + '.');
|
||||
}
|
||||
tokenData = matchedTokens.get(0);
|
||||
} else {
|
||||
if (type > matchedTokens.size()) {
|
||||
logger.warn("Not enough images for token with type " + type + ", name " + name + ", set " + set + ".");
|
||||
logger.warn("Not enough images for token with type " + type + ", name " + name + ", set " + set + '.');
|
||||
return null;
|
||||
}
|
||||
tokenData = matchedTokens.get(card.getType() - 1);
|
||||
}
|
||||
|
||||
String url = "http://tokens.mtg.onl/tokens/" + tokenData.getExpansionSetCode().trim() + "_"
|
||||
+ tokenData.getNumber().trim() + "-" + tokenData.getName().trim() + ".jpg";
|
||||
String url = "http://tokens.mtg.onl/tokens/" + tokenData.getExpansionSetCode().trim() + '_'
|
||||
+ tokenData.getNumber().trim() + '-' + tokenData.getName().trim() + ".jpg";
|
||||
url = url.replace(' ', '-');
|
||||
return url;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -410,11 +410,11 @@ public class WizardCardsImageSource implements CardImageSource {
|
|||
private String normalizeName(String name) {
|
||||
//Split card
|
||||
if(name.contains("//")) {
|
||||
name = name.substring(0, name.indexOf("(") - 1);
|
||||
name = name.substring(0, name.indexOf('(') - 1);
|
||||
}
|
||||
//Special timeshifted name
|
||||
if(name.startsWith("XX")) {
|
||||
name = name.substring(name.indexOf("(") + 1, name.length() - 1);
|
||||
name = name.substring(name.indexOf('(') + 1, name.length() - 1);
|
||||
}
|
||||
return name.replace("\u2014", "-").replace("\u2019", "'")
|
||||
.replace("\u00C6", "AE").replace("\u00E6", "ae")
|
||||
|
|
@ -456,7 +456,7 @@ public class WizardCardsImageSource implements CardImageSource {
|
|||
} else {
|
||||
link = setLinks.get(Integer.toString(number - 21));
|
||||
if (link != null) {
|
||||
link = link.replace(Integer.toString(number - 20), (Integer.toString(number - 20) + "a"));
|
||||
link = link.replace(Integer.toString(number - 20), (Integer.toString(number - 20) + 'a'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -325,12 +325,12 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
|
||||
int tokenImages = 0;
|
||||
for (CardDownloadData card : cardsToDownload) {
|
||||
logger.debug((card.isToken() ? "Token" : "Card") + " image to download: " + card.getName() + " (" + card.getSet() + ")");
|
||||
logger.debug((card.isToken() ? "Token" : "Card") + " image to download: " + card.getName() + " (" + card.getSet() + ')');
|
||||
if (card.isToken()) {
|
||||
tokenImages++;
|
||||
}
|
||||
}
|
||||
logger.info("Check download images (total card images: " + numberCardImages + ", total token images: " + numberAllTokenImages + ")");
|
||||
logger.info("Check download images (total card images: " + numberCardImages + ", total token images: " + numberAllTokenImages + ')');
|
||||
logger.info(" => Missing card images: " + (cardsToDownload.size() - tokenImages));
|
||||
logger.info(" => Missing token images: " + tokenImages);
|
||||
return new ArrayList<>(cardsToDownload);
|
||||
|
|
@ -445,7 +445,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
|
||||
CardDownloadData card = cardsToDownload.get(i);
|
||||
|
||||
logger.debug("Downloading card: " + card.getName() + " (" + card.getSet() + ")");
|
||||
logger.debug("Downloading card: " + card.getName() + " (" + card.getSet() + ')');
|
||||
|
||||
String url;
|
||||
if (ignoreUrls.contains(card.getSet()) || card.isToken()) {
|
||||
|
|
@ -470,7 +470,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
} catch (Exception ex) {
|
||||
}
|
||||
} else if (cardImageSource.getTotalImages() == -1) {
|
||||
logger.info("Card not available on " + cardImageSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ")");
|
||||
logger.info("Card not available on " + cardImageSource.getSourceName() + ": " + card.getName() + " (" + card.getSet() + ')');
|
||||
synchronized (sync) {
|
||||
update(cardIndex + 1, cardsToDownload.size());
|
||||
}
|
||||
|
|
@ -540,7 +540,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
try {
|
||||
filePath.append(Constants.IO.imageBaseDir);
|
||||
if (!useSpecifiedPaths && card != null) {
|
||||
filePath.append(card.hashCode()).append(".").append(card.getName().replace(":", "").replace("//", "-")).append(".jpg");
|
||||
filePath.append(card.hashCode()).append('.').append(card.getName().replace(":", "").replace("//", "-")).append(".jpg");
|
||||
temporaryFile = new File(filePath.toString());
|
||||
}
|
||||
String imagePath;
|
||||
|
|
@ -650,7 +650,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
if (card != null && !useSpecifiedPaths) {
|
||||
logger.warn("Image download for " + card.getName()
|
||||
+ (!card.getDownloadName().equals(card.getName()) ? " downloadname: " + card.getDownloadName() : "")
|
||||
+ "(" + card.getSet() + ") failed - responseCode: " + responseCode + " url: " + url.toString());
|
||||
+ '(' + card.getSet() + ") failed - responseCode: " + responseCode + " url: " + url.toString());
|
||||
}
|
||||
if (logger.isDebugEnabled()) { // Shows the returned html from the request to the web server
|
||||
logger.debug("Returned HTML ERROR:\n" + convertStreamToString(((HttpURLConnection) httpConn).getErrorStream()));
|
||||
|
|
@ -658,7 +658,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
}
|
||||
|
||||
} catch (AccessDeniedException e) {
|
||||
logger.error("The file " + (outputFile != null ? outputFile.toString() : "to add the image of " + card.getName() + "(" + card.getSet() + ")") + " can't be accessed. Try rebooting your system to remove the file lock.");
|
||||
logger.error("The file " + (outputFile != null ? outputFile.toString() : "to add the image of " + card.getName() + '(' + card.getSet() + ')') + " can't be accessed. Try rebooting your system to remove the file lock.");
|
||||
} catch (Exception e) {
|
||||
logger.error(e, e);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -255,11 +255,11 @@ public class ImageCache {
|
|||
* Returns the map key for a card, without any suffixes for the image size.
|
||||
*/
|
||||
private static String getKey(CardView card, String name, String suffix) {
|
||||
return name + "#" + card.getExpansionSetCode() + "#" + card.getType() + "#" + card.getCardNumber() + "#"
|
||||
return name + '#' + card.getExpansionSetCode() + '#' + card.getType() + '#' + card.getCardNumber() + '#'
|
||||
+ (card.getTokenSetCode() == null ? "" : card.getTokenSetCode())
|
||||
+ suffix
|
||||
+ (card.getUsesVariousArt() ? "#usesVariousArt" : "")
|
||||
+ (card.getTokenDescriptor() != null ? "#" + card.getTokenDescriptor() : "#");
|
||||
+ (card.getTokenDescriptor() != null ? '#' + card.getTokenDescriptor() : "#");
|
||||
}
|
||||
|
||||
// /**
|
||||
|
|
|
|||
|
|
@ -168,11 +168,11 @@ public class CardImageUtils {
|
|||
String imageDir = getImageDir(card, imagesPath);
|
||||
String imageName;
|
||||
|
||||
String type = card.getType() != 0 ? " " + Integer.toString(card.getType()) : "";
|
||||
String type = card.getType() != 0 ? ' ' + Integer.toString(card.getType()) : "";
|
||||
String name = card.getFileName().isEmpty() ? card.getName().replace(":", "").replace("//", "-") : card.getFileName();
|
||||
|
||||
if (card.getUsesVariousArt()) {
|
||||
imageName = name + "." + card.getCollectorId() + ".full.jpg";
|
||||
imageName = name + '.' + card.getCollectorId() + ".full.jpg";
|
||||
} else {
|
||||
imageName = name + type + ".full.jpg";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue