net.sf.freecol.common
Class Specification

java.lang.Object
  extended by net.sf.freecol.common.Specification

public final class Specification
extends java.lang.Object

This class encapsulates any parts of the "specification" for FreeCol that are expressed best using XML. The XML is loaded through the class loader from the resource named "specification.xml" in the same package as this class.


Field Summary
private  java.util.Map<java.lang.String,java.util.List<Ability>> allAbilities
           
private  java.util.Map<java.lang.String,java.util.List<Modifier>> allModifiers
           
private  java.util.Map<java.lang.String,OptionGroup> allOptionGroups
           
private  java.util.Map<java.lang.String,AbstractOption> allOptions
           
private  java.util.Map<java.lang.String,FreeColGameObjectType> allTypes
           
static FreeColGameObjectType AMBUSH_BONUS_SOURCE
           
static FreeColGameObjectType ARTILLERY_PENALTY_SOURCE
           
static FreeColGameObjectType ATTACK_BONUS_SOURCE
           
static FreeColGameObjectType BASE_DEFENCE_SOURCE
           
static FreeColGameObjectType BASE_OFFENCE_SOURCE
           
private  java.util.List<BuildingType> buildingTypeList
           
static FreeColGameObjectType CARGO_PENALTY_SOURCE
           
static FreeColGameObjectType COLONY_GOODS_PARTY
           
private  java.util.List<DifficultyLevel> difficultyLevels
           
private  java.util.List<EquipmentType> equipmentTypes
           
private  java.util.List<Nation> europeanNations
           
private  java.util.List<EuropeanNationType> europeanNationTypes
           
private  java.util.Map<GoodsType,UnitType> experts
           
private  java.util.List<GoodsType> farmedGoodsTypeList
           
private  java.util.List<GoodsType> foodGoodsTypeList
           
static FreeColGameObjectType FORTIFICATION_BONUS_SOURCE
           
private  java.util.List<FoundingFather> foundingFathers
           
private  java.util.List<GoodsType> goodsTypeList
           
private  java.util.List<GoodsType> immigrationGoodsTypeList
           
private  java.util.List<ImprovementActionType> improvementActionTypeList
           
static FreeColGameObjectType IN_CAPITAL
           
static FreeColGameObjectType IN_SETTLEMENT
           
static FreeColGameObjectType INDIAN_RAID_BONUS_SOURCE
           
private  java.util.List<Nation> indianNations
           
private  java.util.List<IndianNationType> indianNationTypes
           
private  boolean initialized
           
private  java.util.List<GoodsType> libertyGoodsTypeList
           
private static java.util.logging.Logger logger
           
static FreeColGameObjectType MOVEMENT_PENALTY_SOURCE
           
private  java.util.List<Nation> nations
           
private  java.util.List<NationType> nationTypes
           
private  java.util.List<GoodsType> newWorldGoodsTypeList
           
private  java.util.List<Nation> REFNations
           
private  java.util.List<EuropeanNationType> REFNationTypes
           
private  java.util.List<ResourceType> resourceTypeList
           
protected static Specification specification
          Singleton
private  int storableTypes
           
private  java.util.List<TileImprovementType> tileImprovementTypeList
           
private  java.util.List<TileType> tileTypeList
           
private  java.util.List<UnitType> unitTypeList
           
private  java.util.List<UnitType> unitTypesPurchasedInEurope
           
private  java.util.List<UnitType> unitTypesTrainedInEurope
           
 
Constructor Summary
protected Specification(java.io.InputStream in)
          Creates a new Specification object by loading it from the specification.xml.
 
Method Summary
 void addAbility(Ability ability)
          Registers an Ability as defined.
 void addAbility(java.lang.String id)
          Registers an Ability's id as defined.
 void addAbstractOption(AbstractOption abstractOption)
          Adds an AbstractOption to the specification
 void addModifier(Modifier modifier)
          Add a modifier.
 void addOptionGroup(OptionGroup optionGroup)
          Adds an OptionGroup to the specification
 void applyDifficultyLevel(int difficultyLevel)
          Applies the difficulty level to the current specification.
