Merge pull request #2697 from sotovdev/master

Refactoring SQl query + unwanted ArrayList creation
This commit is contained in:
LevelX2 2016-12-21 15:48:01 +01:00 committed by GitHub
commit f0ba7d38a6
7 changed files with 71 additions and 70 deletions

View file

@ -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

View file

@ -71,7 +71,7 @@ public enum UserStatsRepository {
QueryBuilder<UserStats, Object> qb = dao.queryBuilder();
qb.limit(1L).where().eq("userName", userName);
List<UserStats> users = dao.query(qb.prepare());
if (users.size() == 1) {
if (!users.isEmpty()) {
return users.get(0);
}
} catch (SQLException ex) {
@ -95,7 +95,7 @@ public enum UserStatsRepository {
QueryBuilder<UserStats, Object> qb = dao.queryBuilder();
qb.orderBy("endTimeMs", false).limit(1L);
List<UserStats> users = dao.query(qb.prepare());
if (users.size() == 1) {
if (!users.isEmpty()) {
return users.get(0).getEndTimeMs();
}
} catch (SQLException ex) {

View file

@ -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;
}
}
}

View file

@ -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));
}

View file

@ -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() {

View file

@ -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;
@ -115,7 +116,7 @@ public enum ExpansionRepository {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.limit(1L).where().eq("code", new SelectArg(setCode));
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
if (expansions.size() > 0) {
if (!expansions.isEmpty()) {
set = expansions.get(0);
}
} catch (SQLException ex) {
@ -129,7 +130,7 @@ public enum ExpansionRepository {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.limit(1L).where().eq("name", new SelectArg(setName));
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
if (expansions.size() > 0) {
if (!expansions.isEmpty()) {
set = expansions.get(0);
}
} catch (SQLException ex) {
@ -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() {

View file

@ -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
}
}