Refactoring

See github line by line comments in 'File changed'
This commit is contained in:
vraskulin 2016-12-29 15:26:19 +03:00
parent 6577e641e6
commit c526306c5b
11 changed files with 21 additions and 25 deletions

View file

@ -53,7 +53,7 @@ public interface Card extends MageObject {
void setOwnerId(UUID ownerId);
public Abilities<Ability> getAbilities(Game game);
Abilities<Ability> getAbilities(Game game);
void setSpellAbility(SpellAbility ability);

View file

@ -462,9 +462,9 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
}
break;
case COMMAND:
lkiObject = (Commander) game.getObject(objectId);
lkiObject = game.getObject(objectId);
if (lkiObject != null) {
removed = game.getState().getCommand().remove((Commander) game.getObject(objectId));
removed = game.getState().getCommand().remove(game.getObject(objectId));
}
break;
case OUTSIDE:

View file

@ -30,7 +30,6 @@ package mage.cards;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
/**
*

View file

@ -65,6 +65,7 @@ public class Sets extends HashMap<String, ExpansionSet> {
try {
addSet((ExpansionSet) c.getMethod("getInstance").invoke(null));
} catch (Exception ex) {
logger.error(ex);
}
}
}
@ -142,10 +143,9 @@ public class Sets extends HashMap<String, ExpansionSet> {
}
public static void saveDeck(String file, DeckCardLists deck) throws FileNotFoundException {
PrintWriter out = new PrintWriter(file);
Map<String, DeckCardInfo> deckCards = new HashMap<>();
Map<String, DeckCardInfo> sideboard = new HashMap<>();
try {
try (PrintWriter out = new PrintWriter(file)) {
if (deck.getName() != null && deck.getName().length() > 0) {
out.println("NAME:" + deck.getName());
}
@ -169,10 +169,10 @@ public class Sets extends HashMap<String, ExpansionSet> {
}
// Write out all of the cards
for (Map.Entry<String, DeckCardInfo> entry : deckCards.entrySet()) {
for (Entry<String, DeckCardInfo> entry : deckCards.entrySet()) {
out.printf("%d [%s:%s] %s%n", entry.getValue().getQuantity(), entry.getValue().getSetCode(), entry.getValue().getCardNum(), entry.getValue().getCardName());
}
for (Map.Entry<String, DeckCardInfo> entry : sideboard.entrySet()) {
for (Entry<String, DeckCardInfo> entry : sideboard.entrySet()) {
out.printf("SB: %d [%s:%s] %s%n", entry.getValue().getQuantity(), entry.getValue().getSetCode(), entry.getValue().getCardNum(), entry.getValue().getCardName());
}
@ -183,8 +183,6 @@ public class Sets extends HashMap<String, ExpansionSet> {
out.print("LAYOUT SIDEBOARD:");
writeCardLayout(out, deck.getSideboardLayout());
out.print("\n");
} finally {
out.close();
}
}

View file

@ -35,7 +35,6 @@ import mage.abilities.AbilitiesImpl;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.SpellAbilityType;
import mage.constants.Zone;
import mage.game.Game;

View file

@ -8,7 +8,6 @@ package mage.cards;
import java.util.ArrayList;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.SpellAbilityType;
import mage.constants.Zone;
import mage.game.Game;

View file

@ -32,7 +32,6 @@ import java.util.UUID;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.cards.CardImpl;

View file

@ -74,7 +74,7 @@ public class DeckCardInfo implements Serializable {
}
public String getCardKey() {
return new StringBuilder(setCode).append(cardNum).toString();
return setCode + cardNum;
}
}

View file

@ -53,8 +53,7 @@ public abstract class DeckImporter {
lineCount = 0;
sbMessage.setLength(0);
try {
Scanner scanner = new Scanner(f);
try {
try (Scanner scanner = new Scanner(f)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
lineCount++;
@ -63,13 +62,9 @@ public abstract class DeckImporter {
if (sbMessage.length() > 0) {
logger.fatal(sbMessage);
}
}
catch (Exception ex) {
} catch (Exception ex) {
logger.fatal(null, ex);
}
finally {
scanner.close();
}
} catch (Exception ex) {
logger.fatal(null, ex);
}

View file

@ -28,7 +28,7 @@
package mage.cards.decks.importer;
import java.util.List;
import java.util.Random;
import mage.cards.decks.DeckCardInfo;
import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardCriteria;
@ -69,8 +69,7 @@ public class MWSDeckImporter extends DeckImporter {
CardCriteria criteria = new CardCriteria();
criteria.name(lineName);
criteria.setCodes(setCode);
List<CardInfo> cards = null;
cards = CardRepository.instance.findCards(criteria);
List<CardInfo> cards = CardRepository.instance.findCards(criteria);
if (!cards.isEmpty()) {
cardInfo = cards.get(RandomUtil.nextInt(cards.size()));
}

View file

@ -33,7 +33,7 @@ public enum ExpansionRepository {
private Dao<ExpansionInfo, Object> expansionDao;
private ExpansionRepository() {
ExpansionRepository() {
File file = new File("db");
if (!file.exists()) {
file.mkdirs();
@ -57,6 +57,7 @@ public enum ExpansionRepository {
try {
expansionDao.create(expansion);
} catch (SQLException ex) {
logger.error(ex);
}
}
@ -83,6 +84,7 @@ public enum ExpansionRepository {
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
sets = expansions.toArray(new ExpansionInfo[0]);
} catch (SQLException ex) {
logger.error(ex);
}
return sets;
}
@ -95,6 +97,7 @@ public enum ExpansionRepository {
qb.where().eq("basicLands", new SelectArg(true));
sets = expansionDao.query(qb.prepare());
} catch (SQLException ex) {
logger.error(ex);
}
return sets;
}
@ -106,6 +109,7 @@ public enum ExpansionRepository {
qb.where().eq("blockName", new SelectArg(blockName));
return expansionDao.query(qb.prepare());
} catch (SQLException ex) {
logger.error(ex);
}
return sets;
}
@ -120,6 +124,7 @@ public enum ExpansionRepository {
set = expansions.get(0);
}
} catch (SQLException ex) {
logger.error(ex);
}
return set;
}
@ -134,6 +139,7 @@ public enum ExpansionRepository {
set = expansions.get(0);
}
} catch (SQLException ex) {
logger.error(ex);
}
return set;
}
@ -144,6 +150,7 @@ public enum ExpansionRepository {
qb.orderBy("releaseDate", true);
return expansionDao.query(qb.prepare());
} catch (SQLException ex) {
logger.error(ex);
}
return Collections.emptyList();
}
@ -159,6 +166,7 @@ public enum ExpansionRepository {
}
return setNames;
} catch (SQLException ex) {
logger.error(ex);
}
return Collections.emptyList();
}