/*
* SystemCollections.java
* Copyright 2001 (C) Bryan McRoberts <merton_monk@yahoo.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Created 2003-07-12 14:02
*
* Current Ver: $Revision$
*
*/
package pcgen.core;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import pcgen.core.character.EquipSlot;
import pcgen.core.system.MigrationRule;
/**
* Contains lists of stuff loaded from system-wide lst files.
*
* @author Jonas Karlsson <jujutsunerd@users.sourceforge.net>
**/
public final class SystemCollections
{
/** The following are loaded from system files.
* <ul>
* <li>birthplaceList</li>
* <li>bonusStackList</li>
* <li>cityList</li>
* <li>gameModeList</li>
* <li>gameModeDisplayList</li>
* <li>hairStyleList</li>
* <li>helpContextFileList</li>
* <li>interestsList</li>
* <li>locationList</li>
* <li>paperInfoList</li>
* <li>phobiaList</li>
* <li>phraseList</li>
* <li>equipSlotMap</li>
* <li>specialsList</li>
* <li>speechList</li>
* <li>traitList</li>
* <li>paperInfoList</li>
* </ul>
*/
private static final Map<String, List<String>> birthplaceMap = new HashMap<>();
private static final Map<String, List<String>> cityMap = new HashMap<>();
private static final List<GameMode> gameModeList = new ArrayList<>();
private static final List<GameModeDisplay> gameModeDisplayList = new ArrayList<>();
private static final Map<String, List<String>> hairStyleMap = new HashMap<>();
private static final Map<String, List<String>> interestsMap = new HashMap<>();
private static final Map<String, List<String>> locationMap = new HashMap<>();
private static final Map<String, List<String>> phobiaMap = new HashMap<>();
private static final Map<String, Set<String>> phraseMap = new HashMap<>();
private static final Map<String, List<String>> speechMap = new HashMap<>();
private static final Map<String, Set<String>> traitMap = new HashMap<>();
private static final Map<String, List<String>> bodyStructureMap = new HashMap<>();
private static final Map<String, List<EquipSlot>> equipSlotMap = new HashMap<>();
private static final Map<String, List<MigrationRule>> migrationRuleMap = new HashMap<>();
/**
* Make sure it doesn't get instantiated.
*/
private SystemCollections()
{
// Empty Constructor
}
/**
* Return a game mode matching the name.
* @param aString
* @return GameMode
*/
public static GameMode getGameModeNamed(final String aString)
{
for ( GameMode gameMode : gameModeList )
{
if (gameMode.getName().equalsIgnoreCase(aString))
{
return gameMode;
}
}
return null;
}
/**
* Return a game mode matching the display name.
* @param aString
* @return GameMode
*/
public static GameMode getGameModeWithDisplayName(final String aString)
{
for ( GameMode gameMode : gameModeList )
{
if (gameMode.getDisplayName().equalsIgnoreCase(aString))
{
return gameMode;
}
}
return null;
}
/**
* Returns an <b>unmodifiable</b> birtplace list.
* @return an <b>unmodifiable</b> birtplace list.
*/
public static List<String> getUnmodifiableBirthplaceList()
{
List<String> birthplaceList = birthplaceMap.get(SettingsHandler.getGame().getName());
if (birthplaceList == null)
{
birthplaceList = birthplaceMap.get("*");
}
if (birthplaceList == null)
{
birthplaceList = Collections.emptyList();
}
return Collections.unmodifiableList(birthplaceList);
}
/**
* Return an <b>unmodifiable</b> version of the city list.
* @return an <b>unmodifiable</b> version of the city list.
*/
public static List<String> getUnmodifiableCityList()
{
List<String> cityList = cityMap.get(SettingsHandler.getGame().getName());
if (cityList == null)
{
cityList = cityMap.get("*");
}
if (cityList == null)
{
cityList = Collections.emptyList();
}
return Collections.unmodifiableList(cityList);
}
/**
* Return an <b>unmodifiable</b> version of the equipment slots list.
* @return an <b>unmodifiable</b> version of the equipment slots list.
*/
public static List<EquipSlot> getUnmodifiableEquipSlotList()
{
// Try getting an equipslotlist for the currently selected gamemode
List<EquipSlot> equipSlotList = equipSlotMap.get(SettingsHandler.getGame().getName());
if (equipSlotList == null)
{
// if that list doesn't exist, try the default equipslotmap
equipSlotList = equipSlotMap.get("*");
}
if (equipSlotList == null)
{
// if that's also empty, return an empty list
equipSlotList = Collections.emptyList();
}
return Collections.unmodifiableList(equipSlotList);
}
/**
* Return an <b>unmodifiable</b> version of the body structure list for the
* current gamemode.
* @return an <b>unmodifiable</b> version of the body structure list.
*/
public static List<String> getUnmodifiableBodyStructureList()
{
// Try getting a body structure for the currently selected gamemode
List<String> bodyStructures = bodyStructureMap.get(SettingsHandler.getGame().getName());
if (bodyStructures == null)
{
// if that list doesn't exist, try the default body structure list
bodyStructures = bodyStructureMap.get("*");
}
if (bodyStructures == null)
{
// if that's also empty, return an empty list
bodyStructures = Collections.emptyList();
}
return Collections.unmodifiableList(bodyStructures);
}
/**
* Return an <b>unmodifiable</b> version of the migration rules list.
* @return an <b>unmodifiable</b> version of the migration rules list.
*/
public static List<MigrationRule> getUnmodifiableMigrationRuleList(String gameModeName)
{
// Try getting an migrationRuleList for the currently selected gamemode
List<MigrationRule> migrationRuleList = migrationRuleMap.get(gameModeName);
if (migrationRuleList == null)
{
// if that list doesn't exist, try the default migrationRuleList
migrationRuleList = migrationRuleMap.get("*");
}
if (migrationRuleList == null)
{
// if that's also empty, return an empty list
migrationRuleList = Collections.emptyList();
}
return Collections.unmodifiableList(migrationRuleList);
}
/**
* Return an <b>unmodifiable</b> version of the game mode list.
* @return an <b>unmodifiable</b> version of the game mode list.
*/
public static List<GameMode> getUnmodifiableGameModeList()
{
return Collections.unmodifiableList(gameModeList);
}
/**
* Return an <b>unmodifiable</b> version of the game mode display list.
* @return an <b>unmodifiable</b> version of the game mode display list.
*/
public static List<GameModeDisplay> getUnmodifiableGameModeDisplayList()
{
return Collections.unmodifiableList(gameModeDisplayList);
}
/**
* Return an <b>unmodifiable</b> version of the hairstyle list.
* @return an <b>unmodifiable</b> version of the hairstyle list.
*/
public static List<String> getUnmodifiableHairStyleList()
{
List<String> hairStyleList = hairStyleMap.get(SettingsHandler.getGame().getName());
if (hairStyleList == null)
{
hairStyleList = hairStyleMap.get("*");
}
if (hairStyleList == null)
{
hairStyleList = Collections.emptyList();
}
return Collections.unmodifiableList(hairStyleList);
}
/**
* Return an <b>unmodifiable</b> version of the interests list.
* @return an <b>unmodifiable</b> version of the interests list.
*/
public static List<String> getUnmodifiableInterestsList()
{
List<String> interestsList = interestsMap.get(SettingsHandler.getGame().getName());
if (interestsList == null)
{
interestsList = interestsMap.get("*");
}
if (interestsList == null)
{
interestsList = Collections.emptyList();
}
return Collections.unmodifiableList(interestsList);
}
/**
* Return an <b>unmodifiable</b> version of the location list.
* @return an <b>unmodifiable</b> version of the location list.
*/
public static List<String> getUnmodifiableLocationList()
{
List<String> locationList = locationMap.get(SettingsHandler.getGame().getName());
if (locationList == null)
{
locationList = locationMap.get("*");
}
if (locationList == null)
{
locationList = Collections.emptyList();
}
return Collections.unmodifiableList(locationList);
}
/**
* Return an <b>unmodifiable</b> version of the phobia list.
* @return an <b>unmodifiable</b> version of the phobia list.
*/
public static List<String> getUnmodifiablePhobiaList()
{
List<String> phobiaList = phobiaMap.get(SettingsHandler.getGame().getName());
if (phobiaList == null)
{
phobiaList = phobiaMap.get("*");
}
if (phobiaList == null)
{
phobiaList = Collections.emptyList();
}
return Collections.unmodifiableList(phobiaList);
}
/**
* Return an <b>unmodifiable</b> version of the phrase list.
* @return an <b>unmodifiable</b> version of the phrase list.
*/
public static List<String> getUnmodifiablePhraseList()
{
Set<String> phraseSet = phraseMap.get(SettingsHandler.getGame().getName());
if (phraseSet == null)
{
phraseSet = phraseMap.get("*");
}
if (phraseSet == null)
{
return Collections.emptyList();
}
return new ArrayList<>(phraseSet);
}
/**
* Return an <b>unmodifiable</b> version of the speech list.
* @return an <b>unmodifiable</b> version of the speech list.
*/
public static List<String> getUnmodifiableSpeechList()
{
List<String> speechList = speechMap.get(SettingsHandler.getGame().getName());
if (speechList == null)
{
speechList = speechMap.get("*");
}
if (speechList == null)
{
speechList = Collections.emptyList();
}
return Collections.unmodifiableList(speechList);
}
/**
* Return an <b>unmodifiable</b> version of the trait list.
* @return an <b>unmodifiable</b> version of the trait list.
*/
public static List<String> getUnmodifiableTraitList()
{
Set<String> traitList = traitMap.get(SettingsHandler.getGame().getName());
if (traitList == null)
{
traitList = traitMap.get("*");
}
if (traitList == null)
{
return Collections.emptyList();
}
return new ArrayList<>(traitList);
}
//BirthplaceList
/**
* Add a birthplace name to the birthplace list.
* @param birthplace
* @param gameMode
*/
public static void addToBirthplaceList(final String birthplace, final String gameMode)
{
List<String> birthplaceList = birthplaceMap.get(gameMode);
if (birthplaceList == null)
{
birthplaceList = new ArrayList<>();
birthplaceMap.put(gameMode, birthplaceList);
}
if (!birthplaceList.contains(birthplace))
{
birthplaceList.add(birthplace);
}
}
//CITYLIST
/**
* Add to the city list.
* @param city
* @param gameMode
*/
public static void addToCityList(final String city, final String gameMode)
{
List<String> cityList = cityMap.get(gameMode);
if (cityList == null)
{
cityList = new ArrayList<>();
cityMap.put(gameMode, cityList);
}
if (!cityList.contains(city))
{
cityList.add(city);
}
}
//EQUIPSLOTLIST
/**
* Add the equipment slot to the equipment slot list.
* @param equipmentSlot
* @param gameMode = key in the equipSlotMap to which to add the equipmentSlot
*/
public static void addToEquipSlotsList(final EquipSlot equipmentSlot, final String gameMode)
{
List<EquipSlot> equipSlotList = equipSlotMap.get(gameMode);
if (equipSlotList == null)
{
equipSlotList = new ArrayList<>();
equipSlotMap.put(gameMode, equipSlotList);
}
if (!equipSlotList.contains(equipmentSlot))
{
equipSlotList.add(equipmentSlot);
}
}
/**
* Add the body structure to the body structure list.
* @param bodyStructure
* @param gameMode = key in the equipSlotMap to which to add the equipmentSlot
*/
public static void addToBodyStructureList(final String bodyStructure, final String gameMode)
{
List<String> bodyStructureList = bodyStructureMap.get(gameMode);
if (bodyStructureList == null)
{
bodyStructureList = new ArrayList<>();
bodyStructureMap.put(gameMode, bodyStructureList);
}
if (!bodyStructureList.contains(bodyStructure))
{
bodyStructureList.add(bodyStructure);
}
}
/**
* Add the migration rule to the game mode's migration rule list.
* @param migrationRule The migration rule to be added.
* @param gameMode = key in the migrationRuleMap to which to add the migrationRule
*/
public static void addToMigrationRulesList(final MigrationRule migrationRule, final String gameMode)
{
List<MigrationRule> migrationRuleList = migrationRuleMap.get(gameMode);
if (migrationRuleList == null)
{
migrationRuleList = new ArrayList<>();
migrationRuleMap.put(gameMode, migrationRuleList);
}
if (!migrationRuleList.contains(migrationRule))
{
migrationRuleList.add(migrationRule);
}
}
//GAMEMODELIST
/**
* Add the game mode to the list.
* @param mode
*/
public static void addToGameModeList(final GameMode mode)
{
gameModeList.add(mode);
gameModeDisplayList.add(new GameModeDisplay(mode));
}
//HAIRSTYLELIST
/**
* Add the hairstyle to the list.
* @param hairStyle
* @param gameMode
*/
public static void addToHairStyleList(final String hairStyle, final String gameMode)
{
List<String> hairStyleList = hairStyleMap.get(gameMode);
if (hairStyleList == null)
{
hairStyleList = new ArrayList<>();
hairStyleMap.put(gameMode, hairStyleList);
}
if (!hairStyleList.contains(hairStyle))
{
hairStyleList.add(hairStyle);
}
hairStyleList.add(hairStyle);
}
//INTERESTLIST
/**
* Add to the interests list.
* @param interest
* @param gameMode
*/
public static void addToInterestsList(final String interest, final String gameMode)
{
List<String> interestsList = interestsMap.get(gameMode);
if (interestsList == null)
{
interestsList = new ArrayList<>();
interestsMap.put(gameMode, interestsList);
}
if (!interestsList.contains(interest))
{
interestsList.add(interest);
}
}
//LOCATIONLIST
/**
* Add to the location list.
* @param location
* @param gameMode
*/
public static void addToLocationList(final String location, final String gameMode)
{
List<String> locationList = locationMap.get(gameMode);
if (locationList == null)
{
locationList = new ArrayList<>();
locationMap.put(gameMode, locationList);
}
if (!locationList.contains(location))
{
locationList.add(location);
}
}
//PHOBIALIST
/**
* Add the phobia to the phobia list.
* @param phobia
* @param gameMode
*/
public static void addToPhobiaList(final String phobia, final String gameMode)
{
List<String> phobiaList = phobiaMap.get(gameMode);
if (phobiaList == null)
{
phobiaList = new ArrayList<>();
phobiaMap.put(gameMode, phobiaList);
}
if (!phobiaList.contains(phobia))
{
phobiaList.add(phobia);
}
}
//PHRASELIST
/**
* Add the phrase to the phrase list.
* @param phrase
* @param gameMode
*/
public static void addToPhraseList(final String phrase, final String gameMode)
{
Set<String> phraseList = phraseMap.get(gameMode);
if (phraseList == null)
{
phraseList = new HashSet<>();
phraseMap.put(gameMode, phraseList);
}
phraseList.add(phrase);
}
//SPEECHLIST
/**
* Add to the speech list.
* @param speech
* @param gameMode
*/
public static void addToSpeechList(final String speech, final String gameMode)
{
List<String> speechList = speechMap.get(gameMode);
if (speechList == null)
{
speechList = new ArrayList<>();
speechMap.put(gameMode, speechList);
}
if (!speechList.contains(speech))
{
speechList.add(speech);
}
}
//TRAITLIST
/**
* Add the trait to the trait list.
* @param trait
* @param gameMode
*/
public static void addToTraitList(final String trait, final String gameMode)
{
Set<String> traitList = traitMap.get(gameMode);
if (traitList == null)
{
traitList = new HashSet<>();
traitMap.put(gameMode, traitList);
}
traitList.add(trait);
}
/**
* Empty the equipment slots list.
*/
public static void clearEquipSlotsMap()
{
equipSlotMap.clear();
}
/**
* Empty the migration rules list.
*/
public static void clearMigrationRuleMap()
{
migrationRuleMap.clear();
}
/**
* Empty the game mode list.
*/
public static void clearGameModeList()
{
gameModeList.clear();
gameModeDisplayList.clear();
}
/**
* Sort the game mode list.
*/
public static void sortGameModeList()
{
Collections.sort(gameModeList);
Collections.sort(gameModeDisplayList);
}
}