static void createSpecification(java.io.InputStream is)
          Loads the specification.
 java.util.List<Ability> getAbilities(java.lang.String id)
          Return a list of all Abilities with the given id.
 BooleanOption getBooleanOption(java.lang.String Id)
          Returns the BooleanOption with the given ID.
 BuildingType getBuildingType(int buildingTypeIndex)
          Describe getBuildingType method here.
 BuildingType getBuildingType(java.lang.String id)
           
 java.util.List<BuildingType> getBuildingTypeList()
           
 DifficultyLevel getDifficultyLevel(int level)
          Describe getDifficultyLevel method here.
 DifficultyLevel getDifficultyLevel(java.lang.String id)
          Describe getDifficultyLevel method here.
 java.util.List<DifficultyLevel> getDifficultyLevels()
           
 EquipmentType getEquipmentType(java.lang.String id)
           
 java.util.List<EquipmentType> getEquipmentTypeList()
           
 java.util.List<Nation> getEuropeanNations()
           
 java.util.List<EuropeanNationType> getEuropeanNationTypes()
           
 UnitType getExpertForProducing(GoodsType goodsType)
           
 java.util.List<GoodsType> getFarmedGoodsTypeList()
           
 FoundingFather getFoundingFather(java.lang.String id)
           
 java.util.List<FoundingFather> getFoundingFathers()
           
 java.util.List<GoodsType> getGoodsFood()
           
 GoodsType getGoodsType(java.lang.String id)
          Describe getGoodsType method here.
 java.util.List<GoodsType> getGoodsTypeList()
           
 java.util.List<GoodsType> getImmigrationGoodsTypeList()
           
 ImprovementActionType getImprovementActionType(java.lang.String id)
           
 java.util.List<ImprovementActionType> getImprovementActionTypeList()
           
 java.util.List<Nation> getIndianNations()
           
 java.util.List<IndianNationType> getIndianNationTypes()
           
 IntegerOption getIntegerOption(java.lang.String Id)
          Returns the IntegerOption with the given ID.
 java.util.List<GoodsType> getLibertyGoodsTypeList()
           
 java.util.List<Modifier> getModifiers(java.lang.String id)
          Return a list of all Modifiers with the given id.
 Nation getNation(java.lang.String id)
           
 java.util.List<Nation> getNations()
           
 NationType getNationType(java.lang.String id)
           
 java.util.List<NationType> getNationTypes()
           
 java.util.List<GoodsType> getNewWorldGoodsTypeList()
           
 AbstractOption getOption(java.lang.String Id)
          Returns the AbstractOption with the given ID.
 OptionGroup getOptionGroup(java.lang.String Id)
          Returns the OptionGroup with the given ID.
 RangeOption getRangeOption(java.lang.String Id)
          Returns the RangeOption with the given ID.
 java.util.List<Nation> getREFNations()
           
 java.util.List<EuropeanNationType> getREFNationTypes()
           
 ResourceType getResourceType(java.lang.String id)
           
 java.util.List<ResourceType> getResourceTypeList()
           
static Specification getSpecification()
           
 StringOption getStringOption(java.lang.String Id)
          Returns the StringOption with the given ID.
 TileImprovementType getTileImprovementType(java.lang.String id)
           
 java.util.List<TileImprovementType> getTileImprovementTypeList()
           
 TileType getTileType(java.lang.String id)
           
 java.util.List<TileType> getTileTypeList()
           
 FreeColGameObjectType getType(java.lang.String Id)
           
<T extends FreeColGameObjectType>
T
getType(java.lang.String Id, java.lang.Class<T> type)
          Returns the FreeColGameObjectType with the given ID.
<T extends FreeColGameObjectType>
T
getType(javax.xml.stream.XMLStreamReader in, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue)
          Returns the FreeColGameObjectType identified by the attributeName, or the default value if there is no such attribute.
 java.util.List<FreeColGameObjectType> getTypesProviding(java.lang.String id, boolean value)
          Return a list of FreeColGameObjectTypes that provide the required ability.
