Sonar cleanups 03032019

This commit is contained in:
Ingmar Goudt 2019-03-04 10:43:20 +01:00
parent f46f321635
commit 45f665eb1d
13 changed files with 37 additions and 41 deletions

View file

@ -270,12 +270,14 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
mageCards = new LinkedHashMap<>();
//Find card view
for (UUID uuid : cards.keySet()) {
for (Map.Entry<UUID, CardView> view : cards.entrySet()) {
UUID uuid = view.getKey();
CardView cardView = view.getValue();
if (oldMageCards.containsKey(uuid)) {
mageCards.put(uuid, oldMageCards.get(uuid));
oldMageCards.remove(uuid);
} else {
mageCards.put(uuid, addCard(cards.get(uuid), bigCard, gameId));
mageCards.put(uuid, addCard(cardView, bigCard, gameId));
}
}
//Remove unused cards

View file

@ -238,11 +238,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
}
final MagePermanent perm = Plugins.instance.getMagePermanent(permanent, bigCard, cardDimension, gameId, true);
if (!Plugins.instance.isCardPluginLoaded()) {
//perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
} else {
//perm.setAlpha(0);
}
permanents.put(permanent.getId(), perm);
BattlefieldPanel.this.jPanel.add(perm, 10);

View file

@ -428,7 +428,7 @@ public class CardViewEDHPowerLevelComparator implements Comparator<CardView> {
|| cn.equals("krosan restorer") || cn.equals("laboratory maniac")
|| cn.equals("leovold, emissary of trest")
|| cn.equals("leonin relic-warder") || cn.equals("leyline of the void")
|| cn.equals("memnarch") || cn.equals("memnarch")
|| cn.equals("memnarch")
|| cn.equals("meren of clan nel toth") || cn.equals("mikaeus, the unhallowed")
|| cn.equals("mindcrank") || cn.equals("mindslaver")
|| cn.equals("minion reflector") || cn.equals("mycosynth lattice")
@ -446,7 +446,7 @@ public class CardViewEDHPowerLevelComparator implements Comparator<CardView> {
|| cn.equals("sunder")
|| cn.equals("storm cauldron") || cn.equals("teferi's puzzle box")
|| cn.equals("tangle wire")
|| cn.equals("teferi, mage of zhalfir") || cn.equals("teferi, mage of zhalfir")
|| cn.equals("teferi, mage of zhalfir")
|| cn.equals("tezzeret the seeker") || cn.equals("time stretch")
|| cn.equals("time warp") || cn.equals("training grounds")
|| cn.equals("triskelavus") || cn.equals("triskelion")

View file

@ -180,7 +180,7 @@ public final class ManaSymbols {
codes = EnumSet.of(Rarity.COMMON, Rarity.UNCOMMON, Rarity.RARE, Rarity.MYTHIC);
}
Map<Rarity, Image> rarityImages = new HashMap<>();
Map<Rarity, Image> rarityImages = new EnumMap<>(Rarity.class);
setImages.put(set, rarityImages);
// load medium size

View file

@ -25,7 +25,7 @@ public enum TokensMtgImageSource implements CardImageSource {
private static final Logger logger = Logger.getLogger(TokensMtgImageSource.class);
// [[EXP/Name, TokenData>
private HashMap<String, ArrayList<TokenData>> tokensData;
private HashMap<String, List<TokenData>> tokensData;
private static final Set<String> supportedSets = new LinkedHashSet<String>();
private final Object tokensDataSync = new Object();
@ -177,7 +177,7 @@ public enum TokensMtgImageSource implements CardImageSource {
return false;
}
private HashMap<String, ArrayList<TokenData>> getTokensData() throws IOException {
private HashMap<String, List<TokenData>> getTokensData() throws IOException {
synchronized (tokensDataSync) {
if (tokensData == null) {
DownloadPicturesService.getInstance().updateAndViewMessage("Find tokens data...");
@ -188,7 +188,7 @@ public enum TokensMtgImageSource implements CardImageSource {
List<TokenData> fileTokensData = parseTokensData(inputStream);
for (TokenData tokenData : fileTokensData) {
String key = tokenData.getExpansionSetCode() + "/" + tokenData.getName();
ArrayList<TokenData> list = tokensData.get(key);
List<TokenData> list = tokensData.get(key);
if (list == null) {
list = new ArrayList<>();
tokensData.put(key, list);
@ -213,7 +213,7 @@ public enum TokensMtgImageSource implements CardImageSource {
// logger.info("TOK: " + siteData.getExpansionSetCode() + "/" + siteData.getName());
String key = siteData.getExpansionSetCode() + "/" + siteData.getName();
supportedSets.add(siteData.getExpansionSetCode());
ArrayList<TokenData> list = tokensData.get(key);
List<TokenData> list = tokensData.get(key);
if (list == null) {
list = new ArrayList<>();
tokensData.put(key, list);
@ -249,7 +249,7 @@ public enum TokensMtgImageSource implements CardImageSource {
BufferedReader reader = new BufferedReader(inputReader)) {
// we have to specify encoding to read special comma
reader.readLine(); // skip header
String header = reader.readLine(); // skip header
String line = reader.readLine();
// states
// 0 - wait set name

View file

@ -40,7 +40,7 @@ public enum WizardCardsImageSource implements CardImageSource {
WizardCardsImageSource() {
languageAliases = new HashMap<>();
languageAliases = new EnumMap<>(CardLanguage.class);
languageAliases.put(CardLanguage.ENGLISH, "English");
languageAliases.put(CardLanguage.SPANISH, "Spanish");
languageAliases.put(CardLanguage.FRENCH, "French");
@ -544,9 +544,9 @@ public enum WizardCardsImageSource implements CardImageSource {
getLandVariations(setLinks, cardSet, multiverseId, cardName);
} else {
String numberChar = "";
int pos1 = cardName.indexOf("(");
int pos1 = cardName.indexOf('(');
if (pos1 > 0) {
int pos2 = cardName.indexOf("(", pos1 + 1);
int pos2 = cardName.indexOf('(', pos1 + 1);
if (pos2 > 0) {
numberChar = cardName.substring(pos2 + 1, pos2 + 2);
cardName = cardName.substring(0, pos1);

View file

@ -119,7 +119,7 @@ public class SessionImpl implements Session {
if (ex.getMessage() != null && ex.getMessage().startsWith("Unable to perform invocation")) {
addMessage = "Maybe the server version is not compatible. ";
}
client.showMessage("Unable connect to server. " + addMessage + ex.getMessage() != null ? ex.getMessage() : "");
client.showMessage("Unable connect to server. " + addMessage + (ex.getMessage() != null ? ex.getMessage() : ""));
} catch (MageVersionException ex) {
if (!canceled) {
client.showMessage("Unable connect to server. " + ex.getMessage());

View file

@ -121,10 +121,8 @@ public enum ServerMessagesUtil {
return Collections.emptyList();
}
Scanner scanner = null;
List<String> newMessages = new ArrayList<>();
try {
scanner = new Scanner(is);
try(Scanner scanner = new Scanner(is)) {
while (scanner.hasNextLine()) {
String message = scanner.nextLine();
if (!message.trim().isEmpty()) {
@ -134,7 +132,6 @@ public enum ServerMessagesUtil {
} catch (Exception e) {
log.error(e, e);
} finally {
StreamUtils.closeQuietly(scanner);
StreamUtils.closeQuietly(is);
}
return newMessages;

View file

@ -2,8 +2,11 @@
package mage.cards.b;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
@ -65,13 +68,10 @@ class BaneOfBalaGedEffect extends OneShotEffect {
if (defendingPlayer != null) {
Target target = new TargetControlledPermanent(2);
defendingPlayer.chooseTarget(outcome, target, source, game);
Set<Card> toExile = new HashSet<>();
target.getTargets().stream().map((targetId)
-> game.getPermanent(targetId)).filter((permanent)
-> (permanent != null)).forEach((permanent)
-> {
toExile.add(permanent);
});
Set<Card> toExile = target.getTargets().stream()
.map(game::getPermanent)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
defendingPlayer.moveCards(toExile, Zone.EXILED, source, game);
return true;
}

View file

@ -1,5 +1,6 @@
package mage.cards.c;
import java.util.Objects;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
@ -61,12 +62,11 @@ class CentaurMediatorEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
game.getState().getPlayersInRange(
source.getControllerId(), game
).stream().map((playerId) -> game.getPlayer(playerId)).filter(
(player) -> (player != null)
).forEachOrdered((player) -> {
player.gainLife(4, game, source);
});
source.getControllerId(), game)
.stream()
.map(game::getPlayer)
.filter(Objects::nonNull)
.forEachOrdered(player -> player.gainLife(4, game, source));
return true;
}

View file

@ -72,7 +72,7 @@ class KavuPredatorTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (game.getOpponents(this.controllerId).contains(event.getPlayerId())) {
this.getEffects().get(0).setValue("gainedLife", new Integer(event.getAmount()));
this.getEffects().get(0).setValue("gainedLife", event.getAmount());
return true;
}
return false;

View file

@ -289,8 +289,9 @@ public final class RateCard {
}
// normalize for the file to [1..100]
for (String name : thisFileRatings.keySet()) {
int r = thisFileRatings.get(name);
for (Map.Entry<String, Integer> ratingByName : thisFileRatings.entrySet()) {
int r = ratingByName.getValue();
String name = ratingByName.getKey();
int newRating = (int) (100.0f * (r - min) / (max - min));
int oldRating = baseRatings.getOrDefault(name, 0);
if (newRating > oldRating) {
@ -339,7 +340,7 @@ public final class RateCard {
}
Integer typeCount = singleCount.get(symbol);
if (typeCount == null) {
typeCount = new Integer(0);
typeCount = 0;
}
typeCount += 1;
singleCount.put(symbol, typeCount);

View file

@ -28,7 +28,7 @@ public class JarVersion {
String manifestPath;
if (classPath.startsWith("jar")) {
// jar source
manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
manifestPath = classPath.substring(0, classPath.lastIndexOf('!') + 1) + "/META-INF/MANIFEST.MF";
} else {
// dir source (e.g. IDE's debug)
// it's can be generated by runtime, but need extra code and performance: https://stackoverflow.com/questions/34674073/how-to-generate-manifest-mf-file-during-compile-phase