introduced StringUtil class with .isEmpty(String input) and .isNotEmpty(String input), to replace str != null && str.length()>0 statements

This commit is contained in:
ingmargoudt 2016-09-16 20:51:51 +02:00
parent fb15c79964
commit f1cf9e7adb
47 changed files with 132 additions and 96 deletions

View file

@ -87,6 +87,7 @@ import mage.client.util.gui.ArrowBuilder;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.EnlargeMode; import mage.constants.EnlargeMode;
import mage.remote.Session; import mage.remote.Session;
import mage.util.StringUtil;
import mage.view.AbilityView; import mage.view.AbilityView;
import mage.view.CardView; import mage.view.CardView;
import mage.view.CounterView; import mage.view.CounterView;
@ -248,7 +249,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
for (String rule : getRules()) { for (String rule : getRules()) {
sb.append("\n").append(rule); sb.append("\n").append(rule);
} }
if (card.getExpansionSetCode() != null && card.getExpansionSetCode().length() > 0) { if (StringUtil.isNotEmpty(card.getExpansionSetCode())) {
sb.append("\n").append(card.getCardNumber()).append(" - "); sb.append("\n").append(card.getCardNumber()).append(" - ");
sb.append(Sets.getInstance().get(card.getExpansionSetCode()).getName()).append(" - "); sb.append(Sets.getInstance().get(card.getExpansionSetCode()).getName()).append(" - ");
sb.append(card.getRarity().toString()); sb.append(card.getRarity().toString());

View file

@ -163,7 +163,7 @@ public class CardArea extends JPanel implements MouseListener {
private void loadCardsMany(CardsView showCards, BigCard bigCard, UUID gameId) { private void loadCardsMany(CardsView showCards, BigCard bigCard, UUID gameId) {
int rowsOfCards = 20; int rowsOfCards = 20;
int columns = 1; int columns = 1;
if (showCards != null && showCards.size() > 0) { if (showCards != null && !showCards.isEmpty()) {
Rectangle rectangle = new Rectangle(cardDimension.width, cardDimension.height); Rectangle rectangle = new Rectangle(cardDimension.width, cardDimension.height);
int count = 0; int count = 0;
for (CardView card : showCards.values()) { for (CardView card : showCards.values()) {

View file

@ -54,6 +54,7 @@ import static mage.client.constants.Constants.POWBOX_TEXT_MAX_TOP;
import mage.client.util.Config; import mage.client.util.Config;
import mage.client.util.ImageHelper; import mage.client.util.ImageHelper;
import mage.constants.CardType; import mage.constants.CardType;
import mage.util.StringUtil;
import mage.view.CounterView; import mage.view.CounterView;
import mage.view.PermanentView; import mage.view.PermanentView;
import org.mage.plugins.card.images.ImageCache; import org.mage.plugins.card.images.ImageCache;
@ -124,7 +125,7 @@ public class Permanent extends Card {
for (String rule: getRules()) { for (String rule: getRules()) {
sb.append("\n").append(rule); sb.append("\n").append(rule);
} }
if (permanent.getOriginal().getExpansionSetCode().length() > 0) { if (StringUtil.isNotEmpty(permanent.getOriginal().getExpansionSetCode())) {
sb.append("\n").append(permanent.getCardNumber()).append(" - "); sb.append("\n").append(permanent.getCardNumber()).append(" - ");
sb.append("\n").append(Sets.getInstance().get(permanent.getOriginal().getExpansionSetCode()).getName()).append(" - "); sb.append("\n").append(Sets.getInstance().get(permanent.getOriginal().getExpansionSetCode()).getName()).append(" - ");
sb.append(permanent.getOriginal().getRarity().toString()); sb.append(permanent.getOriginal().getRarity().toString());

View file

@ -42,6 +42,7 @@ import javax.swing.JTextField;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.SessionHandler; import mage.client.SessionHandler;
import mage.client.util.GUISizeHelper; import mage.client.util.GUISizeHelper;
import mage.util.StringUtil;
import mage.view.ChatMessage.MessageColor; import mage.view.ChatMessage.MessageColor;
import mage.view.ChatMessage.MessageType; import mage.view.ChatMessage.MessageType;
import org.mage.card.arcane.ManaSymbols; import org.mage.card.arcane.ManaSymbols;
@ -221,13 +222,13 @@ public class ChatPanelBasic extends javax.swing.JPanel {
textColor = MESSAGE_COLOR; textColor = MESSAGE_COLOR;
userSeparator = ": "; userSeparator = ": ";
} }
if (color.equals(MessageColor.ORANGE)) { if (color == MessageColor.ORANGE) {
textColor = "Orange"; textColor = "Orange";
} }
if (color.equals(MessageColor.YELLOW)) { if (color == MessageColor.YELLOW) {
textColor = "Yellow"; textColor = "Yellow";
} }
if (username != null && !username.isEmpty()) { if (StringUtil.isNotEmpty(username)) {
text.append(getColoredText(userColor, username + userSeparator)); text.append(getColoredText(userColor, username + userSeparator));
} }
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML(message, ManaSymbols.Type.CHAT))); text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML(message, ManaSymbols.Type.CHAT)));

View file

@ -51,7 +51,7 @@ public class MageTextArea extends JEditorPane {
text = text.replace("\r\n", "<div style='font-size:5pt'></div>"); text = text.replace("\r\n", "<div style='font-size:5pt'></div>");
final String basicText = ManaSymbols.replaceSymbolsWithHTML(text, ManaSymbols.Type.DIALOG); final String basicText = ManaSymbols.replaceSymbolsWithHTML(text, ManaSymbols.Type.DIALOG);
if (text.length() > 0) { if (!text.isEmpty()) {
buffer.append(basicText); buffer.append(basicText);
} }

View file

@ -296,7 +296,7 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
text = text.replace("\r\n", "<div style='font-size:5pt'></div>"); text = text.replace("\r\n", "<div style='font-size:5pt'></div>");
//text += "<br>"; //text += "<br>";
if (text.length() > 0) { if (!text.isEmpty()) {
buffer.append(ManaSymbols.replaceSymbolsWithHTML(text, ManaSymbols.Type.DIALOG)); buffer.append(ManaSymbols.replaceSymbolsWithHTML(text, ManaSymbols.Type.DIALOG));
} }

View file

@ -405,33 +405,25 @@ public class NewTableDialog extends MageDialog {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error creating table.", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error creating table.", "Error", JOptionPane.ERROR_MESSAGE);
return; return;
} }
try { if (SessionHandler.joinTable(
if (SessionHandler.joinTable( roomId,
roomId, table.getTableId(),
table.getTableId(), this.player1Panel.getPlayerName(),
this.player1Panel.getPlayerName(), "Human", 1,
"Human", 1, DeckImporterUtil.importDeck(this.player1Panel.getDeckFile()),
DeckImporterUtil.importDeck(this.player1Panel.getDeckFile()), this.txtPassword.getText())) {
this.txtPassword.getText())) { for (TablePlayerPanel player : players) {
for (TablePlayerPanel player : players) { if (!player.getPlayerType().equals("Human")) {
if (!player.getPlayerType().equals("Human")) { if (!player.joinTable(roomId, table.getTableId())) {
if (!player.joinTable(roomId, table.getTableId())) { // error message must be send by the server
// error message must be send by the server SessionHandler.removeTable(roomId, table.getTableId());
SessionHandler.removeTable(roomId, table.getTableId()); table = null;
table = null; return;
return;
}
} }
} }
this.hideDialog();
return;
} }
} catch (FileNotFoundException ex) { this.hideDialog();
handleError(ex); return;
} catch (IOException ex) {
handleError(ex);
} catch (ClassNotFoundException ex) {
handleError(ex);
} }
// JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining table.", "Error", JOptionPane.ERROR_MESSAGE); // JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining table.", "Error", JOptionPane.ERROR_MESSAGE);
SessionHandler.removeTable(roomId, table.getTableId()); SessionHandler.removeTable(roomId, table.getTableId());

View file

@ -2173,7 +2173,7 @@ public final class GamePanel extends javax.swing.JPanel {
choices, choices,
this.chosenHandKey); this.chosenHandKey);
if (newChosenHandKey != null && newChosenHandKey.length() > 0) { if (newChosenHandKey != null && !newChosenHandKey.isEmpty()) {
this.chosenHandKey = newChosenHandKey; this.chosenHandKey = newChosenHandKey;
CardsView cards = handCards.get(chosenHandKey); CardsView cards = handCards.get(chosenHandKey);
handContainer.loadCards(cards, bigCard, gameId); handContainer.loadCards(cards, bigCard, gameId);

View file

@ -69,7 +69,7 @@ public class TablePlayerPanel extends javax.swing.JPanel {
cbPlayerType.setSelectedIndex(cbPlayerType.getItemCount() - 1); cbPlayerType.setSelectedIndex(cbPlayerType.getItemCount() - 1);
} }
else { else {
Integer index = Integer.parseInt(Config.defaultOtherPlayerIndex); int index = Integer.parseInt(Config.defaultOtherPlayerIndex);
cbPlayerType.setSelectedIndex(index); cbPlayerType.setSelectedIndex(index);
} }
} }
@ -78,7 +78,7 @@ public class TablePlayerPanel extends javax.swing.JPanel {
} }
} }
public boolean joinTable(UUID roomId, UUID tableId) throws FileNotFoundException, IOException, ClassNotFoundException { public boolean joinTable(UUID roomId, UUID tableId) {
if (!this.cbPlayerType.getSelectedItem().equals("Human")) { if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
return SessionHandler.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), (String)this.cbPlayerType.getSelectedItem(), this.newPlayerPanel.getLevel(), DeckImporterUtil.importDeck(this.newPlayerPanel.getDeckFile()),""); return SessionHandler.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), (String)this.cbPlayerType.getSelectedItem(), this.newPlayerPanel.getLevel(), DeckImporterUtil.importDeck(this.newPlayerPanel.getDeckFile()),"");
} }

