change some size() comparisons, to isEmpty()

This commit is contained in:
Ingmar Goudt 2019-07-14 20:53:23 +02:00
parent 5ba206111a
commit eb0cfc94f8
23 changed files with 35 additions and 36 deletions

View file

@ -352,7 +352,7 @@ public class MageBook extends JComponent {
List<Plane> planes = getPlanes(currentPage, currentSet, numTokensEmblems); List<Plane> planes = getPlanes(currentPage, currentSet, numTokensEmblems);
int numPlanes = 0; int numPlanes = 0;
if (planes != null && planes.size() > 0) { if (!planes.isEmpty()) {
int size = planes.size(); int size = planes.size();
numPlanes = size; numPlanes = size;
Rectangle rectangle = new Rectangle(); Rectangle rectangle = new Rectangle();
@ -523,7 +523,7 @@ public class MageBook extends JComponent {
// second run for empty numbers // second run for empty numbers
int countHave = haveNumbers.size(); int countHave = haveNumbers.size();
int countNotHave = 0; int countNotHave = 0;
if (cards.size() > 0) { if (!cards.isEmpty()) {
for (int i = startNumber; i <= endNumber; i++) { for (int i = startNumber; i <= endNumber; i++) {
if (!haveNumbers.contains(i)) { if (!haveNumbers.contains(i)) {
countNotHave++; countNotHave++;
@ -593,8 +593,8 @@ public class MageBook extends JComponent {
} }
private List<Emblem> getEmblems(int page, String set, int numTokensEmblems) { private List<Emblem> getEmblems(int page, String set, int numTokensEmblems) {
ArrayList<CardDownloadData> allEmblems = getTokenCardUrls(); List<CardDownloadData> allEmblems = getTokenCardUrls();
ArrayList<Emblem> emblems = new ArrayList<>(); List<Emblem> emblems = new ArrayList<>();
for (CardDownloadData emblem : allEmblems) { for (CardDownloadData emblem : allEmblems) {
if (emblem.getSet().equals(set)) { if (emblem.getSet().equals(set)) {
@ -650,8 +650,8 @@ public class MageBook extends JComponent {
} }
private List<Plane> getPlanes(int page, String set, int numTokensEmblems) { private List<Plane> getPlanes(int page, String set, int numTokensEmblems) {
ArrayList<CardDownloadData> allPlanes = getTokenCardUrls(); List<CardDownloadData> allPlanes = getTokenCardUrls();
ArrayList<Plane> planes = new ArrayList<>(); List<Plane> planes = new ArrayList<>();
for (CardDownloadData plane : allPlanes) { for (CardDownloadData plane : allPlanes) {
if (plane.getSet().equals(set)) { if (plane.getSet().equals(set)) {

View file

@ -198,7 +198,7 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog {
public void doApply() { public void doApply() {
if (getSelectedPacks().size() < 2 && isRandomDraft) { if (getSelectedPacks().size() < 2 && isRandomDraft) {
JOptionPane.showMessageDialog(this, "At least 2 sets must be selected", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, "At least 2 sets must be selected", "Error", JOptionPane.ERROR_MESSAGE);
} else if (getSelectedPacks().size() < 1 && isRichManDraft) { } else if (getSelectedPacks().isEmpty() && isRichManDraft) {
JOptionPane.showMessageDialog(this, "At least 1 set must be selected", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(this, "At least 1 set must be selected", "Error", JOptionPane.ERROR_MESSAGE);
} else { } else {
this.setVisible(false); this.setVisible(false);

View file

@ -1212,7 +1212,7 @@ public final class GamePanel extends javax.swing.JPanel {
needPlayable = new HashSet<>(); needPlayable = new HashSet<>();
} }
if (needChoosen.size() == 0 && needSelectable.size() == 0 && needPlayable.size() == 0) { if (needChoosen.isEmpty() && needSelectable.isEmpty() && needPlayable.isEmpty()) {
return; return;
} }

View file

@ -365,7 +365,7 @@ public class HelperPanel extends JPanel {
this.mainPanel.setOpaque(false); this.mainPanel.setOpaque(false);
} }
if (buttons.size() == 0) { if (buttons.isEmpty()) {
return; return;
} }

View file

@ -140,7 +140,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
private boolean isCardsPlayable(Collection<CardView> cards, GameView gameView, Set<UUID> possibleTargets) { private boolean isCardsPlayable(Collection<CardView> cards, GameView gameView, Set<UUID> possibleTargets) {
if (cards != null) { if (cards != null) {
// can play // can play
if (gameView != null && gameView.getCanPlayObjects() != null && gameView.getCanPlayObjects().size() > 0) { if (gameView != null && gameView.getCanPlayObjects() != null && !gameView.getCanPlayObjects().isEmpty()) {
for (CardView card : cards) { for (CardView card : cards) {
if (gameView.getCanPlayObjects().contains(card.getId())) { if (gameView.getCanPlayObjects().contains(card.getId())) {
return true; return true;
@ -148,7 +148,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
} }
} }
// can select // can select
if (possibleTargets != null && possibleTargets.size() > 0) { if (possibleTargets != null && !possibleTargets.isEmpty()) {
for (CardView card : cards) { for (CardView card : cards) {
if (possibleTargets.contains(card.getId())) { if (possibleTargets.contains(card.getId())) {
return true; return true;

View file

@ -145,7 +145,7 @@ public enum CopyPasteImageSource implements CardImageSource {
final CopyPasteImageSourceDialog dialog = new CopyPasteImageSourceDialog(); final CopyPasteImageSourceDialog dialog = new CopyPasteImageSourceDialog();
dialog.pack(); dialog.pack();
int count = 0; int count = 0;
if (viewMissingCards && missingCards.size() > 0 && singleLinks.size() == 0) { if (viewMissingCards && !missingCards.isEmpty() && singleLinks.isEmpty()) {
viewMissingCards = false; viewMissingCards = false;
String displayMissingCardsStr = "Up to the first 20 cards are:\n"; String displayMissingCardsStr = "Up to the first 20 cards are:\n";
String missingCardsStr = ""; String missingCardsStr = "";
@ -228,7 +228,7 @@ public enum CopyPasteImageSource implements CardImageSource {
public ArrayList<String> getSupportedSets() { public ArrayList<String> getSupportedSets() {
setupLinks(); setupLinks();
ArrayList<String> supportedSetsCopy = new ArrayList<>(); ArrayList<String> supportedSetsCopy = new ArrayList<>();
if (supportedSets.size() == 0) { if (supportedSets.isEmpty()) {
for (String setCode : Sets.getInstance().keySet()) { for (String setCode : Sets.getInstance().keySet()) {
supportedSets.add(setCode); supportedSets.add(setCode);
} }

View file

@ -238,16 +238,16 @@ public class GathererSets implements Iterable<DownloadJob> {
// 2. missing rarity icon: // 2. missing rarity icon:
// WARNING, need too much time (60+ secs), only for debug mode // WARNING, need too much time (60+ secs), only for debug mode
///* ///*
if ((set.getCardsByRarity(Rarity.COMMON).size() > 0) && !res.haveCommon) { if (!set.getCardsByRarity(Rarity.COMMON).isEmpty() && !res.haveCommon) {
logger.error(String.format("Symbols: set have common cards, but don't download icon: %s (%s)", set.getCode(), set.getName())); logger.error(String.format("Symbols: set have common cards, but don't download icon: %s (%s)", set.getCode(), set.getName()));
} }
if ((set.getCardsByRarity(Rarity.UNCOMMON).size() > 0) && !res.haveUncommon) { if (!set.getCardsByRarity(Rarity.UNCOMMON).isEmpty() && !res.haveUncommon) {
logger.error(String.format("Symbols: set have uncommon cards, but don't download icon: %s (%s)", set.getCode(), set.getName())); logger.error(String.format("Symbols: set have uncommon cards, but don't download icon: %s (%s)", set.getCode(), set.getName()));
} }
if ((set.getCardsByRarity(Rarity.RARE).size() > 0) && !res.haveRare) { if (!set.getCardsByRarity(Rarity.RARE).isEmpty() && !res.haveRare) {
logger.error(String.format("Symbols: set have rare cards, but don't download icon: %s (%s)", set.getCode(), set.getName())); logger.error(String.format("Symbols: set have rare cards, but don't download icon: %s (%s)", set.getCode(), set.getName()));
} }
if ((set.getCardsByRarity(Rarity.MYTHIC).size() > 0) && !res.haveMyth) { if (!set.getCardsByRarity(Rarity.MYTHIC).isEmpty() && !res.haveMyth) {
logger.error(String.format("Symbols: set have mythic cards, but don't download icon: %s (%s)", set.getCode(), set.getName())); logger.error(String.format("Symbols: set have mythic cards, but don't download icon: %s (%s)", set.getCode(), set.getName()));
} }
//*/ //*/

View file

@ -115,7 +115,7 @@ public class Commander extends Constructed {
} }
} }
if (deck.getSideboard().size() < 1 || deck.getSideboard().size() > 2) { if (deck.getSideboard().isEmpty() || deck.getSideboard().size() > 2) {
if ((deck.getSideboard().size() > 1 && !partnerAllowed)) { if ((deck.getSideboard().size() > 1 && !partnerAllowed)) {
invalid.put("Commander", "You may only have one commander"); invalid.put("Commander", "You may only have one commander");
} }

View file

@ -68,7 +68,7 @@ public class FreeformCommander extends Constructed {
} }
} }
if (deck.getSideboard().size() < 1 || deck.getSideboard().size() > 2) { if (deck.getSideboard().isEmpty() || deck.getSideboard().size() > 2) {
invalid.put("Commander", "Sideboard must contain only the commander(s)"); invalid.put("Commander", "Sideboard must contain only the commander(s)");
valid = false; valid = false;
} else { } else {

View file

@ -134,11 +134,11 @@ public class Oathbreaker extends Vintage {
} }
// check size (1+1 or 2+2 allows) // check size (1+1 or 2+2 allows)
if (commanderNames.size() == 0 || commanderNames.size() > 2) { if (commanderNames.isEmpty() || commanderNames.size() > 2) {
invalid.put("Oathbreaker", "Sideboard must contains 1 or 2 oathbreakers, but found: " + commanderNames.size()); invalid.put("Oathbreaker", "Sideboard must contains 1 or 2 oathbreakers, but found: " + commanderNames.size());
valid = false; valid = false;
} }
if (signatureSpells.size() == 0 || signatureSpells.size() > 2) { if (signatureSpells.isEmpty() || signatureSpells.size() > 2) {
invalid.put("Signature Spell", "Sideboard must contains 1 or 2 signature spells, but found: " + signatureSpells.size()); invalid.put("Signature Spell", "Sideboard must contains 1 or 2 signature spells, but found: " + signatureSpells.size());
valid = false; valid = false;
} }

View file

@ -79,7 +79,7 @@ public class PennyDreadfulCommander extends Constructed {
} }
} }
if (deck.getSideboard().size() < 1 || deck.getSideboard().size() > 2) { if (deck.getSideboard().isEmpty() || deck.getSideboard().size() > 2) {
invalid.put("Commander", "Sideboard must contain only the commander(s)"); invalid.put("Commander", "Sideboard must contain only the commander(s)");
valid = false; valid = false;
} else { } else {

View file

@ -1960,7 +1960,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
final int DECK_SIZE = deckMinSize != 0 ? deckMinSize : 40; final int DECK_SIZE = deckMinSize != 0 ? deckMinSize : 40;
List<Card> sortedCards = new ArrayList<>(cardPool); List<Card> sortedCards = new ArrayList<>(cardPool);
if (sortedCards.size() > 0) { if (!sortedCards.isEmpty()) {
while (deck.getCards().size() < DECK_SIZE) { while (deck.getCards().size() < DECK_SIZE) {
deck.getCards().add(sortedCards.get(RandomUtil.nextInt(sortedCards.size()))); deck.getCards().add(sortedCards.get(RandomUtil.nextInt(sortedCards.size())));
} }

View file

@ -68,7 +68,7 @@ class AncestralKnowledgeEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 10)); Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 10));
if (cards.size() > 0) { if (!cards.isEmpty()) {
controller.lookAtCards(source, null, cards, game); controller.lookAtCards(source, null, cards, game);
TargetCard target = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, new FilterCard("cards to exile")); TargetCard target = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, new FilterCard("cards to exile"));
controller.choose(Outcome.Exile, cards, target, game); controller.choose(Outcome.Exile, cards, target, game);

View file

@ -81,7 +81,7 @@ class BandTogetherEffect extends OneShotEffect {
return false; return false;
} }
Permanent permanentDamage1 = damageTarget.getTargets().size() < 1 ? null : game.getPermanent(damageTarget.getTargets().get(0)); Permanent permanentDamage1 = damageTarget.getTargets().isEmpty() ? null : game.getPermanent(damageTarget.getTargets().get(0));
Permanent permanentDamage2 = damageTarget.getTargets().size() < 2 ? null : game.getPermanent(damageTarget.getTargets().get(1)); Permanent permanentDamage2 = damageTarget.getTargets().size() < 2 ? null : game.getPermanent(damageTarget.getTargets().get(1));
Permanent permanentDest = game.getPermanent(destTarget.getTargets().get(0)); Permanent permanentDest = game.getPermanent(destTarget.getTargets().get(0));
if (permanentDest == null) { if (permanentDest == null) {

View file

@ -107,7 +107,7 @@ class CephalidSnitchEffect extends LoseAbilityTargetEffect{
objectColors.add(o); objectColors.add(o);
} }
//Construct a card filter excluding black //Construct a card filter excluding black
if(objectColors.size() > 0) { if(!objectColors.isEmpty()) {
FilterCard filter = new FilterCard(filterNameAssembler(objectColors)); FilterCard filter = new FilterCard(filterNameAssembler(objectColors));
if (objectColors.size() == 1) if (objectColors.size() == 1)
filter.add(new ColorPredicate(objectColors.get(0))); filter.add(new ColorPredicate(objectColors.get(0)));

View file

@ -125,7 +125,7 @@ class CurseOfThePiercedHeartEffect extends OneShotEffect {
if (opponent == null) { if (opponent == null) {
return false; return false;
} }
if (game.getBattlefield().getAllActivePermanents(new FilterPlaneswalkerPermanent(), opponentId, game).size() > 0) { if (!game.getBattlefield().getAllActivePermanents(new FilterPlaneswalkerPermanent(), opponentId, game).isEmpty()) {
if (controller.chooseUse(Outcome.Damage, "Redirect to a planeswalker controlled by " + opponent.getLogName() + "?", source, game)) { if (controller.chooseUse(Outcome.Damage, "Redirect to a planeswalker controlled by " + opponent.getLogName() + "?", source, game)) {
FilterPlaneswalkerPermanent filter = new FilterPlaneswalkerPermanent("a planeswalker controlled by " + opponent.getLogName()); FilterPlaneswalkerPermanent filter = new FilterPlaneswalkerPermanent("a planeswalker controlled by " + opponent.getLogName());
filter.add(new ControllerIdPredicate(opponentId)); filter.add(new ControllerIdPredicate(opponentId));

View file

@ -77,7 +77,7 @@ class ElementalAppealEffect extends OneShotEffect {
for (UUID tokenId : effect.getLastAddedTokenIds()) { for (UUID tokenId : effect.getLastAddedTokenIds()) {
predList.add(new CardIdPredicate(tokenId)); predList.add(new CardIdPredicate(tokenId));
} }
if (predList.size() > 0) { if (!predList.isEmpty()) {
FilterCreaturePermanent filter = new FilterCreaturePermanent(); FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.or(predList)); filter.add(Predicates.or(predList));
game.addEffect(new BoostAllEffect(7, 0, Duration.EndOfTurn, filter, false), source); game.addEffect(new BoostAllEffect(7, 0, Duration.EndOfTurn, filter, false), source);

View file

@ -70,7 +70,7 @@ enum FaceOfDivinityCondition implements Condition {
Permanent currentAura = game.getPermanent(source.getSourceId()); Permanent currentAura = game.getPermanent(source.getSourceId());
if (currentAura != null && currentAura.getAttachedTo() != null) { if (currentAura != null && currentAura.getAttachedTo() != null) {
Permanent permanent = game.getPermanent(currentAura.getAttachedTo()); Permanent permanent = game.getPermanent(currentAura.getAttachedTo());
if (permanent != null && permanent.getAttachments().size() > 0) { if (permanent != null && !permanent.getAttachments().isEmpty()) {
for (UUID id : permanent.getAttachments()) { for (UUID id : permanent.getAttachments()) {
Permanent otherAura = game.getPermanent(id); Permanent otherAura = game.getPermanent(id);
if (otherAura != null && !otherAura.getId().equals(currentAura.getId()) if (otherAura != null && !otherAura.getId().equals(currentAura.getId())

View file

@ -120,7 +120,7 @@ class FinaleOfPromiseEffect extends OneShotEffect {
} }
// ask to cast order // ask to cast order
if (cardsToCast.size() > 0) { if (!cardsToCast.isEmpty()) {
String cardsOrder = cardsToCast.stream() String cardsOrder = cardsToCast.stream()
.map(game::getCard) .map(game::getCard)
.filter(Objects::nonNull) .filter(Objects::nonNull)

View file

@ -69,8 +69,8 @@ class FloodOfTearsEffect extends OneShotEffect {
StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), source.getSourceId(), game StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), source.getSourceId(), game
); );
Cards cards = new CardsImpl(); Cards cards = new CardsImpl();
if (nonlands.size() > 0) { if (!nonlands.isEmpty()) {
nonlands.stream().forEach(permanent -> cards.add(permanent)); nonlands.forEach(cards::add);
boolean putIntoPlay = nonlands.stream() boolean putIntoPlay = nonlands.stream()
.filter(permanent -> permanent.isControlledBy(player.getId())) .filter(permanent -> permanent.isControlledBy(player.getId()))
.filter(permanent -> !(permanent instanceof Token)) .filter(permanent -> !(permanent instanceof Token))

View file

@ -75,7 +75,7 @@ class GeodeGolemEffect extends OneShotEffect {
} }
} }
if (possibleCommanders.size() == 0) { if (possibleCommanders.isEmpty()) {
return false; return false;
} }

View file

@ -106,7 +106,7 @@ class KarnPlus1Effect extends OneShotEffect {
cards.remove(cardToHand); cards.remove(cardToHand);
} }
if (cards.size() > 0) { if (!cards.isEmpty()) {
controller.moveCards(cards, Zone.EXILED, source, game); controller.moveCards(cards, Zone.EXILED, source, game);
for (Card c : cards.getCards(game)) { for (Card c : cards.getCards(game)) {
c.addCounters(CounterType.SILVER.createInstance(1), source, game); c.addCounters(CounterType.SILVER.createInstance(1), source, game);
@ -156,7 +156,6 @@ class KarnMinus1Effect extends OneShotEffect {
return true; return true;
} }
Set<Card> filtered = new HashSet<Card>();
Cards filteredCards = new CardsImpl(); Cards filteredCards = new CardsImpl();
for (Card exileCard : exile) { for (Card exileCard : exile) {

View file

@ -75,7 +75,7 @@ class KheruMindEaterExileEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source)); Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null && player.getHand().size() > 0) { if (player != null && !player.getHand().isEmpty()) {
Target target = new TargetCardInHand(1, new FilterCard()); Target target = new TargetCardInHand(1, new FilterCard());
target.chooseTarget(Outcome.Exile, player.getId(), source, game); target.chooseTarget(Outcome.Exile, player.getId(), source, game);
Card card = game.getCard(target.getFirstTarget()); Card card = game.getCard(target.getFirstTarget());