<T extends FreeColGameObjectType>
java.util.List<T>
getTypesWithAbility(java.lang.Class<T> resultType, java.lang.String... abilities)
          Return all types which have any of the given abilities.
 UnitType getUnitType(java.lang.String id)
           
 java.util.List<UnitType> getUnitTypeList()
           
 java.util.List<UnitType> getUnitTypesPurchasedInEurope()
          Returns the unit types that can be purchased in Europe.
 java.util.List<UnitType> getUnitTypesTrainedInEurope()
          Returns the unit types that can be trained in Europe.
 java.util.List<UnitType> getUnitTypesWithAbility(java.lang.String... abilities)
          Return the unit types which have any of the given abilities
 boolean hasOption(java.lang.String Id)
          Is option with this ID present? This is helpful when options are optionally(!) present, for example model.option.priceIncrease.artillery exists but model.option.priceIncrease.frigate does not.
private  java.lang.String mangle(java.lang.String id)
           
 int numberOfBuildingTypes()
          Describe numberOfBuildingTypes method here.
 int numberOfFarmedGoodsTypes()
          Describe numberOfFarmedGoodsTypes method here.
 int numberOfFoundingFathers()
           
 int numberOfGoodsTypes()
          Describe numberOfGoodsTypes method here.
 int numberOfNationTypes()
           
 int numberOfResourceTypes()
           
 int numberOfStoredGoodsTypes()
           
 int numberOfTileTypes()
           
 int numberOfUnitTypes()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MOVEMENT_PENALTY_SOURCE

public static final FreeColGameObjectType MOVEMENT_PENALTY_SOURCE

ARTILLERY_PENALTY_SOURCE

public static final FreeColGameObjectType ARTILLERY_PENALTY_SOURCE

ATTACK_BONUS_SOURCE

public static final FreeColGameObjectType ATTACK_BONUS_SOURCE

FORTIFICATION_BONUS_SOURCE

public static final FreeColGameObjectType FORTIFICATION_BONUS_SOURCE

INDIAN_RAID_BONUS_SOURCE

public static final FreeColGameObjectType INDIAN_RAID_BONUS_SOURCE

BASE_OFFENCE_SOURCE

public static final FreeColGameObjectType BASE_OFFENCE_SOURCE

BASE_DEFENCE_SOURCE

public static final FreeColGameObjectType BASE_DEFENCE_SOURCE

CARGO_PENALTY_SOURCE

public static final FreeColGameObjectType CARGO_PENALTY_SOURCE

AMBUSH_BONUS_SOURCE

public static final FreeColGameObjectType AMBUSH_BONUS_SOURCE

IN_SETTLEMENT

public static final FreeColGameObjectType IN_SETTLEMENT

IN_CAPITAL

public static final FreeColGameObjectType IN_CAPITAL

COLONY_GOODS_PARTY

public static final FreeColGameObjectType COLONY_GOODS_PARTY

specification

protected static Specification specification
Singleton


logger

private static final java.util.logging.Logger logger

allTypes

private final java.util.Map<java.lang.String,FreeColGameObjectType> allTypes

allOptions

private final java.util.Map<java.lang.String,AbstractOption> allOptions

allOptionGroups

private final java.util.Map<java.lang.String,OptionGroup> allOptionGroups

experts

private final java.util.Map<GoodsType,UnitType> experts

allAbilities

private final java.util.Map<java.lang.String,java.util.List<Ability>> allAbilities

allModifiers

private final java.util.Map<java.lang.String,java.util.List<Modifier>> allModifiers

buildingTypeList

private final java.util.List<BuildingType> buildingTypeList

goodsTypeList

private final java.util.List<GoodsType> goodsTypeList

farmedGoodsTypeList

private final java.util.List<GoodsType> farmedGoodsTypeList

foodGoodsTypeList

private final java.util.List<GoodsType> foodGoodsTypeList

newWorldGoodsTypeList

private final java.util.List<GoodsType> newWorldGoodsTypeList

libertyGoodsTypeList

private final java.util.List<GoodsType> libertyGoodsTypeList

immigrationGoodsTypeList