View file

@ -18,6 +18,7 @@ import mage.constants.CardType;
import mage.constants.MageObjectType; import mage.constants.MageObjectType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.util.StringUtil;
import mage.utils.CardUtil; import mage.utils.CardUtil;
import mage.view.CardView; import mage.view.CardView;
import mage.view.CounterView; import mage.view.CounterView;
@ -339,7 +340,7 @@ public class GuiDisplayUtil {
} }
String legal = rule.toString(); String legal = rule.toString();
if (legal.length() > 0) { if (StringUtil.isNotEmpty(legal)) {
legal = legal.replaceAll("\\{this\\}", card.getName().isEmpty() ? "this" : card.getName()); legal = legal.replaceAll("\\{this\\}", card.getName().isEmpty() ? "this" : card.getName());
legal = legal.replaceAll("\\{source\\}", card.getName().isEmpty() ? "this" : card.getName()); legal = legal.replaceAll("\\{source\\}", card.getName().isEmpty() ? "this" : card.getName());
buffer.append(ManaSymbols.replaceSymbolsWithHTML(legal, ManaSymbols.Type.TOOLTIP)); buffer.append(ManaSymbols.replaceSymbolsWithHTML(legal, ManaSymbols.Type.TOOLTIP));

View file

@ -32,6 +32,7 @@ import mage.client.plugins.impl.Plugins;
import mage.client.util.audio.AudioManager; import mage.client.util.audio.AudioManager;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.EnlargeMode; import mage.constants.EnlargeMode;
import mage.util.StringUtil;
import mage.view.AbilityView; import mage.view.AbilityView;
import mage.view.CardView; import mage.view.CardView;
import mage.view.PermanentView; import mage.view.PermanentView;
@ -725,7 +726,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
for (String rule : card.getRules()) { for (String rule : card.getRules()) {
sb.append("\n").append(rule); sb.append("\n").append(rule);
} }
if (card.getExpansionSetCode() != null && card.getExpansionSetCode().length() > 0) { if (StringUtil.isNotEmpty(card.getExpansionSetCode())) {
sb.append("\n").append(card.getCardNumber()).append(" - "); sb.append("\n").append(card.getCardNumber()).append(" - ");
sb.append(card.getExpansionSetCode()).append(" - "); sb.append(card.getExpansionSetCode()).append(" - ");
sb.append(card.getRarity().toString()); sb.append(card.getRarity().toString());

View file

@ -45,7 +45,17 @@ public class ChatMessage implements Serializable {
private MessageType messageType; private MessageType messageType;
public enum MessageColor { public enum MessageColor {
BLACK, RED, GREEN, BLUE, ORANGE, YELLOW; BLACK("Black"), RED("Red"), GREEN("Green"), BLUE("Blue"), ORANGE("Orange"), YELLOW("Yellow");
private String color;
MessageColor(String t){
color = t;
}
public String toString(){
return color;
}
} }
public enum MessageType { public enum MessageType {

View file

@ -597,15 +597,15 @@ public class User {
builder.append(proto.getMatches()); builder.append(proto.getMatches());
List<String> quit = new ArrayList<>(); List<String> quit = new ArrayList<>();
if (proto.getMatchesIdleTimeout() > 0) { if (proto.getMatchesIdleTimeout() > 0) {
quit.add("I:" + Integer.toString(proto.getMatchesIdleTimeout())); quit.add("I:" + proto.getMatchesIdleTimeout());//Integer.toString(proto.getMatchesIdleTimeout()));
} }
if (proto.getMatchesTimerTimeout() > 0) { if (proto.getMatchesTimerTimeout() > 0) {
quit.add("T:" + Integer.toString(proto.getMatchesTimerTimeout())); quit.add("T:" + proto.getMatchesTimerTimeout());//Integer.toString(proto.getMatchesTimerTimeout()));
} }
if (proto.getMatchesQuit() > 0) { if (proto.getMatchesQuit() > 0) {
quit.add("Q:" + Integer.toString(proto.getMatchesQuit())); quit.add("Q:" + proto.getMatchesQuit());//Integer.toString(proto.getMatchesQuit()));
} }
if (quit.size() > 0) { if (!quit.isEmpty()) {
builder.append(" ("); builder.append(" (");
joinStrings(builder, quit, " "); joinStrings(builder, quit, " ");
builder.append(")"); builder.append(")");
@ -629,15 +629,15 @@ public class User {
builder.append(proto.getTourneys()); builder.append(proto.getTourneys());
List<String> quit = new ArrayList<>(); List<String> quit = new ArrayList<>();
if (proto.getTourneysQuitDuringDrafting() > 0) { if (proto.getTourneysQuitDuringDrafting() > 0) {
quit.add("D:" + Integer.toString(proto.getTourneysQuitDuringDrafting())); quit.add("D:" + proto.getTourneysQuitDuringDrafting());//Integer.toString(proto.getTourneysQuitDuringDrafting()));
} }
if (proto.getTourneysQuitDuringConstruction() > 0) { if (proto.getTourneysQuitDuringConstruction() > 0) {
quit.add("C:" + Integer.toString(proto.getTourneysQuitDuringConstruction())); quit.add("C:" + proto.getTourneysQuitDuringConstruction());//Integer.toString(proto.getTourneysQuitDuringConstruction()));
} }
if (proto.getTourneysQuitDuringRound() > 0) { if (proto.getTourneysQuitDuringRound() > 0) {
quit.add("R:" + Integer.toString(proto.getTourneysQuitDuringRound())); quit.add("R:" + proto.getTourneysQuitDuringRound());//Integer.toString(proto.getTourneysQuitDuringRound()));
} }
if (quit.size() > 0) { if (!quit.isEmpty()) {
builder.append(" ("); builder.append(" (");
joinStrings(builder, quit, " "); joinStrings(builder, quit, " ");
builder.append(")"); builder.append(")");

View file

@ -206,26 +206,21 @@ public class ConditionalMana extends Mana implements Serializable {
break; break;
case BLUE: case BLUE:
blue += amount; blue += amount;
;
break; break;
case GREEN: case GREEN:
green += amount; green += amount;
;
break; break;
case RED: case RED:
red += amount; red += amount;
;
break; break;
case WHITE: case WHITE:
white += amount; white += amount;
;
break; break;
case COLORLESS: case COLORLESS:
colorless += amount; colorless += amount;
;
case GENERIC: case GENERIC:
generic += amount; generic += amount;
;
break; break;
} }
} }

View file

@ -39,6 +39,7 @@ import mage.abilities.keyword.ProtectionAbility;
import mage.abilities.mana.ManaAbility; import mage.abilities.mana.ManaAbility;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.util.StringUtil;
import mage.util.ThreadLocalStringBuilder; import mage.util.ThreadLocalStringBuilder;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -105,11 +106,10 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
rules.add(sbRule.toString()); rules.add(sbRule.toString());
} }
String rule = ability.getRule(); String rule = ability.getRule();
if (rule != null) { if (StringUtil.isNotEmpty(rule)){
if (rule.length() > 0) {
rules.add(Character.toUpperCase(rule.charAt(0)) + rule.substring(1)); rules.add(Character.toUpperCase(rule.charAt(0)) + rule.substring(1));
} }
} else { // logging so we can still can be made aware of rule problems a card has else { // logging so we can still can be made aware of rule problems a card has
String cardName = ((SpellAbility) ability).getCardName(); String cardName = ((SpellAbility) ability).getCardName();
logger.fatal("Error in rule text generation of " + cardName + ": Create a bug report or fix the source code"); logger.fatal("Error in rule text generation of " + cardName + ": Create a bug report or fix the source code");
} }

View file

@ -44,6 +44,7 @@ import mage.players.ManaPool;
import mage.players.Player; import mage.players.Player;
import mage.target.Targets; import mage.target.Targets;
import mage.util.ManaUtil; import mage.util.ManaUtil;
import mage.util.StringUtil;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -320,13 +321,13 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
this.add(cost.copy()); this.add(cost.copy());
} }
} else { } else {
if (mana == null || mana.isEmpty()) { if (StringUtil.isNotEmpty(mana)) {
return; return;
} }
String[] symbols = mana.split("^\\{|\\}\\{|\\}$"); String[] symbols = mana.split("^\\{|\\}\\{|\\}$");
int modifierForX = 0; int modifierForX = 0;
for (String symbol : symbols) { for (String symbol : symbols) {
if (symbol.length() > 0) { if (StringUtil.isNotEmpty(symbol)) {
if (symbol.length() == 1 || isNumeric(symbol)) { if (symbol.length() == 1 || isNumeric(symbol)) {
if (Character.isDigit(symbol.charAt(0))) { if (Character.isDigit(symbol.charAt(0))) {
this.add(new GenericManaCost(Integer.valueOf(symbol))); this.add(new GenericManaCost(Integer.valueOf(symbol)));

View file

@ -37,6 +37,7 @@ import mage.abilities.effects.ReplacementEffectImpl;
import mage.constants.Duration; import mage.constants.Duration;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.util.StringUtil;
/** /**
* *
@ -143,7 +144,7 @@ public class ConditionalReplacementEffect extends ReplacementEffectImpl {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
if (staticText == null || staticText.isEmpty() && this.effect != null) { // usefull for conditional night/day card abilities if (StringUtil.isEmpty(staticText) && this.effect != null) { // usefull for conditional night/day card abilities
return effect.getText(mode); return effect.getText(mode);
} }
return staticText; return staticText;

View file

@ -129,7 +129,7 @@ public class CreateTokenEffect extends OneShotEffect {
sb.append(" attacking"); sb.append(" attacking");
} }
String message = amount.getMessage(); String message = amount.getMessage();
if (message.length() > 0) { if (!message.isEmpty()) {
if (amount.toString().equals("X")) { if (amount.toString().equals("X")) {
sb.append(", where X is "); sb.append(", where X is ");
} else { } else {

View file

@ -80,7 +80,7 @@ public class CreateTokenTargetEffect extends OneShotEffect {
sb.append(" attacking"); sb.append(" attacking");
} }
String message = amount.getMessage(); String message = amount.getMessage();
if (message.length() > 0) { if (!message.isEmpty()) {
sb.append(" for each "); sb.append(" for each ");
} }
sb.append(message); sb.append(message);

View file

@ -36,6 +36,7 @@ import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.StringUtil;
/** /**
* *
@ -103,7 +104,7 @@ public class DamageControllerEffect extends OneShotEffect {
sb.append(amount); sb.append(amount);
} }
sb.append(" damage to you"); sb.append(" damage to you");
if (message.length() > 0) { if (StringUtil.isNotEmpty(message)) {
if (message.equals("1")) { if (message.equals("1")) {
sb.append(" equal to the number of "); sb.append(" equal to the number of ");
} else { } else {

View file

@ -37,6 +37,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.util.StringUtil;
import java.util.UUID; import java.util.UUID;
@ -142,7 +143,7 @@ public class DamageTargetEffect extends OneShotEffect {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) { if (StringUtil.isNotEmpty(staticText)) {
return staticText; return staticText;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -152,12 +153,12 @@ public class DamageTargetEffect extends OneShotEffect {
sb.append(amount); sb.append(amount);
} }
sb.append(" damage to "); sb.append(" damage to ");
if (targetDescription.length() > 0) { if (StringUtil.isNotEmpty(targetDescription)){
sb.append(targetDescription); sb.append(targetDescription);
} else { } else {
sb.append("target ").append(mode.getTargets().get(0).getTargetName()); sb.append("target ").append(mode.getTargets().get(0).getTargetName());
} }
if (message.length() > 0) { if (StringUtil.isNotEmpty(message)) {
if (message.equals("1")) { if (message.equals("1")) {
sb.append(" equal to the number of "); sb.append(" equal to the number of ");
} else { } else {

View file

@ -158,7 +158,7 @@ public class DontUntapInControllersNextUntapStepTargetEffect extends ContinuousR
if (staticText != null && !staticText.isEmpty()) { if (staticText != null && !staticText.isEmpty()) {
return staticText; return staticText;
} }
if (targetName != null && targetName.length() > 0) { if (targetName != null && !targetName.isEmpty()) {
if (targetName.equals("Those creatures") || targetName.equals("They")) { if (targetName.equals("Those creatures") || targetName.equals("They")) {
return targetName + " don't untap during their controller's next untap step"; return targetName + " don't untap during their controller's next untap step";
} else } else

View file

@ -36,6 +36,7 @@ import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.util.StringUtil;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -83,7 +84,7 @@ public class DrawCardSourceControllerEffect extends OneShotEffect {
sb.append("s"); sb.append("s");
} }
String message = amount.getMessage(); String message = amount.getMessage();
if (message.length() > 0) { if (StringUtil.isNotEmpty(message)) {
sb.append(" for each "); sb.append(" for each ");
} }
sb.append(message); sb.append(message);

View file

@ -136,7 +136,7 @@ public class DrawCardTargetEffect extends OneShotEffect {
sb.append("s"); sb.append("s");
} }
String message = amount.getMessage(); String message = amount.getMessage();
if (message.length() > 0) { if (!message.isEmpty()) {
sb.append(" for each "); sb.append(" for each ");
} }
sb.append(message); sb.append(message);

View file

@ -36,6 +36,7 @@ import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.util.StringUtil;
public class LoseLifeControllerAttachedEffect extends OneShotEffect { public class LoseLifeControllerAttachedEffect extends OneShotEffect {
@ -88,7 +89,7 @@ public class LoseLifeControllerAttachedEffect extends OneShotEffect {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("it's controller loses ").append(amount.toString()).append(" life"); sb.append("it's controller loses ").append(amount.toString()).append(" life");
String message = amount.getMessage(); String message = amount.getMessage();
if (message.length() > 0) { if (StringUtil.isNotEmpty(message)) {
sb.append(" for each "); sb.append(" for each ");
sb.append(message); sb.append(message);
} }

View file

@ -87,7 +87,7 @@ public class LoseLifeOpponentsEffect extends OneShotEffect {
sb.append(amount).append(" "); sb.append(amount).append(" ");
} }
sb.append("life"); sb.append("life");
if (message.length() > 0) { if (!message.isEmpty()) {
sb.append(message.equals("1") || message.startsWith("the ") ? " equal to the number of " : " for each "); sb.append(message.equals("1") || message.startsWith("the ") ? " equal to the number of " : " for each ");
sb.append(message); sb.append(message);
} }

View file

@ -35,6 +35,7 @@ import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.StringUtil;
/** /**
* *
@ -78,7 +79,7 @@ public class LoseLifeSourceControllerEffect extends OneShotEffect {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("you lose ").append(amount.toString()).append(" life"); sb.append("you lose ").append(amount.toString()).append(" life");
String message = amount.getMessage(); String message = amount.getMessage();
if (message.length() > 0) { if (StringUtil.isNotEmpty(message)) {
sb.append(" for each "); sb.append(" for each ");
} }
sb.append(message); sb.append(message);

View file

@ -35,6 +35,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.StringUtil;
/** /**
* *
@ -81,7 +82,7 @@ public class LoseLifeTargetEffect extends OneShotEffect {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String message = amount.getMessage(); String message = amount.getMessage();
if (mode.getTargets().size() > 0) { if (!mode.getTargets().isEmpty()) {
sb.append("target ").append(mode.getTargets().get(0).getTargetName()); sb.append("target ").append(mode.getTargets().get(0).getTargetName());
} else { } else {
sb.append("that player"); sb.append("that player");
@ -91,7 +92,7 @@ public class LoseLifeTargetEffect extends OneShotEffect {
sb.append(amount).append(" "); sb.append(amount).append(" ");
} }
sb.append("life"); sb.append("life");
if (message.length() > 0) { if (StringUtil.isNotEmpty(message)) {
if (amount.toString().equals("X")) { if (amount.toString().equals("X")) {
sb.append(", where X is "); sb.append(", where X is ");
} else { } else {

View file

@ -101,7 +101,7 @@ public class PutLibraryIntoGraveTargetEffect extends OneShotEffect {
} }
sb.append("of his or her library into his or her graveyard"); sb.append("of his or her library into his or her graveyard");
if (message.length() > 0) { if (!message.isEmpty()) {
sb.append(", where X is the number of "); sb.append(", where X is the number of ");
sb.append(message); sb.append(message);
} }

View file

@ -37,6 +37,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.game.Game; import mage.game.Game;
import mage.game.turn.TurnMod; import mage.game.turn.TurnMod;
import mage.players.Player; import mage.players.Player;
import mage.util.StringUtil;
/** /**
* *
@ -77,7 +78,7 @@ public class SkipNextPlayerUntapStepEffect extends OneShotEffect {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (staticText.length() > 0) { if (StringUtil.isNotEmpty(staticText)) {
sb.append(staticText); sb.append(staticText);
} else { } else {
sb.append("target"); sb.append("target");

View file

@ -37,6 +37,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.Target; import mage.target.Target;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.util.StringUtil;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -76,7 +77,7 @@ public class TapTargetEffect extends OneShotEffect {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
if (staticText.length() > 0) { if (StringUtil.isNotEmpty(staticText)) {
return "tap " + staticText; return "tap " + staticText;
} }

View file

@ -14,6 +14,7 @@ import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentCard; import mage.game.permanent.PermanentCard;
import mage.target.Target; import mage.target.Target;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.util.StringUtil;
/** /**
* *
@ -73,7 +74,7 @@ public class TransformTargetEffect extends OneShotEffect {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
if (staticText != null && staticText.length() > 0) { if (StringUtil.isNotEmpty(staticText)) {
return staticText; return staticText;
} }
if (mode.getTargets().isEmpty()) { if (mode.getTargets().isEmpty()) {

View file

@ -106,7 +106,7 @@ public class AssignNoCombatDamageSourceEffect extends ReplacementEffectImpl {
text += " this combat"; text += " this combat";
break; break;
default: default:
if (duration.toString().length() > 0) { if (!duration.toString().isEmpty()) {
text += " " + duration.toString(); text += " " + duration.toString();
} }
} }

View file

@ -118,11 +118,11 @@ public class BecomesColorOrColorsTargetEffect extends OneShotEffect {
return staticText; return staticText;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (mode.getTargets().size() > 0) { if (!mode.getTargets().isEmpty()) {
sb.append("target "); sb.append("target ");
sb.append(mode.getTargets().get(0).getFilter().getMessage()); sb.append(mode.getTargets().get(0).getFilter().getMessage());
sb.append(" becomes the color or colors of your choice"); sb.append(" becomes the color or colors of your choice");
if (duration.toString().length() > 0) { if (!duration.toString().isEmpty()) {
sb.append(" ").append(duration.toString()); sb.append(" ").append(duration.toString());
} }
} }

View file

@ -39,6 +39,7 @@ import mage.filter.FilterPermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.permanent.token.Token; import mage.game.permanent.token.Token;
import mage.util.StringUtil;
/** /**
* @author LevelX2 * @author LevelX2
@ -76,13 +77,11 @@ public class BecomesCreatureAllEffect extends ContinuousEffectImpl {
switch (layer) { switch (layer) {
case TypeChangingEffects_4: case TypeChangingEffects_4:
if (sublayer == SubLayer.NA) { if (sublayer == SubLayer.NA) {
if (token.getCardType().size() > 0) {
for (CardType t : token.getCardType()) { for (CardType t : token.getCardType()) {
if (!permanent.getCardType().contains(t)) { if (!permanent.getCardType().contains(t)) {
permanent.getCardType().add(t); permanent.getCardType().add(t);
} }
} }
}
if (type == null) { if (type == null) {
permanent.getSubtype(game).clear(); permanent.getSubtype(game).clear();
} }
@ -140,7 +139,7 @@ public class BecomesCreatureAllEffect extends ContinuousEffectImpl {
} }
sb.append(filter.getMessage()); sb.append(filter.getMessage());
sb.append(" become a ").append(token.getDescription()); sb.append(" become a ").append(token.getDescription());
if (type != null && type.length() > 0) { if (StringUtil.isNotEmpty(type)) {
sb.append(". They are still ").append(type); sb.append(". They are still ").append(type);
} }
return sb.toString(); return sb.toString();

View file

@ -172,7 +172,7 @@ public class BecomesCreatureSourceEffect extends ContinuousEffectImpl implements
} }
private void setText() { private void setText() {
if (type != null && type.length() > 0) { if (type != null && !type.isEmpty()) {
staticText = duration.toString() + " {this} becomes a " + token.getDescription() + " that's still a " + this.type; staticText = duration.toString() + " {this} becomes a " + token.getDescription() + " that's still a " + this.type;
} else { } else {
staticText = duration.toString() + " {this} becomes a " + token.getDescription(); staticText = duration.toString() + " {this} becomes a " + token.getDescription();

View file

@ -134,7 +134,7 @@ public class BoostEnchantedEffect extends ContinuousEffectImpl {
sb.append(" ").append(duration.toString()); sb.append(" ").append(duration.toString());
} }
String message = power.getMessage(); String message = power.getMessage();
if (message.length() > 0) { if (!message.isEmpty()) {
sb.append(" for each "); sb.append(" for each ");
} }
sb.append(message); sb.append(message);

View file

@ -39,6 +39,7 @@ import mage.abilities.effects.ContinuousEffectImpl;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import mage.util.StringUtil;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -132,7 +133,7 @@ public class BoostEquippedEffect extends ContinuousEffectImpl {
if (duration != Duration.WhileOnBattlefield) if (duration != Duration.WhileOnBattlefield)
sb.append(" ").append(duration.toString()); sb.append(" ").append(duration.toString());
String message = power.getMessage(); String message = power.getMessage();
if (message.length() > 0) { if (StringUtil.isNotEmpty(message)) {
sb.append(" for each "); sb.append(" for each ");
} }
sb.append(message); sb.append(message);

View file

@ -36,6 +36,7 @@ import mage.counters.Counter;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.util.StringUtil;
/** /**
* *
@ -101,7 +102,7 @@ public class AddCountersAttachedEffect extends OneShotEffect {
} }
sb.append(counter.getName().toLowerCase()).append(" counter on "); sb.append(counter.getName().toLowerCase()).append(" counter on ");
sb.append(textEnchanted); sb.append(textEnchanted);
if (amount.getMessage().length() > 0) { if (StringUtil.isNotEmpty(amount.getMessage())) {
sb.append(" for each ").append(amount.getMessage()); sb.append(" for each ").append(amount.getMessage());
} }
staticText = sb.toString(); staticText = sb.toString();

View file

@ -43,6 +43,7 @@ import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.util.StringUtil;
/** /**
* *
@ -164,7 +165,7 @@ public class AddCountersTargetEffect extends OneShotEffect {
sb.append("that creature"); sb.append("that creature");
} }
if (amount.getMessage().length() > 0) { if (StringUtil.isNotEmpty(amount.getMessage())) {
sb.append(" for each ").append(amount.getMessage()); sb.append(" for each ").append(amount.getMessage());
} }
return sb.toString(); return sb.toString();

View file

@ -36,6 +36,7 @@ import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.util.StringUtil;
/** /**
* *
@ -116,7 +117,7 @@ public class DiscardControllerEffect extends OneShotEffect {
sb.append(" at random"); sb.append(" at random");
} }
String message = amount.getMessage(); String message = amount.getMessage();
if (message.length() > 0) { if (StringUtil.isNotEmpty(message)) {
sb.append(" for each "); sb.append(" for each ");
} }
sb.append(message); sb.append(message);

View file

@ -35,6 +35,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.StringUtil;
/** /**
* *
@ -80,11 +81,11 @@ public class DiscardHandTargetEffect extends OneShotEffect {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) { if (StringUtil.isNotEmpty(staticText)) {
return staticText; return staticText;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (targetDescription.length() > 0) { if (StringUtil.isNotEmpty(targetDescription)) {
sb.append(targetDescription); sb.append(targetDescription);
} else { } else {
sb.append("target ").append(mode.getTargets().get(0).getTargetName()); sb.append("target ").append(mode.getTargets().get(0).getTargetName());

View file

@ -36,6 +36,7 @@ import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.util.StringUtil;
/** /**
* *
@ -95,7 +96,7 @@ public class DiscardTargetEffect extends OneShotEffect {
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) { if (StringUtil.isNotEmpty(staticText)) {
return staticText; return staticText;
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -114,7 +115,7 @@ public class DiscardTargetEffect extends OneShotEffect {
sb.append(" at random"); sb.append(" at random");
} }
String message = amount.getMessage(); String message = amount.getMessage();
if (message.length() > 0) { if (StringUtil.isNotEmpty(message)) {
sb.append(" for each "); sb.append(" for each ");
} }
sb.append(message); sb.append(message);

View file

@ -44,6 +44,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.util.StringUtil;
/** /**
* *
@ -104,7 +105,7 @@ public class ManifestTargetPlayerEffect extends OneShotEffect {
private String setText() { private String setText() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (prefix != null && !prefix.isEmpty()) { if (StringUtil.isNotEmpty(prefix)) {
sb.append(prefix).append(" "); sb.append(prefix).append(" ");
} }
sb.append("manifest the top "); sb.append("manifest the top ");

View file

@ -133,7 +133,7 @@ class CascadeEffect extends OneShotEffect {
Cards cardsFromExile = new CardsImpl(); Cards cardsFromExile = new CardsImpl();
Cards cardsToLibrary = new CardsImpl(); Cards cardsToLibrary = new CardsImpl();
cardsFromExile.addAll(exile); cardsFromExile.addAll(exile);
while (cardsFromExile.size() > 0) { while (!cardsFromExile.isEmpty()) {
card = cardsFromExile.getRandom(game); card = cardsFromExile.getRandom(game);
cardsFromExile.remove(card.getId()); cardsFromExile.remove(card.getId());
cardsToLibrary.add(card); cardsToLibrary.add(card);

View file

@ -46,6 +46,7 @@ import mage.constants.ColoredManaSymbol;
import mage.util.ClassScanner; import mage.util.ClassScanner;
import mage.util.RandomUtil; import mage.util.RandomUtil;
import mage.util.StringUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
@ -138,10 +139,11 @@ public class Sets extends HashMap<String, ExpansionSet> {
Map<String, DeckCardInfo> deckCards = new HashMap<>(); Map<String, DeckCardInfo> deckCards = new HashMap<>();
Map<String, DeckCardInfo> sideboard = new HashMap<>(); Map<String, DeckCardInfo> sideboard = new HashMap<>();
try { try {
if (deck.getName() != null && deck.getName().length() > 0) {
if (StringUtil.isNotEmpty(deck.getName())) {
out.println("NAME:" + deck.getName()); out.println("NAME:" + deck.getName());
} }
if (deck.getAuthor() != null && deck.getAuthor().length() > 0) { if (StringUtil.isNotEmpty(deck.getAuthor())) {
out.println("AUTHOR:" + deck.getAuthor()); out.println("AUTHOR:" + deck.getAuthor());
} }
for (DeckCardInfo deckCardInfo: deck.getCards()) { for (DeckCardInfo deckCardInfo: deck.getCards()) {

View file

@ -0,0 +1,15 @@
package mage.util;
/**
* Created by IGOUDT on 16-9-2016.
*/
public class StringUtil {
public static boolean isEmpty(String input){
return (input == null) || input.isEmpty();
}
public static boolean isNotEmpty(String input){
return !isEmpty(input);
}
}