CardDb: dont keep allCards list just use values collection

This commit is contained in:
Hans Mackowiak
2020-12-05 10:08:41 +01:00
parent 112b2badd2
commit db77e2861c
3 changed files with 7 additions and 9 deletions

View File

@@ -50,8 +50,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
private final Map<String, String> alternateName = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
private final Map<String, Integer> artIds = new HashMap<>();
private final List<PaperCard> allCards = new ArrayList<>();
private final List<PaperCard> roAllCards = Collections.unmodifiableList(allCards);
private final Collection<PaperCard> roAllCards = Collections.unmodifiableCollection(allCardsByName.values());
private final CardEdition.Collection editions;
public enum SetPreference {
@@ -247,10 +246,8 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
private void reIndex() {
uniqueCardsByName.clear();
allCards.clear();
for (Entry<String, Collection<PaperCard>> kv : allCardsByName.asMap().entrySet()) {
uniqueCardsByName.put(kv.getKey(), getFirstWithImage(kv.getValue()));
allCards.addAll(kv.getValue());
}
}
@@ -537,7 +534,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
}
@Override
public List<PaperCard> getAllCards() {
public Collection<PaperCard> getAllCards() {
return roAllCards;
}

View File

@@ -24,9 +24,9 @@ public interface ICardDatabase extends Iterable<PaperCard> {
int getArtCount(String cardName, String edition);
Collection<PaperCard> getUniqueCards();
List<PaperCard> getAllCards();
List<PaperCard> getAllCards(String cardName);
List<PaperCard> getAllCards(Predicate<PaperCard> predicate);
Collection<PaperCard> getAllCards();
Collection<PaperCard> getAllCards(String cardName);
Collection<PaperCard> getAllCards(Predicate<PaperCard> predicate);
List<PaperCard> getAllCardsFromEdition(CardEdition edition);

View File

@@ -27,6 +27,7 @@ import forge.util.storage.StorageReaderFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -102,7 +103,7 @@ public class QuestWorld implements Comparable<QuestWorld>{
return format;
}
public List<PaperCard> getAllCards() {
public Collection<PaperCard> getAllCards() {
GameFormat format0 = format;
if (format0 == null) {
format0 = FModel.getQuest().getMainFormat();