private final java.util.List<GoodsType> immigrationGoodsTypeList

resourceTypeList

private final java.util.List<ResourceType> resourceTypeList

tileTypeList

private final java.util.List<TileType> tileTypeList

tileImprovementTypeList

private final java.util.List<TileImprovementType> tileImprovementTypeList

improvementActionTypeList

private final java.util.List<ImprovementActionType> improvementActionTypeList

unitTypeList

private final java.util.List<UnitType> unitTypeList

unitTypesTrainedInEurope

private final java.util.List<UnitType> unitTypesTrainedInEurope

unitTypesPurchasedInEurope

private final java.util.List<UnitType> unitTypesPurchasedInEurope

foundingFathers

private final java.util.List<FoundingFather> foundingFathers

nations

private final java.util.List<Nation> nations

europeanNations

private final java.util.List<Nation> europeanNations

REFNations

private final java.util.List<Nation> REFNations

indianNations

private final java.util.List<Nation> indianNations

nationTypes

private final java.util.List<NationType> nationTypes

europeanNationTypes

private final java.util.List<EuropeanNationType> europeanNationTypes

REFNationTypes

private final java.util.List<EuropeanNationType> REFNationTypes

indianNationTypes

private final java.util.List<IndianNationType> indianNationTypes

equipmentTypes

private final java.util.List<EquipmentType> equipmentTypes

difficultyLevels

private final java.util.List<DifficultyLevel> difficultyLevels

storableTypes

private int storableTypes

initialized

private boolean initialized
Constructor Detail

Specification

protected Specification(java.io.InputStream in)
Creates a new Specification object by loading it from the specification.xml. This method is protected, since only one Specification object may exist. This is due to static links from type Goods to the most important GoodsTypes. If another specification object is created these links would not work anymore for the previously created specification. To get hold of an Specification object use the static method getSpecification() which returns a singleton instance of the Specification class.

Method Detail

addAbility

public void addAbility(Ability ability)
Registers an Ability as defined.

Parameters:
ability - an Ability value

addAbility

public void addAbility(java.lang.String id)
Registers an Ability's id as defined. This is useful for abilities that are required rather than provided by FreeColGameObjectTypes.

Parameters:
id - a String value

getAbilities

public java.util.List<Ability> getAbilities(java.lang.String id)
Return a list of all Abilities with the given id.

Parameters:
id - the ability id

getTypesProviding

public java.util.List<FreeColGameObjectType> getTypesProviding(java.lang.String id,
                                                               boolean value)
Return a list of FreeColGameObjectTypes that provide the required ability.

Parameters:
id - the ability id
value - the ability value
Returns:
a list of FreeColGameObjectTypes that provide the required ability.

addModifier

public void addModifier(Modifier modifier)
Add a modifier.

Parameters:
modifier - a Modifier value

getModifiers

public java.util.List<Modifier> getModifiers(java.lang.String id)
Return a list of all Modifiers with the given id.

Parameters:
id - the modifier id

getType

public <T extends FreeColGameObjectType> T getType(java.lang.String Id,
                                                   java.lang.Class<T> type)
                                        throws java.lang.IllegalArgumentException
Returns the FreeColGameObjectType with the given ID. Throws an IllegalArgumentException if the ID is null. Throws and IllegalArgumentException if no such Type can be retrieved and initialization is complete.

Parameters:
Id - a String value
type - a Class value
Returns:
a FreeColGameObjectType value
Throws:
java.lang.IllegalArgumentException - if an error occurs

mangle

private java.lang.String mangle(java.lang.String id)

getType

public FreeColGameObjectType getType(java.lang.String Id)
                              throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

getTypesWithAbility

public <T extends FreeColGameObjectType> java.util.List<T> getTypesWithAbility(java.lang.Class<T> resultType,
                                                                               java.lang.String... abilities)
Return all types which have any of the given abilities.

Parameters:
abilities - The abilities for the search
Returns:
a List of UnitType

hasOption

public boolean hasOption(java.lang.String Id)
Is option with this ID present? This is helpful when options are optionally(!) present, for example model.option.priceIncrease.artillery exists but model.option.priceIncrease.frigate does not.

Parameters:
Id - a String value
Returns:
True/false on presence of option Id

getOption

public AbstractOption getOption(java.lang.String Id)
                         throws java.lang.IllegalArgumentException
Returns the AbstractOption with the given ID. Throws an IllegalArgumentException if the ID is null or unknown.

Parameters:
Id - a String value
Returns:
an AbstractOption value
Throws:
java.lang.IllegalArgumentException

getOptionGroup

public OptionGroup getOptionGroup(java.lang.String Id)
                           throws java.lang.IllegalArgumentException
Returns the OptionGroup with the given ID. Throws an IllegalArgumentException if the ID is null or unknown.

Parameters:
Id - a String value
Returns:
an OptionGroup value
Throws:
java.lang.IllegalArgumentException

addOptionGroup

public void addOptionGroup(OptionGroup optionGroup)
Adds an OptionGroup to the specification

Parameters:
optionGroup - OptionGroup to add

addAbstractOption

public void addAbstractOption(AbstractOption abstractOption)
Adds an AbstractOption to the specification

Parameters:
abstractOption - AbstractOption to add

getIntegerOption

public IntegerOption getIntegerOption(java.lang.String Id)
Returns the IntegerOption with the given ID. Throws an IllegalArgumentException if the ID is null, or if no such Type can be retrieved.

Parameters:
Id - a String value
Returns:
an IntegerOption value

getRangeOption

public RangeOption getRangeOption(java.lang.String Id)
Returns the RangeOption with the given ID. Throws an IllegalArgumentException if the ID is null, or if no such Type can be retrieved.

Parameters:
Id - a String value
Returns:
an RangeOption value

getBooleanOption

public BooleanOption getBooleanOption(java.lang.String Id)
Returns the BooleanOption with the given ID. Throws an IllegalArgumentException if the ID is null, or if no such Type can be retrieved.

Parameters:
Id - a String value
Returns:
an BooleanOption value

getStringOption

public StringOption getStringOption(java.lang.String Id)
Returns the StringOption with the given ID. Throws an IllegalArgumentException if the ID is null, or if no such Type can be retrieved.

Parameters:
Id - a String value
Returns:
an StringOption value

getBuildingTypeList

public java.util.List<BuildingType> getBuildingTypeList()

numberOfBuildingTypes

public int numberOfBuildingTypes()
Describe numberOfBuildingTypes method here.

Returns:
an int value

getBuildingType

public BuildingType getBuildingType(int buildingTypeIndex)
Describe getBuildingType method here.

Parameters:
buildingTypeIndex - an int value
Returns:
a BuildingType value

getBuildingType

public BuildingType getBuildingType(java.lang.String id)

getGoodsTypeList

public java.util.List<GoodsType> getGoodsTypeList()

numberOfGoodsTypes

public int numberOfGoodsTypes()
Describe numberOfGoodsTypes method here.

Returns:
an int value

numberOfStoredGoodsTypes

public int numberOfStoredGoodsTypes()

getFarmedGoodsTypeList

public java.util.List<GoodsType> getFarmedGoodsTypeList()

getNewWorldGoodsTypeList

public java.util.List<GoodsType> getNewWorldGoodsTypeList()

getLibertyGoodsTypeList

public java.util.List<GoodsType> getLibertyGoodsTypeList()

getImmigrationGoodsTypeList

public java.util.List<GoodsType> getImmigrationGoodsTypeList()

numberOfFarmedGoodsTypes

public int numberOfFarmedGoodsTypes()
Describe numberOfFarmedGoodsTypes method here.

Returns:
an int value

getGoodsType

public GoodsType getGoodsType(java.lang.String id)
Describe getGoodsType method here.

Parameters:
id - a String value
Returns:
a GoodsType value

getGoodsFood

public java.util.List<GoodsType> getGoodsFood()

getResourceTypeList

public java.util.List<ResourceType> getResourceTypeList()

numberOfResourceTypes

public int numberOfResourceTypes()

getResourceType

