mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Creating new ArrayList is unneccesarry
We shouldn't create new arraylist with default size and no element in it to show that no elements found in database. It's one more object in heap, which will be never used. There is special method Collections.emptyList() - it's more readeable and returns empty immutable list
This commit is contained in:
parent
e22951c68e
commit
2e83930ace
6 changed files with 67 additions and 66 deletions
|
@ -27,15 +27,6 @@
|
|||
*/
|
||||
package mage.player.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbility;
|
||||
|
@ -56,6 +47,9 @@ import mage.players.net.UserData;
|
|||
import mage.target.Target;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -63,12 +57,11 @@ import org.apache.log4j.Logger;
|
|||
public class SimulatedPlayer2 extends ComputerPlayer {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SimulatedPlayer2.class);
|
||||
private static PassAbility pass = new PassAbility();
|
||||
private final boolean isSimulatedPlayer;
|
||||
private final List<String> suggested;
|
||||
private transient ConcurrentLinkedQueue<Ability> allActions;
|
||||
private boolean forced;
|
||||
private static PassAbility pass = new PassAbility();
|
||||
|
||||
private final List<String> suggested;
|
||||
|
||||
public SimulatedPlayer2(UUID id, boolean isSimulatedPlayer, List<String> suggested) {
|
||||
super(id);
|
||||
|
@ -375,7 +368,7 @@ public class SimulatedPlayer2 extends ComputerPlayer {
|
|||
Map<Integer, Combat> engagements = new HashMap<>();
|
||||
int numGroups = game.getCombat().getGroups().size();
|
||||
if (numGroups == 0) {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
//add a node with no blockers
|
||||
|
|
|
@ -27,9 +27,6 @@
|
|||
*/
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
|
@ -46,6 +43,11 @@ import mage.players.Player;
|
|||
import mage.target.Target;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Effect for the DevourAbility
|
||||
*
|
||||
|
@ -68,37 +70,6 @@ public class DevourEffect extends ReplacementEffectImpl {
|
|||
}
|
||||
private final DevourFactor devourFactor;
|
||||
|
||||
public enum DevourFactor {
|
||||
|
||||
Devour1("Devour 1", "that many +1/+1 counters on it", 1),
|
||||
Devour2("Devour 2", "twice that many +1/+1 counters on it", 2),
|
||||
Devour3("Devour 3", "three times that many +1/+1 counters on it", 3),
|
||||
DevourX("Devour X, where X is the number of creatures devoured this way", "X +1/+1 counters on it for each of those creatures", Integer.MAX_VALUE);
|
||||
|
||||
private final String text;
|
||||
private final String ruleText;
|
||||
private final int factor;
|
||||
|
||||
DevourFactor(String text, String ruleText, int factor) {
|
||||
this.text = text;
|
||||
this.ruleText = ruleText;
|
||||
this.factor = factor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getRuleText() {
|
||||
return ruleText;
|
||||
}
|
||||
|
||||
public int getFactor() {
|
||||
return factor;
|
||||
}
|
||||
}
|
||||
|
||||
public DevourEffect(DevourFactor devourFactor) {
|
||||
super(Duration.EndOfGame, Outcome.Detriment);
|
||||
this.devourFactor = devourFactor;
|
||||
|
@ -184,7 +155,7 @@ public class DevourEffect extends ReplacementEffectImpl {
|
|||
if (object != null) {
|
||||
return (List<ArrayList<String>>) object;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public int getDevouredCreaturesAmount(Game game, UUID permanentId) {
|
||||
|
@ -199,4 +170,35 @@ public class DevourEffect extends ReplacementEffectImpl {
|
|||
public DevourEffect copy() {
|
||||
return new DevourEffect(this);
|
||||
}
|
||||
|
||||
public enum DevourFactor {
|
||||
|
||||
Devour1("Devour 1", "that many +1/+1 counters on it", 1),
|
||||
Devour2("Devour 2", "twice that many +1/+1 counters on it", 2),
|
||||
Devour3("Devour 3", "three times that many +1/+1 counters on it", 3),
|
||||
DevourX("Devour X, where X is the number of creatures devoured this way", "X +1/+1 counters on it for each of those creatures", Integer.MAX_VALUE);
|
||||
|
||||
private final String text;
|
||||
private final String ruleText;
|
||||
private final int factor;
|
||||
|
||||
DevourFactor(String text, String ruleText, int factor) {
|
||||
this.text = text;
|
||||
this.ruleText = ruleText;
|
||||
this.factor = factor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getRuleText() {
|
||||
return ruleText;
|
||||
}
|
||||
|
||||
public int getFactor() {
|
||||
return factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,6 @@ package mage.cards.repository;
|
|||
import com.j256.ormlite.field.DataType;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpellAbility;
|
||||
|
@ -48,6 +45,11 @@ import mage.constants.Rarity;
|
|||
import mage.constants.SpellAbilityType;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
|
@ -244,7 +246,7 @@ public class CardInfo {
|
|||
|
||||
private List<String> parseList(String list) {
|
||||
if (list.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.asList(list.split(SEPARATOR));
|
||||
}
|
||||
|
|
|
@ -37,16 +37,17 @@ import com.j256.ormlite.stmt.Where;
|
|||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.support.DatabaseConnection;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SetType;
|
||||
import mage.util.RandomUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
|
@ -339,7 +340,7 @@ public enum CardRepository {
|
|||
return cardDao.query(queryBuilder.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -392,7 +393,7 @@ public enum CardRepository {
|
|||
return cardDao.query(queryBuilder.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<CardInfo> findCardsCaseInsensitive(String name) {
|
||||
|
@ -409,7 +410,7 @@ public enum CardRepository {
|
|||
} catch (SQLException ex) {
|
||||
Logger.getLogger(CardRepository.class).error("Error during execution of raw sql statement", ex);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<CardInfo> findCards(CardCriteria criteria) {
|
||||
|
@ -421,7 +422,7 @@ public enum CardRepository {
|
|||
} catch (SQLException ex) {
|
||||
Logger.getLogger(CardRepository.class).error("Error during execution of card repository query statement", ex);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public long getContentVersionFromDB() {
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.apache.log4j.Logger;
|
|||
import java.io.File;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -144,7 +145,7 @@ public enum ExpansionRepository {
|
|||
return expansionDao.query(qb.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<String> getAllSetNames() {
|
||||
|
@ -159,7 +160,7 @@ public enum ExpansionRepository {
|
|||
return setNames;
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public long getContentVersionFromDB() {
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
package mage.target.targetpointer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FixedTarget implements TargetPointer {
|
||||
|
||||
private final UUID targetId;
|
||||
|
@ -76,7 +78,7 @@ public class FixedTarget implements TargetPointer {
|
|||
if (this.zoneChangeCounter > 0) { // will be zero if not defined in init
|
||||
Card card = game.getCard(targetId);
|
||||
if (card != null && card.getZoneChangeCounter(game) != this.zoneChangeCounter) {
|
||||
return new ArrayList<>(); // return empty
|
||||
return Collections.emptyList(); // return empty
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue