mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
Make the implementations of CardImageSource an enum
This commit is contained in:
parent
3f47d5a253
commit
05785f71b9
11 changed files with 36 additions and 96 deletions
|
@ -37,19 +37,12 @@ import java.util.HashMap;
|
|||
*
|
||||
* @author spjspj
|
||||
*/
|
||||
public class AltMtgOnlTokensImageSource implements CardImageSource {
|
||||
public enum AltMtgOnlTokensImageSource implements CardImageSource {
|
||||
|
||||
instance;
|
||||
private static final Logger logger = Logger.getLogger(AltMtgOnlTokensImageSource.class);
|
||||
private static CardImageSource instance = new AltMtgOnlTokensImageSource();
|
||||
private static int maxTimes = 0;
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new AltMtgOnlTokensImageSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "http://alternative.mtg.onl/tokens/";
|
||||
|
|
|
@ -37,19 +37,12 @@ import org.mage.plugins.card.images.CardDownloadData;
|
|||
*
|
||||
* @author spjspj
|
||||
*/
|
||||
public class GrabbagImageSource implements CardImageSource {
|
||||
public enum GrabbagImageSource implements CardImageSource {
|
||||
|
||||
instance;
|
||||
private static final Logger logger = Logger.getLogger(GrabbagImageSource.class);
|
||||
private static CardImageSource instance = new GrabbagImageSource();
|
||||
private static int maxTimes = 0;
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new GrabbagImageSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "";
|
||||
|
|
|
@ -10,10 +10,9 @@ import org.mage.plugins.card.utils.CardImageUtils;
|
|||
*
|
||||
* @author North
|
||||
*/
|
||||
public class MagicCardsImageSource implements CardImageSource {
|
||||
|
||||
private static CardImageSource instance = new MagicCardsImageSource();
|
||||
public enum MagicCardsImageSource implements CardImageSource {
|
||||
|
||||
instance;
|
||||
private static final Map<String, String> setNameTokenReplacement = new HashMap<String, String>() {
|
||||
{
|
||||
put("10E", "tenth-edition");
|
||||
|
@ -146,12 +145,6 @@ public class MagicCardsImageSource implements CardImageSource {
|
|||
return "magiccards.info";
|
||||
}
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MagicCardsImageSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNextHttpImageUrl() {
|
||||
|
|
|
@ -36,15 +36,9 @@ import java.net.URI;
|
|||
* @author Pete Rossi
|
||||
*/
|
||||
|
||||
public class MagidexImageSource implements CardImageSource {
|
||||
private static CardImageSource instance = new MagidexImageSource();
|
||||
public enum MagidexImageSource implements CardImageSource {
|
||||
instance;
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MagidexImageSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "magidex.com";
|
||||
|
|
|
@ -39,16 +39,9 @@ import org.mage.plugins.card.images.CardDownloadData;
|
|||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class MtgImageSource implements CardImageSource {
|
||||
public enum MtgImageSource implements CardImageSource {
|
||||
|
||||
private static CardImageSource instance = new MtgImageSource();
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MtgImageSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
|
|
|
@ -37,19 +37,12 @@ import java.util.HashMap;
|
|||
*
|
||||
* @author spjspj
|
||||
*/
|
||||
public class MtgOnlTokensImageSource implements CardImageSource {
|
||||
public enum MtgOnlTokensImageSource implements CardImageSource {
|
||||
|
||||
instance;
|
||||
private static final Logger logger = Logger.getLogger(MtgOnlTokensImageSource.class);
|
||||
private static CardImageSource instance = new MtgOnlTokensImageSource();
|
||||
private static int maxTimes = 0;
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MtgOnlTokensImageSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "http://mtg.onl/token-list/tokens/";
|
||||
|
|
|
@ -54,27 +54,21 @@ import org.mage.plugins.card.images.CardDownloadData;
|
|||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class MythicspoilerComSource implements CardImageSource {
|
||||
public enum MythicspoilerComSource implements CardImageSource {
|
||||
|
||||
private static CardImageSource instance;
|
||||
private static Map<String, String> setsAliases;
|
||||
private static Map<String, String> cardNameAliases;
|
||||
private static Map<String, Set<String>> cardNameAliasesStart;
|
||||
instance;
|
||||
private Map<String, String> setsAliases;
|
||||
private Map<String, String> cardNameAliases;
|
||||
private Map<String, Set<String>> cardNameAliasesStart;
|
||||
private final Map<String, Map<String, String>> sets;
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MythicspoilerComSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "mythicspoiler.com";
|
||||
}
|
||||
|
||||
public MythicspoilerComSource() {
|
||||
MythicspoilerComSource() {
|
||||
sets = new LinkedHashMap<>();
|
||||
setsAliases = new HashMap<>();
|
||||
setsAliases.put("exp", "bfz");
|
||||
|
|
|
@ -44,23 +44,16 @@ import java.util.Map;
|
|||
*
|
||||
* @author Quercitron
|
||||
*/
|
||||
public class TokensMtgImageSource implements CardImageSource {
|
||||
public enum TokensMtgImageSource implements CardImageSource {
|
||||
|
||||
instance;
|
||||
private static final Logger logger = Logger.getLogger(TokensMtgImageSource.class);
|
||||
|
||||
private static CardImageSource instance = new TokensMtgImageSource();
|
||||
|
||||
private List<TokenData> tokensData;
|
||||
|
||||
private final Object tokensDataSync = new Object();
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new TokensMtgImageSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "tokens.mtg.onl";
|
||||
|
|
|
@ -42,6 +42,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.remote.Connection;
|
||||
|
@ -53,29 +54,22 @@ import org.jsoup.select.Elements;
|
|||
import org.mage.plugins.card.images.CardDownloadData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class WizardCardsImageSource implements CardImageSource {
|
||||
public enum WizardCardsImageSource implements CardImageSource {
|
||||
|
||||
private static CardImageSource instance;
|
||||
private static Map<String, String> setsAliases;
|
||||
private static Map<String, String> languageAliases;
|
||||
instance;
|
||||
private Map<String, String> setsAliases;
|
||||
private Map<String, String> languageAliases;
|
||||
private final Map<String, Map<String, String>> sets;
|
||||
|
||||
public static CardImageSource getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new WizardCardsImageSource();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "WOTC Gatherer";
|
||||
}
|
||||
|
||||
public WizardCardsImageSource() {
|
||||
WizardCardsImageSource() {
|
||||
sets = new HashMap<>();
|
||||
setsAliases = new HashMap<>();
|
||||
setsAliases.put("2ED", "Unlimited Edition");
|
||||
|
|
|
@ -117,7 +117,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
});
|
||||
jComboBox1 = new JComboBox();
|
||||
|
||||
cardImageSource = MagicCardsImageSource.getInstance();
|
||||
cardImageSource = MagicCardsImageSource.instance;
|
||||
|
||||
jComboBox1.setModel(jComboBox1Model);
|
||||
jComboBox1.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
|
@ -125,28 +125,28 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
JComboBox cb = (JComboBox) e.getSource();
|
||||
switch (cb.getSelectedIndex()) {
|
||||
case 0:
|
||||
cardImageSource = MagicCardsImageSource.getInstance();
|
||||
cardImageSource = MagicCardsImageSource.instance;
|
||||
break;
|
||||
case 1:
|
||||
cardImageSource = WizardCardsImageSource.getInstance();
|
||||
cardImageSource = WizardCardsImageSource.instance;
|
||||
break;
|
||||
case 2:
|
||||
cardImageSource = MythicspoilerComSource.getInstance();
|
||||
cardImageSource = MythicspoilerComSource.instance;
|
||||
break;
|
||||
case 3:
|
||||
cardImageSource = TokensMtgImageSource.getInstance();
|
||||
cardImageSource = TokensMtgImageSource.instance;
|
||||
break;
|
||||
case 4:
|
||||
cardImageSource = MtgOnlTokensImageSource.getInstance();
|
||||
cardImageSource = MtgOnlTokensImageSource.instance;
|
||||
break;
|
||||
case 5:
|
||||
cardImageSource = AltMtgOnlTokensImageSource.getInstance();
|
||||
cardImageSource = AltMtgOnlTokensImageSource.instance;
|
||||
break;
|
||||
case 6:
|
||||
cardImageSource = GrabbagImageSource.getInstance();
|
||||
cardImageSource = GrabbagImageSource.instance;
|
||||
break;
|
||||
case 7:
|
||||
cardImageSource = MagidexImageSource.getInstance();
|
||||
cardImageSource = MagidexImageSource.instance;
|
||||
break;
|
||||
}
|
||||
updateCardsToDownload();
|
||||
|
|
|
@ -16,7 +16,7 @@ public class TokensMtgImageSourceTest {
|
|||
|
||||
@Test
|
||||
public void generateTokenUrlTest() throws Exception {
|
||||
CardImageSource imageSource = TokensMtgImageSource.getInstance();
|
||||
CardImageSource imageSource = TokensMtgImageSource.instance;
|
||||
|
||||
String url = imageSource.generateTokenUrl(new CardDownloadData("Thopter", "ORI", "0", false, 1, "ORI", ""));
|
||||
Assert.assertEquals("http://tokens.mtg.onl/tokens/ORI_010-Thopter.jpg", url);
|
||||
|
|
Loading…
Reference in a new issue