public ResourceType getResourceType(java.lang.String id)

getTileTypeList

public java.util.List<TileType> getTileTypeList()

numberOfTileTypes

public int numberOfTileTypes()

getTileType

public TileType getTileType(java.lang.String id)

getTileImprovementTypeList

public java.util.List<TileImprovementType> getTileImprovementTypeList()

getTileImprovementType

public TileImprovementType getTileImprovementType(java.lang.String id)

getImprovementActionTypeList

public java.util.List<ImprovementActionType> getImprovementActionTypeList()

getImprovementActionType

public ImprovementActionType getImprovementActionType(java.lang.String id)

getUnitTypeList

public java.util.List<UnitType> getUnitTypeList()

numberOfUnitTypes

public int numberOfUnitTypes()

getUnitType

public UnitType getUnitType(java.lang.String id)

getExpertForProducing

public UnitType getExpertForProducing(GoodsType goodsType)

getUnitTypesWithAbility

public java.util.List<UnitType> getUnitTypesWithAbility(java.lang.String... abilities)
Return the unit types which have any of the given abilities

Parameters:
abilities - The abilities for the search
Returns:
a List of UnitType

getUnitTypesTrainedInEurope

public java.util.List<UnitType> getUnitTypesTrainedInEurope()
Returns the unit types that can be trained in Europe.


getUnitTypesPurchasedInEurope

public java.util.List<UnitType> getUnitTypesPurchasedInEurope()
Returns the unit types that can be purchased in Europe.


getFoundingFathers

public java.util.List<FoundingFather> getFoundingFathers()

numberOfFoundingFathers

public int numberOfFoundingFathers()

getFoundingFather

public FoundingFather getFoundingFather(java.lang.String id)

getNationTypes

public java.util.List<NationType> getNationTypes()

getEuropeanNationTypes

public java.util.List<EuropeanNationType> getEuropeanNationTypes()

getREFNationTypes

public java.util.List<EuropeanNationType> getREFNationTypes()

getIndianNationTypes

public java.util.List<IndianNationType> getIndianNationTypes()

numberOfNationTypes

public int numberOfNationTypes()

getNationType

public NationType getNationType(java.lang.String id)

getNations

public java.util.List<Nation> getNations()

getNation

public Nation getNation(java.lang.String id)

getEuropeanNations

public java.util.List<Nation> getEuropeanNations()

getIndianNations

public java.util.List<Nation> getIndianNations()

getREFNations

public java.util.List<Nation> getREFNations()

getEquipmentTypeList

public java.util.List<EquipmentType> getEquipmentTypeList()

getEquipmentType

public EquipmentType getEquipmentType(java.lang.String id)

getDifficultyLevels

public java.util.List<DifficultyLevel> getDifficultyLevels()

getDifficultyLevel

public DifficultyLevel getDifficultyLevel(java.lang.String id)
Describe getDifficultyLevel method here.

Parameters:
id - a String value
Returns:
a DifficultyLevel value

getDifficultyLevel

public DifficultyLevel getDifficultyLevel(int level)
Describe getDifficultyLevel method here.

Parameters:
level - an int value
Returns:
a DifficultyLevel value

applyDifficultyLevel

public void applyDifficultyLevel(int difficultyLevel)
Applies the difficulty level to the current specification.

Parameters:
difficultyLevel - difficulty level to apply

createSpecification

public static void createSpecification(java.io.InputStream is)
Loads the specification.

Parameters:
is - The stream to load the specification from.

getSpecification

public static Specification getSpecification()

getType

public <T extends FreeColGameObjectType> T getType(javax.xml.stream.XMLStreamReader in,
                                                   java.lang.String attributeName,
                                                   java.lang.Class<T> returnClass,
                                                   T defaultValue)
Returns the FreeColGameObjectType identified by the attributeName, or the default value if there is no such attribute.

Parameters:
in - the XMLStreamReader
attributeName - the name of the attribute identifying the FreeColGameObjectType
returnClass - the class of the return value
defaultValue - the value to return if there is no attribute named attributeName
Returns:
a FreeColGameObjectType value