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:
vraskulin 2016-12-19 12:23:23 +03:00
parent e22951c68e
commit 2e83930ace
6 changed files with 67 additions and 66 deletions

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