Refactor/Code Cleanup

This commit is contained in:
Anthony Calosa
2019-09-02 18:08:56 +08:00
parent 83b6b9faeb
commit c38bae910a
411 changed files with 1354 additions and 3010 deletions

View File

@@ -64,7 +64,7 @@ public class CardStorageReader {
void report(int current, int total);
// does nothing, used when they pass null instead of an instance
public final static ProgressObserver emptyObserver = new ProgressObserver() {
ProgressObserver emptyObserver = new ProgressObserver() {
@Override public void setOperationName(final String name, final boolean usePercents) {}
@Override public void report(final int current, final int total) {}
};

View File

@@ -123,7 +123,7 @@ public final class ImageKeys {
int index = filename.lastIndexOf('_');
if (index != -1) {
String setlessFilename = filename.substring(0, index);
String setCode = filename.substring(index + 1, filename.length());
String setCode = filename.substring(index + 1);
// try with upper case set
file = findFile(dir, setlessFilename + "_" + setCode.toUpperCase());
if (file != null) { return file; }
@@ -133,7 +133,7 @@ public final class ImageKeys {
// if there's an art variant try without it
if (setlessFilename.matches(".*[0-9]*$")) {
file = findFile(dir, setlessFilename.replaceAll("[0-9]*$", ""));
if (file != null) { return file; }
return file;
}
}
} else if (filename.contains("/")) {
@@ -144,7 +144,7 @@ public final class ImageKeys {
// try lowering the art index to the minimum for regular cards
if (setlessFilename.contains(".full")) {
file = findFile(dir, setlessFilename.replaceAll("[0-9]*[.]full", "1.full"));
if (file != null) { return file; }
return file;
}
}

View File

@@ -47,13 +47,8 @@ public abstract class LobbyPlayer {
}
LobbyPlayer other = (LobbyPlayer) obj;
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
return other.name == null;
} else return name.equals(other.name);
}
public int getAvatarIndex() {

View File

@@ -41,7 +41,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
public final static char NameSetSeparator = '|';
// need this to obtain cardReference by name+set+artindex
private final ListMultimap<String, PaperCard> allCardsByName = Multimaps.newListMultimap(new TreeMap<String,Collection<PaperCard>>(String.CASE_INSENSITIVE_ORDER), CollectionSuppliers.<PaperCard>arrayLists());
private final ListMultimap<String, PaperCard> allCardsByName = Multimaps.newListMultimap(new TreeMap<String,Collection<PaperCard>>(String.CASE_INSENSITIVE_ORDER), CollectionSuppliers.arrayLists());
private final Map<String, PaperCard> uniqueCardsByName = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
private final Map<String, CardRules> rulesByName;
private final Map<String, ICardFace> facesByName = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
@@ -62,7 +62,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
Random(false);
final boolean filterSets;
private SetPreference(boolean filterIrregularSets) {
SetPreference(boolean filterIrregularSets) {
filterSets = filterIrregularSets;
}

View File

@@ -189,7 +189,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
public String getBoosterMustContain() { return boosterMustContain; }
public CardInSet[] getCards() { return cards; }
public Map<String, Integer> getTokens() { return tokenNormalized; };
public Map<String, Integer> getTokens() { return tokenNormalized; }
public static final Function<CardEdition, String> FN_GET_CODE = new Function<CardEdition, String>() {
@Override

View File

@@ -20,7 +20,7 @@ final class CardFace implements ICardFace {
public enum FaceSelectionMethod { //
USE_ACTIVE_FACE,
USE_PRIMARY_FACE,
COMBINE;
COMBINE
}
@@ -87,7 +87,7 @@ final class CardFace implements ICardFace {
void setInitialLoyalty(String value) { this.initialLoyalty = value; }
void setPtText(String value) {
final String k[] = value.split("/");
final String[] k = value.split("/");
if (k.length != 2) {
throw new RuntimeException("Creature '" + this.getName() + "' has bad p/t stats");

View File

@@ -85,7 +85,7 @@ public final class CardFacePredicates {
@Override
public boolean apply(ICardFace input) {
String k[] = valid.split("\\.", 2);
String[] k = valid.split("\\.", 2);
if ("Card".equals(k[0])) {
// okay
@@ -110,10 +110,7 @@ public final class CardFacePredicates {
static protected boolean hasProperty(ICardFace input, final String v) {
if (v.startsWith("non")) {
return !hasProperty(input, v.substring(3));
} else if (!input.getType().hasStringType(v)) {
return false;
}
return true;
} else return input.getType().hasStringType(v);
}
}

View File

@@ -35,7 +35,7 @@ public enum CardRarity {
private final String shortName, longName;
private CardRarity(final String shortName0, final String longName0) {
CardRarity(final String shortName0, final String longName0) {
shortName = shortName0;
longName = longName0;
}

View File

@@ -435,10 +435,10 @@ public final class CardRulesPredicates {
return this.op(card.getManaCost().getGenericCost(), this.operand);
case POWER:
value = card.getIntPower();
return value != Integer.MAX_VALUE ? this.op(value, this.operand) : false;
return value != Integer.MAX_VALUE && this.op(value, this.operand);
case TOUGHNESS:
value = card.getIntToughness();
return value != Integer.MAX_VALUE ? this.op(value, this.operand) : false;
return value != Integer.MAX_VALUE && this.op(value, this.operand);
default:
return false;
}

View File

@@ -10,7 +10,7 @@ public enum CardSplitType
Split(FaceSelectionMethod.COMBINE, CardStateName.RightSplit),
Flip(FaceSelectionMethod.USE_PRIMARY_FACE, CardStateName.Flipped);
private CardSplitType(FaceSelectionMethod calcMode, CardStateName stateName) {
CardSplitType(FaceSelectionMethod calcMode, CardStateName stateName) {
method = calcMode;
this.changedStateName = stateName;
}

View File

@@ -73,7 +73,7 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
public final boolean isPermanent;
private static final ImmutableList<String> allCoreTypeNames = EnumUtil.getNames(CoreType.class);
private CoreType(final boolean permanent) {
CoreType(final boolean permanent) {
isPermanent = permanent;
}
}
@@ -598,10 +598,7 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
if (multiWordTypes[0].startsWith(type) && !multiWordTypes[0].equals(type)) {
return true;
}
if (multiWordTypes[1].startsWith(type) && !multiWordTypes[1].equals(type)) {
return true;
}
return false;
return multiWordTypes[1].startsWith(type) && !multiWordTypes[1].equals(type);
}
public static class Constant {

View File

@@ -5,5 +5,5 @@ package forge.card;
*
*/
public interface ICardFace extends ICardCharacteristics, ICardRawAbilites, Comparable<ICardFace> {
public String getAltName();
String getAltName();
}

View File

@@ -168,7 +168,7 @@ public final class MagicColor {
private final String name, symbol;
private final byte colormask;
private Color(String name0, byte colormask0, String symbol0) {
Color(String name0, byte colormask0, String symbol0) {
name = name0;
colormask = colormask0;
symbol = symbol0;

View File

@@ -44,7 +44,7 @@ public abstract class ManaAtom {
if (s.length() == 2) { //if name is two characters, check for combination of two colors
return (byte)(fromName(s.charAt(0)) | fromName(s.charAt(1)));
} else if (s.length() == 1) {
return (byte) fromName(s.charAt(0));
return fromName(s.charAt(0));
}
s = s.toLowerCase();

View File

@@ -69,7 +69,7 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh
private ManaCost(int cmc) {
this.hasNoCost = cmc < 0;
this.genericCost = cmc < 0 ? 0 : cmc;
sealClass(Lists.<ManaCostShard>newArrayList());
sealClass(Lists.newArrayList());
}
private ManaCost(int cmc, List<ManaCostShard> shards0) {

View File

@@ -86,7 +86,7 @@ public enum ManaCostShard {
* @param sValue
* the s value
*/
private ManaCostShard(final int value, final String sValue) {
ManaCostShard(final int value, final String sValue) {
this(value, sValue, sValue);
}
@@ -100,7 +100,7 @@ public enum ManaCostShard {
* @param imgKey
* the img key
*/
private ManaCostShard(final int value, final String sValue, final String imgKey) {
ManaCostShard(final int value, final String sValue, final String imgKey) {
this.shard = value;
this.cmc = this.getCMC();
this.cmpc = this.getCmpCost();

View File

@@ -85,10 +85,7 @@ public enum DeckFormat {
if (otherPart != null && otherPart.getManaCost().getCMC() > 3) {
return false; //only cards with CMC less than 3 are allowed
}
if (bannedCards.contains(rules.getName())) {
return false;
}
return true;
return !bannedCards.contains(rules.getName());
}
}) {
private final Set<String> bannedCommanders = ImmutableSet.of("Derevi, Empyrial Tactician", "Erayo, Soratami Ascendant", "Rofellos, Llanowar Emissary");
@@ -120,7 +117,7 @@ public enum DeckFormat {
private final static String ADVPROCLAMATION = "Advantageous Proclamation";
private final static String SOVREALM = "Sovereign's Realm";
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<CardRules> cardPoolFilter0, Predicate<PaperCard> paperCardPoolFilter0) {
DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<CardRules> cardPoolFilter0, Predicate<PaperCard> paperCardPoolFilter0) {
mainRange = mainRange0;
sideRange = sideRange0;
maxCardCopies = maxCardCopies0;
@@ -128,7 +125,7 @@ public enum DeckFormat {
paperCardPoolFilter = paperCardPoolFilter0;
}
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<CardRules> cardPoolFilter0) {
DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0, Predicate<CardRules> cardPoolFilter0) {
mainRange = mainRange0;
sideRange = sideRange0;
maxCardCopies = maxCardCopies0;
@@ -136,7 +133,7 @@ public enum DeckFormat {
cardPoolFilter = cardPoolFilter0;
}
private DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0) {
DeckFormat(Range<Integer> mainRange0, Range<Integer> sideRange0, int maxCardCopies0) {
mainRange = mainRange0;
sideRange = sideRange0;
maxCardCopies = maxCardCopies0;

View File

@@ -216,10 +216,7 @@ public class DeckRecognizer {
if (line.toLowerCase().contains("schemes")) {
return true;
}
if (line.toLowerCase().contains("vanguard")) {
return true;
}
return false;
return line.toLowerCase().contains("vanguard");
}
public void setDateConstraint(int month, Integer year) {

View File

@@ -10,7 +10,7 @@ public enum DeckSection {
Conspiracy(0);
private final int typicalSize; // Rules enforcement is done in DeckFormat class, this is for reference only
private DeckSection(int commonSize) {
DeckSection(int commonSize) {
typicalSize = commonSize;
}

View File

@@ -142,7 +142,7 @@ public abstract class DeckGeneratorBase {
if(basicLandEdition == null){
if(setBasicLandPool(cp.getEdition())){
basicLandEdition = cp.getEdition();
};
}
}
cardCounts.put(cp.getName(), newCount);
trace.append(String.format("(%d) %s [%s]%n", cp.getRules().getManaCost().getCMC(), cp.getName(), cp.getRules().getManaCost()));

View File

@@ -159,11 +159,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
if (!edition.equals(other.edition)) {
return false;
}
if ((other.foil != foil) || (other.artIndex != artIndex)) {
return false;
}
return true;
return (other.foil == foil) && (other.artIndex == artIndex);
}
/*
@@ -238,13 +234,11 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
// Return true if card is one of the five basic lands that can be added for free
public boolean isVeryBasicLand() {
if ((this.getName().equals("Swamp"))
return (this.getName().equals("Swamp"))
|| (this.getName().equals("Plains"))
|| (this.getName().equals("Island"))
|| (this.getName().equals("Forest"))
|| (this.getName().equals("Mountain"))) {
return true;
} else return false;
|| (this.getName().equals("Mountain"));
}
}

View File

@@ -36,6 +36,7 @@ import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import java.nio.charset.StandardCharsets;
/**
* A Base64 encoder/decoder.
@@ -377,7 +378,7 @@ public final class Base64Coder {
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
return String.valueOf(encode(pbeCipher.doFinal(value.getBytes("UTF-8"))));
return String.valueOf(encode(pbeCipher.doFinal(value.getBytes(StandardCharsets.UTF_8))));
}
public static String decrypt(String value) throws Exception {
@@ -385,7 +386,7 @@ public final class Base64Coder {
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
return new String(pbeCipher.doFinal(decode(value)), "UTF-8");
return new String(pbeCipher.doFinal(decode(value)), StandardCharsets.UTF_8);
}
// Dummy constructor.

View File

@@ -33,7 +33,7 @@ public enum ComparableOp {
private final String caption;
private ComparableOp(String caption0) {
ComparableOp(String caption0) {
caption = caption0;
}

View File

@@ -10,7 +10,7 @@ import forge.item.PaperCard;
public class ImageUtil {
public static float getNearestHQSize(float baseSize, float actualSize) {
//get nearest power of actualSize to baseSize so that the image renders good
return (float)Math.round(actualSize) * (float)Math.pow(2, (double)Math.round(Math.log((double)(baseSize / actualSize)) / Math.log(2)));
return (float)Math.round(actualSize) * (float)Math.pow(2, (double)Math.round(Math.log(baseSize / actualSize) / Math.log(2)));
}
public static PaperCard getPaperCardFromImageKey(String key) {
@@ -119,7 +119,6 @@ public class ImageUtil {
for (int i = 0; i < in.length(); i++) {
c = in.charAt(i);
if ((c == '"') || (c == '/') || (c == ':') || (c == '?')) {
out.append("");
} else {
out.append(c);
}

View File

@@ -102,7 +102,7 @@ public final class Lang {
strCount = startsWithVowel(noun) ? "an " : "a ";
}
else {
strCount = String.valueOf(cnt) + " ";
strCount = cnt + " ";
}
return strCount + countedForm;
}

View File

@@ -1,5 +1,5 @@
package forge.util;
public interface LocalizationChangeObserver {
public void localizationChanged();
void localizationChanged();
}

View File

@@ -1,10 +1,10 @@
package forge.util;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.*;
@@ -38,7 +38,7 @@ public class Localizer {
try {
//formatter = new MessageFormat(resourceBundle.getString(key.toLowerCase()), locale);
formatter = new MessageFormat(resourceBundle.getString(key.toString()), locale);
formatter = new MessageFormat(resourceBundle.getString(key), locale);
} catch (final IllegalArgumentException | MissingResourceException e) {
e.printStackTrace();
}
@@ -51,14 +51,10 @@ public class Localizer {
formatter.setLocale(locale);
String formattedMessage = "CHAR ENCODING ERROR";
try {
//Support non-English-standard characters
formattedMessage = new String(formatter.format(messageArguments).getBytes("ISO-8859-1"), "UTF-8");
} catch (final UnsupportedEncodingException e) {
e.printStackTrace();
}
return formattedMessage;
//Support non-English-standard characters
formattedMessage = new String(formatter.format(messageArguments).getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
return formattedMessage;
}

View File

@@ -65,7 +65,7 @@ public class StorageBase<T> implements IStorage<T> {
@Override
public boolean contains(String name) {
return name == null ? false : map.containsKey(name);
return name != null && map.containsKey(name);
}
@Override