mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
* Following the ideas implemented in java.util.collections, IStorageView interface removed, the base class is read-only by default.
* isUnique removed for being synonym for !contains * QuestDeckMap inherited correctly from StorageBase to avoid duplicate code.
This commit is contained in:
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -15178,12 +15178,11 @@ src/main/java/forge/util/maps/TreeMapToAmount.java -text
|
||||
src/main/java/forge/util/maps/package-info.java -text
|
||||
src/main/java/forge/util/package-info.java -text
|
||||
src/main/java/forge/util/storage/IStorage.java -text
|
||||
src/main/java/forge/util/storage/IStorageView.java -text
|
||||
src/main/java/forge/util/storage/StorageBase.java -text
|
||||
src/main/java/forge/util/storage/StorageImmediatelySerialized.java svneol=native#text/plain
|
||||
src/main/java/forge/util/storage/StorageReaderFile.java -text
|
||||
src/main/java/forge/util/storage/StorageReaderFileSections.java -text
|
||||
src/main/java/forge/util/storage/StorageReaderFolder.java -text
|
||||
src/main/java/forge/util/storage/StorageView.java -text
|
||||
src/main/java/forge/util/storage/package-info.java -text
|
||||
src/main/java/forge/view/ButtonUtil.java svneol=native#text/plain
|
||||
src/main/java/forge/view/FView.java -text
|
||||
|
||||
@@ -27,9 +27,9 @@ import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.util.IItemReader;
|
||||
import forge.util.storage.StorageView;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
public final class EditionCollection extends StorageView<CardEdition> {
|
||||
public final class EditionCollection extends StorageBase<CardEdition> {
|
||||
|
||||
private final Map<String, CardEdition> aliasToEdition = new TreeMap<String, CardEdition>();
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ import java.util.List;
|
||||
import forge.game.GameFormat;
|
||||
import forge.util.FileSection;
|
||||
import forge.util.storage.StorageReaderFileSections;
|
||||
import forge.util.storage.StorageView;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
/**
|
||||
* The Class FormatUtils.
|
||||
*/
|
||||
public final class FormatCollection extends StorageView<GameFormat> {
|
||||
public final class FormatCollection extends StorageBase<GameFormat> {
|
||||
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class FormatCollection extends StorageView<GameFormat> {
|
||||
* @return the standard
|
||||
*/
|
||||
public GameFormat getStandard() {
|
||||
return getMap().get("Standard");
|
||||
return this.map.get("Standard");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ public final class FormatCollection extends StorageView<GameFormat> {
|
||||
* @return the extended
|
||||
*/
|
||||
public GameFormat getExtended() {
|
||||
return getMap().get("Extended");
|
||||
return this.map.get("Extended");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +64,7 @@ public final class FormatCollection extends StorageView<GameFormat> {
|
||||
* @return the modern
|
||||
*/
|
||||
public GameFormat getModern() {
|
||||
return getMap().get("Modern");
|
||||
return this.map.get("Modern");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ public final class FormatCollection extends StorageView<GameFormat> {
|
||||
* @return the requested format
|
||||
*/
|
||||
public GameFormat getFormat(String format) {
|
||||
return getMap().get(format);
|
||||
return this.map.get(format);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,6 @@ import forge.util.Aggregates;
|
||||
import forge.util.Lang;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.util.storage.IStorageView;
|
||||
|
||||
/**
|
||||
* Utility collection for various types of decks.
|
||||
@@ -155,7 +154,7 @@ public class DeckgenUtil {
|
||||
}
|
||||
|
||||
public static Deck getRandomPreconDeck() {
|
||||
final IStorageView<PreconDeck> allDecks = QuestController.getPrecons();
|
||||
final IStorage<PreconDeck> allDecks = QuestController.getPrecons();
|
||||
final int rand = (int) (Math.floor(Math.random() * allDecks.size()));
|
||||
final String name = allDecks.getNames().toArray(new String[0])[rand];
|
||||
return allDecks.get(name).getDeck();
|
||||
|
||||
@@ -49,7 +49,7 @@ import forge.item.ItemPoolView;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.HttpUtil;
|
||||
import forge.util.storage.IStorageView;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -94,7 +94,7 @@ public final class BoosterDraft implements IBoosterDraft {
|
||||
case Block: case FantasyBlock: // Draft from cards by block or set
|
||||
|
||||
List<CardBlock> blocks = new ArrayList<CardBlock>();
|
||||
IStorageView<CardBlock> storage = draftType == LimitedPoolType.Block
|
||||
IStorage<CardBlock> storage = draftType == LimitedPoolType.Block
|
||||
? Singletons.getModel().getBlocks() : Singletons.getModel().getFantasyBlocks();
|
||||
|
||||
for (CardBlock b : storage) {
|
||||
|
||||
@@ -35,7 +35,7 @@ import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.FileSection;
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.storage.IStorageView;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -89,7 +89,7 @@ public class CustomLimited extends DeckBase {
|
||||
* @param cubes the cubes
|
||||
* @return the custom limited
|
||||
*/
|
||||
public static CustomLimited parse(final List<String> dfData, final IStorageView<Deck> cubes) {
|
||||
public static CustomLimited parse(final List<String> dfData, final IStorage<Deck> cubes) {
|
||||
|
||||
final FileSection data = FileSection.parse(dfData, ":");
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ public class DeckController<T extends DeckBase> {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean fileExists(final String deckName) {
|
||||
return !this.folder.isUnique(deckName);
|
||||
return this.folder.contains(deckName);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -40,7 +40,7 @@ import forge.item.PreconDeck;
|
||||
import forge.quest.QuestController;
|
||||
import forge.quest.QuestWorld;
|
||||
import forge.quest.StartingPoolType;
|
||||
import forge.util.storage.IStorageView;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
/**
|
||||
* Assembles Swing components of quest data submenu singleton.
|
||||
@@ -248,7 +248,7 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
||||
cboAllowUnlocks.setSelected(true);
|
||||
|
||||
final Map<String, String> preconDescriptions = new HashMap<String, String>();
|
||||
IStorageView<PreconDeck> preconDecks = QuestController.getPrecons();
|
||||
IStorage<PreconDeck> preconDecks = QuestController.getPrecons();
|
||||
|
||||
for (PreconDeck preconDeck : preconDecks) {
|
||||
if (preconDeck.getRecommendedDeals().getMinWins() > 0) {
|
||||
|
||||
@@ -181,7 +181,7 @@ public enum CSubmenuSealed implements ICDoc {
|
||||
|
||||
final IStorage<DeckGroup> sealedDecks = Singletons.getModel().getDecks().getSealed();
|
||||
|
||||
if (!(sealedDecks.isUnique(sDeckName))) {
|
||||
if (sealedDecks.contains(sDeckName)) {
|
||||
final int deleteDeck = JOptionPane.showConfirmDialog(null, "\"" + sDeckName
|
||||
+ "\" already exists! Do you want to replace it?",
|
||||
"Sealed Deck Game Exists", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
@@ -35,7 +35,6 @@ import forge.quest.QuestEvent;
|
||||
import forge.quest.QuestEventChallenge;
|
||||
import forge.quest.QuestUtil;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.util.storage.IStorageView;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class FDeckChooser extends JPanel {
|
||||
@@ -217,7 +216,7 @@ public class FDeckChooser extends JPanel {
|
||||
lst.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
|
||||
final List<String> customNames = new ArrayList<String>();
|
||||
final IStorageView<PreconDeck> allDecks = QuestController.getPrecons();
|
||||
final IStorage<PreconDeck> allDecks = QuestController.getPrecons();
|
||||
for (final PreconDeck d : allDecks) { customNames.add(d.getName()); }
|
||||
|
||||
lst.setListData(customNames.toArray(ArrayUtils.EMPTY_STRING_ARRAY));
|
||||
|
||||
@@ -50,8 +50,8 @@ import forge.quest.QuestWorld;
|
||||
import forge.quest.data.QuestPreferences;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.MultiplexOutputStream;
|
||||
import forge.util.storage.IStorageView;
|
||||
import forge.util.storage.StorageView;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.util.storage.StorageBase;
|
||||
import forge.view.FView;
|
||||
|
||||
/**
|
||||
@@ -81,14 +81,14 @@ public class FModel {
|
||||
|
||||
private final EditionCollection editions;
|
||||
private final FormatCollection formats;
|
||||
private final IStorageView<SealedProductTemplate> boosters;
|
||||
private final IStorageView<SealedProductTemplate> specialBoosters;
|
||||
private final IStorageView<SealedProductTemplate> tournaments;
|
||||
private final IStorageView<FatPackTemplate> fatPacks;
|
||||
private final IStorageView<CardBlock> blocks;
|
||||
private final IStorageView<CardBlock> fantasyBlocks;
|
||||
private final IStorageView<QuestWorld> worlds;
|
||||
private final IStorageView<PrintSheet> printSheets;
|
||||
private final IStorage<SealedProductTemplate> boosters;
|
||||
private final IStorage<SealedProductTemplate> specialBoosters;
|
||||
private final IStorage<SealedProductTemplate> tournaments;
|
||||
private final IStorage<FatPackTemplate> fatPacks;
|
||||
private final IStorage<CardBlock> blocks;
|
||||
private final IStorage<CardBlock> fantasyBlocks;
|
||||
private final IStorage<QuestWorld> worlds;
|
||||
private final IStorage<PrintSheet> printSheets;
|
||||
|
||||
|
||||
private static FModel instance = null;
|
||||
@@ -160,13 +160,13 @@ public class FModel {
|
||||
|
||||
|
||||
this.formats = new FormatCollection("res/blockdata/formats.txt");
|
||||
this.boosters = new StorageView<SealedProductTemplate>(editions.getBoosterGenerator());
|
||||
this.specialBoosters = new StorageView<SealedProductTemplate>(new SealedProductTemplate.Reader("res/blockdata/boosters-special.txt"));
|
||||
this.tournaments = new StorageView<SealedProductTemplate>(new SealedProductTemplate.Reader("res/blockdata/starters.txt"));
|
||||
this.fatPacks = new StorageView<FatPackTemplate>(new FatPackTemplate.Reader("res/blockdata/fatpacks.txt"));
|
||||
this.blocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/blocks.txt", editions));
|
||||
this.fantasyBlocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/fantasyblocks.txt", editions));
|
||||
this.worlds = new StorageView<QuestWorld>(new QuestWorld.Reader("res/quest/world/worlds.txt"));
|
||||
this.boosters = new StorageBase<SealedProductTemplate>(editions.getBoosterGenerator());
|
||||
this.specialBoosters = new StorageBase<SealedProductTemplate>(new SealedProductTemplate.Reader("res/blockdata/boosters-special.txt"));
|
||||
this.tournaments = new StorageBase<SealedProductTemplate>(new SealedProductTemplate.Reader("res/blockdata/starters.txt"));
|
||||
this.fatPacks = new StorageBase<FatPackTemplate>(new FatPackTemplate.Reader("res/blockdata/fatpacks.txt"));
|
||||
this.blocks = new StorageBase<CardBlock>(new CardBlock.Reader("res/blockdata/blocks.txt", editions));
|
||||
this.fantasyBlocks = new StorageBase<CardBlock>(new CardBlock.Reader("res/blockdata/fantasyblocks.txt", editions));
|
||||
this.worlds = new StorageBase<QuestWorld>(new QuestWorld.Reader("res/quest/world/worlds.txt"));
|
||||
// TODO - there's got to be a better place for this...oblivion?
|
||||
Preferences.DEV_MODE = this.preferences.getPrefBoolean(FPref.DEV_MODE_ENABLED);
|
||||
|
||||
@@ -178,7 +178,7 @@ public class FModel {
|
||||
this.decks = new CardCollections();
|
||||
this.quest = new QuestController();
|
||||
|
||||
this.printSheets = new StorageView<PrintSheet>(new PrintSheet.Reader("res/blockdata/printsheets.txt"));
|
||||
this.printSheets = new StorageBase<PrintSheet>(new PrintSheet.Reader("res/blockdata/printsheets.txt"));
|
||||
|
||||
// Preload AI profiles
|
||||
AiProfileUtil.loadAllProfiles();
|
||||
@@ -346,7 +346,7 @@ public class FModel {
|
||||
*
|
||||
* @return the worlds
|
||||
*/
|
||||
public final IStorageView<QuestWorld> getWorlds() {
|
||||
public final IStorage<QuestWorld> getWorlds() {
|
||||
return this.worlds;
|
||||
}
|
||||
|
||||
@@ -361,35 +361,35 @@ public class FModel {
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.CardBlock}> */
|
||||
public IStorageView<CardBlock> getBlocks() {
|
||||
public IStorage<CardBlock> getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.CardBlock}> */
|
||||
public IStorageView<CardBlock> getFantasyBlocks() {
|
||||
public IStorage<CardBlock> getFantasyBlocks() {
|
||||
return fantasyBlocks;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.FatPackTemplate}> */
|
||||
public IStorageView<FatPackTemplate> getFatPacks() {
|
||||
public IStorage<FatPackTemplate> getFatPacks() {
|
||||
return fatPacks;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
|
||||
public final IStorageView<SealedProductTemplate> getTournamentPacks() {
|
||||
public final IStorage<SealedProductTemplate> getTournamentPacks() {
|
||||
return tournaments;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
|
||||
public final IStorageView<SealedProductTemplate> getBoosters() {
|
||||
public final IStorage<SealedProductTemplate> getBoosters() {
|
||||
return boosters;
|
||||
}
|
||||
|
||||
public final IStorageView<SealedProductTemplate> getSpecialBoosters() {
|
||||
public final IStorage<SealedProductTemplate> getSpecialBoosters() {
|
||||
return specialBoosters;
|
||||
}
|
||||
|
||||
public IStorageView<PrintSheet> getPrintSheets() {
|
||||
public IStorage<PrintSheet> getPrintSheets() {
|
||||
return printSheets;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,7 @@ import forge.quest.data.QuestPreferences.DifficultyPrefs;
|
||||
import forge.quest.io.PreconReader;
|
||||
import forge.quest.io.QuestChallengeReader;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.util.storage.IStorageView;
|
||||
import forge.util.storage.StorageView;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
@@ -71,14 +70,14 @@ public class QuestController {
|
||||
private transient IStorage<Deck> decks;
|
||||
|
||||
private QuestEventDuelManager duelManager = null;
|
||||
private IStorageView<QuestEventChallenge> allChallenges = null;
|
||||
private IStorage<QuestEventChallenge> allChallenges = null;
|
||||
|
||||
private QuestBazaarManager bazaar = null;
|
||||
|
||||
private QuestPetStorage pets = null;
|
||||
|
||||
// This is used by shop. Had no idea where else to place this
|
||||
private static transient IStorageView<PreconDeck> preconManager = null;
|
||||
private static transient IStorage<PreconDeck> preconManager = null;
|
||||
|
||||
/** The Constant RANK_TITLES. */
|
||||
public static final String[] RANK_TITLES = new String[] { "Level 0 - Confused Wizard", "Level 1 - Mana Mage",
|
||||
@@ -175,9 +174,9 @@ public class QuestController {
|
||||
*
|
||||
* @return QuestPreconManager
|
||||
*/
|
||||
public static IStorageView<PreconDeck> getPrecons() {
|
||||
public static IStorage<PreconDeck> getPrecons() {
|
||||
if (null == preconManager) {
|
||||
preconManager = new StorageView<PreconDeck>(new PreconReader(new File(NewConstants.QUEST_PRECON_DIR)));
|
||||
preconManager = new StorageBase<PreconDeck>(new PreconReader(new File(NewConstants.QUEST_PRECON_DIR)));
|
||||
}
|
||||
|
||||
return QuestController.preconManager;
|
||||
@@ -368,7 +367,7 @@ public class QuestController {
|
||||
* TODO: Write javadoc for this method.
|
||||
* @return QuestEventManager
|
||||
*/
|
||||
public IStorageView<QuestEventChallenge> getChallenges() {
|
||||
public IStorage<QuestEventChallenge> getChallenges() {
|
||||
if (this.allChallenges == null) {
|
||||
resetChallengesManager();
|
||||
}
|
||||
@@ -392,7 +391,7 @@ public class QuestController {
|
||||
public void resetChallengesManager() {
|
||||
QuestWorld world = getWorld();
|
||||
String path = world == null || world.getChallengesDir() == null ? NewConstants.DEFAULT_CHALLENGES_DIR : "res/quest/world/" + world.getChallengesDir();
|
||||
this.allChallenges = new StorageView<QuestEventChallenge>(new QuestChallengeReader(new File(path)));
|
||||
this.allChallenges = new StorageBase<QuestEventChallenge>(new QuestChallengeReader(new File(path)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,70 +17,24 @@
|
||||
*/
|
||||
package forge.quest;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class QuestDeckMap implements IStorage<Deck> {
|
||||
public class QuestDeckMap extends StorageBase<Deck> {
|
||||
|
||||
/**
|
||||
* Instantiates a new quest deck map.
|
||||
*/
|
||||
public QuestDeckMap() {
|
||||
this.map = new HashMap<String, Deck>();
|
||||
public QuestDeckMap(Map<String, Deck> in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new quest deck map.
|
||||
*
|
||||
* @param inMap the in map
|
||||
*/
|
||||
public QuestDeckMap(final Map<String, Deck> inMap) {
|
||||
this.map = inMap;
|
||||
}
|
||||
|
||||
private final Map<String, Deck> map;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.util.IFolderMapView#get(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Deck get(final String name) {
|
||||
return this.map.get(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.util.IFolderMapView#getNames()
|
||||
*/
|
||||
@Override
|
||||
public Collection<String> getNames() {
|
||||
return this.map.keySet();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Iterable#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Deck> iterator() {
|
||||
return this.map.values().iterator();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -102,38 +56,4 @@ public class QuestDeckMap implements IStorage<Deck> {
|
||||
this.map.remove(deckName);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.util.IFolderMap#isUnique(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isUnique(final String name) {
|
||||
return !this.map.containsKey(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.util.IFolderMapView#any(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(String name) {
|
||||
return map.containsKey(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.util.IStorageView#getCount()
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.util.storage.IStorageView#find(com.google.common.base.Predicate)
|
||||
*/
|
||||
@Override
|
||||
public Deck find(Predicate<Deck> condition) {
|
||||
return Iterables.tryFind(map.values(), condition).orNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import forge.quest.io.QuestDuelReader;
|
||||
import forge.util.maps.CollectionSuppliers;
|
||||
import forge.util.maps.EnumMapOfLists;
|
||||
import forge.util.maps.MapOfLists;
|
||||
import forge.util.storage.IStorageView;
|
||||
import forge.util.storage.StorageView;
|
||||
import forge.util.storage.IStorage;
|
||||
import forge.util.storage.StorageBase;
|
||||
|
||||
/**
|
||||
* QuestEventManager.
|
||||
@@ -43,13 +43,13 @@ import forge.util.storage.StorageView;
|
||||
public class QuestEventDuelManager {
|
||||
|
||||
private final MapOfLists<QuestEventDifficulty, QuestEventDuel> sortedDuels = new EnumMapOfLists<QuestEventDifficulty, QuestEventDuel>(QuestEventDifficulty.class, CollectionSuppliers.<QuestEventDuel>arrayLists());
|
||||
private final IStorageView<QuestEventDuel> allDuels;
|
||||
private final IStorage<QuestEventDuel> allDuels;
|
||||
|
||||
|
||||
/** Instantiate all events and difficulty lists.
|
||||
* @param dir   File object */
|
||||
public QuestEventDuelManager(final File dir) {
|
||||
allDuels = new StorageView<QuestEventDuel>(new QuestDuelReader(dir));
|
||||
allDuels = new StorageBase<QuestEventDuel>(new QuestDuelReader(dir));
|
||||
assembleDuelDifficultyLists();
|
||||
} // End assembleAllEvents()
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import forge.gui.CardListViewer;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.item.PaperCard;
|
||||
import forge.quest.io.ReadPriceList;
|
||||
import forge.util.storage.IStorageView;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
/**
|
||||
* This is a helper class for unlocking new sets during a format-limited
|
||||
@@ -182,8 +182,8 @@ public class QuestUtilUnlockSets {
|
||||
*/
|
||||
public static void doUnlock(QuestController qData, final CardEdition unlockedSet) {
|
||||
|
||||
IStorageView<SealedProductTemplate> starters = Singletons.getModel().getTournamentPacks();
|
||||
IStorageView<SealedProductTemplate> boosters = Singletons.getModel().getBoosters();
|
||||
IStorage<SealedProductTemplate> starters = Singletons.getModel().getTournamentPacks();
|
||||
IStorage<SealedProductTemplate> boosters = Singletons.getModel().getBoosters();
|
||||
qData.getFormat().unlockSet(unlockedSet.getCode());
|
||||
|
||||
List<PaperCard> cardsWon = new ArrayList<PaperCard>();
|
||||
|
||||
@@ -17,41 +17,28 @@
|
||||
*/
|
||||
package forge.util.storage;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
* @param <T> the generic type
|
||||
*/
|
||||
public interface IStorage<T> extends IStorageView<T> {
|
||||
public interface IStorage<T> extends Iterable<T> {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deck
|
||||
* a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
T get(final String name);
|
||||
|
||||
T find(final Predicate<T> condition);
|
||||
|
||||
Collection<String> getNames();
|
||||
|
||||
boolean contains(final String name);
|
||||
|
||||
int size();
|
||||
|
||||
void add(final T deck);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* deleteDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param deckName
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
void delete(final String deckName);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isUnique.
|
||||
* </p>
|
||||
*
|
||||
* @param name the name
|
||||
* @return a boolean.
|
||||
*/
|
||||
boolean isUnique(final String name);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.util.storage;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
* @param <T> the generic type
|
||||
*/
|
||||
public interface IStorageView<T> extends Iterable<T> {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param name the name
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
T get(final String name);
|
||||
|
||||
T find(final Predicate<T> condition);
|
||||
|
||||
/**
|
||||
* Get names of decks.
|
||||
*
|
||||
* @return a ArrayList<String>
|
||||
*/
|
||||
Collection<String> getNames();
|
||||
|
||||
/**
|
||||
* Contains.
|
||||
*
|
||||
* @param name the name
|
||||
* @return true, if successful
|
||||
*/
|
||||
boolean contains(final String name);
|
||||
|
||||
/**
|
||||
* Gets the count.
|
||||
*
|
||||
* @return the count
|
||||
*/
|
||||
int size();
|
||||
|
||||
}
|
||||
@@ -37,58 +37,34 @@ import forge.util.IItemReader;
|
||||
* @author Forge
|
||||
* @version $Id: DeckManager.java 13590 2012-01-27 20:46:27Z Max mtg $
|
||||
*/
|
||||
public class StorageView<T> implements IStorageView<T> {
|
||||
private final Map<String, T> map;
|
||||
public class StorageBase<T> implements IStorage<T> {
|
||||
protected final Map<String, T> map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for DeckManager.
|
||||
* </p>
|
||||
*
|
||||
* @param io the io
|
||||
*/
|
||||
public StorageView(final IItemReader<T> io) {
|
||||
|
||||
public StorageBase(final IItemReader<T> io) {
|
||||
this.map = io.readAll();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.deck.IFolderMapView#get(java.lang.String)
|
||||
*/
|
||||
public StorageBase(final Map<String, T> inMap) {
|
||||
this.map = inMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(final String name) {
|
||||
return this.map.get(name);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.deck.IFolderMapView#getNames()
|
||||
*/
|
||||
@Override
|
||||
public final Collection<String> getNames() {
|
||||
return new ArrayList<String>(this.map.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map.
|
||||
*
|
||||
* @return the map
|
||||
*/
|
||||
protected final Map<String, T> getMap() {
|
||||
return this.map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return this.map.values().iterator();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.util.IFolderMapView#any(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(String name) {
|
||||
return name == null ? false : this.map.containsKey(name);
|
||||
@@ -103,4 +79,16 @@ public class StorageView<T> implements IStorageView<T> {
|
||||
public T find(Predicate<T> condition) {
|
||||
return Iterables.tryFind(map.values(), condition).orNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(T deck) {
|
||||
throw new UnsupportedOperationException("This is a read-only storage");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String deckName) {
|
||||
throw new UnsupportedOperationException("This is a read-only storage");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import forge.util.IItemSerializer;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class StorageImmediatelySerialized<T> extends StorageView<T> implements IStorage<T> {
|
||||
public class StorageImmediatelySerialized<T> extends StorageBase<T> {
|
||||
|
||||
private final IItemSerializer<T> serializer;
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ public class StorageImmediatelySerialized<T> extends StorageView<T> implements I
|
||||
@Override
|
||||
public final void add(final T deck) {
|
||||
String name = serializer.getItemKey(deck);
|
||||
this.getMap().put(name, deck);
|
||||
this.map.put(name, deck);
|
||||
this.serializer.save(deck);
|
||||
}
|
||||
|
||||
@@ -63,17 +63,6 @@ public class StorageImmediatelySerialized<T> extends StorageView<T> implements I
|
||||
*/
|
||||
@Override
|
||||
public final void delete(final String deckName) {
|
||||
this.serializer.erase(this.getMap().remove(deckName));
|
||||
this.serializer.erase(this.map.remove(deckName));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.deck.IFolderMapView#isUnique(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final boolean isUnique(final String name) {
|
||||
return !this.getMap().containsKey(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user