Specification.java

Index Score
net.sf.freecol.common
FreeCol

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0259JAVA0259 Return of collection/array field
FUNCTIONSNumber of function declarations
BLOCKSNumber of blocks
SIZESize of the file in bytes
RETURNSNumber of return points from functions
DECL_COMMENTSComments in declarations
LOOPSNumber of loops
CYCLOMATICCyclomatic complexity
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
EXITSProcedure exits
LOGICAL_LINESNumber of statements
UNIQUE_OPERANDSNumber of unique operands
INTERFACE_COMPLEXITYInterface complexity
ELOCEffective lines of code
LINESNumber of lines in the source file
PROGRAM_VOCABHalstead program vocabulary
LOCLines of code
DOC_COMMENTNumber of javadoc comment lines
COMPARISONSNumber of comparison operators
JAVA0034JAVA0034 Missing braces in if statement
JAVA0126JAVA0126 Method declares unchecked exception in throws
COMMENTSComment lines
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
WHITESPACENumber of whitespace lines
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
LINE_COMMENTNumber of line comments
JAVA0080JAVA0080 Import declaration not used
PARAMSNumber of formal parameter declarations
NEST_DEPTHMaximum nesting depth
JAVA0009JAVA0009 Protected member in final class
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0265JAVA0265 Use of Throwable.printStackTrace()
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
UNIQUE_OPERATORSNumber of unique operators
EXEC_COMMENTSComments in executable code
JAVA0145JAVA0145 Tab character used in source file
/** * Copyright (C) 2002-2007 The FreeCol Team * * This file is part of FreeCol. * * FreeCol 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 2 of the License, or * (at your option) any later version. * * FreeCol 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 FreeCol. If not, see <http://www.gnu.org/licenses/>. */ package net.sf.freecol.common; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Logger; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import net.sf.freecol.client.gui.action.ImprovementActionType; import net.sf.freecol.common.model.Ability; import net.sf.freecol.common.model.BuildingType; import net.sf.freecol.common.model.DifficultyLevel; import net.sf.freecol.common.model.EquipmentType; import net.sf.freecol.common.model.EuropeanNationType; import net.sf.freecol.common.model.FoundingFather; import net.sf.freecol.common.model.FreeColGameObjectType; import net.sf.freecol.common.model.Goods; import net.sf.freecol.common.model.GoodsType; import net.sf.freecol.common.model.IndianNationType; import net.sf.freecol.common.model.Modifier; import net.sf.freecol.common.model.Nation; import net.sf.freecol.common.model.NationType; import net.sf.freecol.common.model.ResourceType; import net.sf.freecol.common.model.Tile; import net.sf.freecol.common.model.TileImprovementType; import net.sf.freecol.common.model.TileType; import net.sf.freecol.common.model.UnitType; import net.sf.freecol.common.option.AbstractOption; import net.sf.freecol.common.option.FileOption; import net.sf.freecol.common.option.IntegerOption; import net.sf.freecol.common.option.BooleanOption; import net.sf.freecol.common.option.LanguageOption; import net.sf.freecol.common.option.Option; import net.sf.freecol.common.option.OptionGroup; import net.sf.freecol.common.option.RangeOption; import net.sf.freecol.common.option.SelectOption; /** * 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. */ public final class Specification { /** * Singleton */ protected static Specification specification; private static final Logger logger = Logger.getLogger(Specification.class.getName()); private final Map<String, FreeColGameObjectType> allTypes; private final Map<String, AbstractOption> allOptions; private final Map<String, OptionGroup> allOptionGroups; private final Map<GoodsType, UnitType> experts; private final Map<String, List<Ability>> allAbilities; private final Map<String, List<Modifier>> allModifiers; private final List<BuildingType> buildingTypeList; private final List<GoodsType> goodsTypeList; private final List<GoodsType> farmedGoodsTypeList; private final List<GoodsType> foodGoodsTypeList; private final List<GoodsType> newWorldGoodsTypeList; private final List<ResourceType> resourceTypeList; private final List<TileType> tileTypeList; private final List<TileImprovementType> tileImprovementTypeList; private final List<ImprovementActionType> improvementActionTypeList; private final List<UnitType> unitTypeList; private final List<UnitType> unitTypesTrainedInEurope; private final List<UnitType> unitTypesPurchasedInEurope; private final List<FoundingFather> foundingFathers; private final List<Nation> nations; private final List<Nation> europeanNations; private final List<Nation> REFNations; private final List<Nation> classicNations; private final List<Nation> indianNations; private final List<NationType> nationTypes; private final List<EuropeanNationType> europeanNationTypes; private final List<EuropeanNationType> REFNationTypes; private final List<EuropeanNationType> classicNationTypes; private final List<IndianNationType> indianNationTypes; private final List<EquipmentType> equipmentTypes; private final List<DifficultyLevel> difficultyLevels; private int storableTypes = 0; /** * 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 {@link 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 * {@link #getSpecification()} which returns a singleton instance of the * Specification class. */ protected Specification(InputStream in) { logger.info("Initializing Specification"); allTypes = new HashMap<String, FreeColGameObjectType>(); allOptions = new HashMap<String, AbstractOption>(); allOptionGroups = new HashMap<String, OptionGroup>(); experts = new HashMap<GoodsType, UnitType>(); allAbilities = new HashMap<String, List<Ability>>(); allModifiers = new HashMap<String, List<Modifier>>(); buildingTypeList = new ArrayList<BuildingType>(); goodsTypeList = new ArrayList<GoodsType>(); foodGoodsTypeList = new ArrayList<GoodsType>(); farmedGoodsTypeList = new ArrayList<GoodsType>(); newWorldGoodsTypeList = new ArrayList<GoodsType>(); resourceTypeList = new ArrayList<ResourceType>(); tileTypeList = new ArrayList<TileType>(); tileImprovementTypeList = new ArrayList<TileImprovementType>(); improvementActionTypeList = new ArrayList<ImprovementActionType>(); unitTypeList = new ArrayList<UnitType>(); unitTypesPurchasedInEurope = new ArrayList<UnitType>(); unitTypesTrainedInEurope = new ArrayList<UnitType>(); foundingFathers = new ArrayList<FoundingFather>(); nations = new ArrayList<Nation>(); europeanNations = new ArrayList<Nation>(); REFNations = new ArrayList<Nation>(); classicNations = new ArrayList<Nation>(); indianNations = new ArrayList<Nation>(); nationTypes = new ArrayList<NationType>(); europeanNationTypes = new ArrayList<EuropeanNationType>(); REFNationTypes = new ArrayList<EuropeanNationType>(); classicNationTypes = new ArrayList<EuropeanNationType>(); indianNationTypes = new ArrayList<IndianNationType>(); equipmentTypes = new ArrayList<EquipmentType>(); difficultyLevels = new ArrayList<DifficultyLevel>(); try { XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(in); xsr.nextTag(); while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { String childName = xsr.getLocalName(); logger.finest("Found child named " + childName); if ("goods-types".equals(childName)) { int goodsIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { GoodsType goodsType = new GoodsType(goodsIndex++); goodsType.readFromXML(xsr, this); goodsTypeList.add(goodsType); allTypes.put(goodsType.getId(), goodsType); if (goodsType.isFarmed()) { farmedGoodsTypeList.add(goodsType); } if (goodsType.isFoodType()) { foodGoodsTypeList.add(goodsType); } if (goodsType.isNewWorldGoodsType()) { newWorldGoodsTypeList.add(goodsType); } if (goodsType.isStorable()) { storableTypes++; } } } else if ("building-types".equals(childName)) { int buildingIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { BuildingType buildingType = new BuildingType(buildingIndex++); buildingType.readFromXML(xsr, this); allTypes.put(buildingType.getId(), buildingType); buildingTypeList.add(buildingType); } } else if ("resource-types".equals(childName)) { int resIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { ResourceType resourceType = new ResourceType(resIndex++); resourceType.readFromXML(xsr, this); allTypes.put(resourceType.getId(), resourceType); resourceTypeList.add(resourceType); } } else if ("tile-types".equals(childName)) { int tileIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { TileType tileType = new TileType(tileIndex++); tileType.readFromXML(xsr, this); allTypes.put(tileType.getId(), tileType); tileTypeList.add(tileType); } } else if ("tileimprovement-types".equals(childName)) { int impIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { TileImprovementType tileImprovementType = new TileImprovementType(impIndex++); tileImprovementType.readFromXML(xsr, this); allTypes.put(tileImprovementType.getId(), tileImprovementType); tileImprovementTypeList.add(tileImprovementType); } } else if ("improvementaction-types".equals(childName)) { while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { ImprovementActionType impActionType = new ImprovementActionType(); impActionType.readFromXML(xsr, this); allTypes.put(impActionType.getId(), impActionType); improvementActionTypeList.add(impActionType); } } else if ("unit-types".equals(childName)) { int unitIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { UnitType unitType = new UnitType(unitIndex++); unitType.readFromXML(xsr, this); allTypes.put(unitType.getId(), unitType); unitTypeList.add(unitType); if (unitType.getExpertProduction() != null) { experts.put(unitType.getExpertProduction(), unitType); } if (unitType.hasPrice()) { if (unitType.getSkill() > 0) { unitTypesTrainedInEurope.add(unitType); } else if (!unitType.hasSkill()) { unitTypesPurchasedInEurope.add(unitType); } } } } else if ("founding-fathers".equals(childName)) { int fatherIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { FoundingFather foundingFather = new FoundingFather(fatherIndex++); foundingFather.readFromXML(xsr, this); allTypes.put(foundingFather.getId(), foundingFather); foundingFathers.add(foundingFather); } } else if ("nation-types".equals(childName)) { int nationIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { NationType nationType; if ("european-nation-type".equals(xsr.getLocalName())) { nationType = new EuropeanNationType(nationIndex++); nationType.readFromXML(xsr, this); if (nationType.isREF()) { REFNationTypes.add((EuropeanNationType) nationType); } else { europeanNationTypes.add((EuropeanNationType) nationType); } } else { nationType = new IndianNationType(nationIndex++); nationType.readFromXML(xsr, this); indianNationTypes.add((IndianNationType) nationType); } allTypes.put(nationType.getId(), nationType); nationTypes.add(nationType); } } else if ("nations".equals(childName)) { int nationIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { Nation nation = new Nation(nationIndex++); nation.readFromXML(xsr, this); allTypes.put(nation.getId(), nation); nations.add(nation); if (nation.getType().isEuropean()) { if (nation.getType().isREF()) { REFNations.add(nation); } else { europeanNations.add(nation); } if (nation.isClassic()) { classicNations.add(nation); classicNationTypes.add((EuropeanNationType) nation.getType()); } } else { indianNations.add(nation); } } } else if ("equipment-types".equals(childName)) { int equipmentIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { EquipmentType equipmentType = new EquipmentType(equipmentIndex++); equipmentType.readFromXML(xsr, this); allTypes.put(equipmentType.getId(), equipmentType); equipmentTypes.add(equipmentType); } } else if ("difficultyLevels".equals(childName)) { int levelIndex = 0; while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { DifficultyLevel level = new DifficultyLevel(levelIndex++); level.readFromXML(xsr, this); allTypes.put(level.getId(), level); difficultyLevels.add(level); } } else if ("options".equals(childName)) { while (xsr.nextTag() != XMLStreamConstants.END_ELEMENT) { AbstractOption option = (AbstractOption) null; String optionType = xsr.getLocalName(); if (OptionGroup.getXMLElementTagName().equals(optionType)) { option = new OptionGroup(xsr); } else if (IntegerOption.getXMLElementTagName().equals(optionType) || "integer-option".equals(optionType)) { option = new IntegerOption(xsr); } else if (BooleanOption.getXMLElementTagName().equals(optionType) || "boolean-option".equals(optionType)) { option = new BooleanOption(xsr); } else if (RangeOption.getXMLElementTagName().equals(optionType) || "range-option".equals(optionType)) { option = new RangeOption(xsr); } else if (SelectOption.getXMLElementTagName().equals(optionType) || "select-option".equals(optionType)) { option = new SelectOption(xsr); } else if (LanguageOption.getXMLElementTagName().equals(optionType) || "language-option".equals(optionType)) { option = new LanguageOption(xsr); } else { logger.finest("Parsing of " + optionType + " is not implemented yet"); xsr.nextTag(); } // If the option is valid, add it to Specification options if (option != (AbstractOption) null) { if(option instanceof OptionGroup) { this.addOptionGroup((OptionGroup) option); } else { this.addAbstractOption((AbstractOption) option); } } } } else { throw new RuntimeException("unexpected: " + childName); } } // Post specification actions // Get Food, Bells, Crosses and Hammers Goods.initialize(getGoodsTypeList(), numberOfGoodsTypes()); logger.info("Specification initialization complete"); } catch (XMLStreamException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); logger.warning(sw.toString()); throw new RuntimeException("Error parsing specification"); } } // ---------------------------------------------------------- retrieval // methods public void addAbility(Ability ability) { String id = ability.getId(); if (!allAbilities.containsKey(id)) { allAbilities.put(id, new ArrayList<Ability>()); } allAbilities.get(id).add(ability); } /** * Return a list of all Abilities with the given id. * * @param id the ability id */ public List<Ability> getAbilities(String id) { return allAbilities.get(id); } public void addModifier(Modifier modifier) { String id = modifier.getId(); if (!allModifiers.containsKey(id)) { allModifiers.put(id, new ArrayList<Modifier>()); } allModifiers.get(id).add(modifier); } /** * Return a list of all Modifiers with the given id. * * @param id the modifier id */ public List<Modifier> getModifiers(String id) { return allModifiers.get(id); } /** * Returns the <code>FreeColGameObjectType</code> with the given ID. * Throws an IllegalArgumentException if the ID is null, or if no such Type * can be retrieved. * * @param Id a <code>String</code> value * @return a <code>FreeColGameObjectType</code> value */ public FreeColGameObjectType getType(String Id) throws IllegalArgumentException { if (Id == null) { throw new IllegalArgumentException("Trying to retrieve FreeColGameObjectType" + " with ID 'null'."); } else if (!allTypes.containsKey(Id)) { throw new IllegalArgumentException("Trying to retrieve FreeColGameObjectType" + " with ID '" + Id + "' returned 'null'."); } else { return allTypes.get(Id); } } /** * Returns the <code>AbstractOption</code> with the given ID. Throws an * IllegalArgumentException if the ID is null or unknown. * * @param Id a <code>String</code> value * @return an <code>AbstractOption</code> value */ public AbstractOption getOption(String Id) throws IllegalArgumentException { if (Id == null) { throw new IllegalArgumentException("Trying to retrieve AbstractOption" + " with ID 'null'."); } else if (!allOptions.containsKey(Id)) { throw new IllegalArgumentException("Trying to retrieve AbstractOption" + " with ID '" + Id + "' returned 'null'."); } else { return allOptions.get(Id); } } /** * Returns the <code>OptionGroup</code> with the given ID. Throws an * IllegalArgumentException if the ID is null or unknown. * * @param Id a <code>String</code> value * @return an <code>OptionGroup</code> value */ public OptionGroup getOptionGroup(String Id) throws IllegalArgumentException { if (Id == null) { throw new IllegalArgumentException("Trying to retrieve OptionGroup" + " with ID 'null'."); } else if (!allOptionGroups.containsKey(Id)) { throw new IllegalArgumentException("Trying to retrieve OptionGroup" + " with ID '" + Id + "' returned 'null'."); } else { return allOptionGroups.get(Id); } } /** * Adds an <code>OptionGroup</code> to the specification * * @param optionGroup <code>OptionGroup</code> to add */ public void addOptionGroup(OptionGroup optionGroup) { // Add the option group allOptionGroups.put(optionGroup.getId(), optionGroup); // Add the options of the group Iterator<Option> iter = optionGroup.iterator(); while(iter.hasNext()){ Option option = iter.next(); addAbstractOption((AbstractOption) option); } } /** * Adds an <code>AbstractOption</code> to the specification * * @param abstractOption <code>AbstractOption</code> to add */ public void addAbstractOption(AbstractOption abstractOption) { // Add the option allOptions.put(abstractOption.getId(), abstractOption); } /** * Returns the <code>IntegerOption</code> with the given ID. Throws an * IllegalArgumentException if the ID is null, or if no such Type can be * retrieved. * * @param Id a <code>String</code> value * @return an <code>IntegerOption</code> value */ public IntegerOption getIntegerOption(String Id) { return (IntegerOption) getOption(Id); } /** * Returns the <code>RangeOption</code> with the given ID. Throws an * IllegalArgumentException if the ID is null, or if no such Type can be * retrieved. * * @param Id a <code>String</code> value * @return an <code>RangeOption</code> value */ public RangeOption getRangeOption(String Id) { return (RangeOption) getOption(Id); } /** * Returns the <code>BooleanOption</code> with the given ID. Throws an * IllegalArgumentException if the ID is null, or if no such Type can be * retrieved. * * @param Id a <code>String</code> value * @return an <code>BooleanOption</code> value */ public BooleanOption getBooleanOption(String Id) { return (BooleanOption) getOption(Id); } // -- Buildings -- public List<BuildingType> getBuildingTypeList() { return buildingTypeList; } /** * Describe <code>numberOfBuildingTypes</code> method here. * * @return an <code>int</code> value */ public int numberOfBuildingTypes() { return buildingTypeList.size(); } /** * Describe <code>getBuildingType</code> method here. * * @param buildingTypeIndex an <code>int</code> value * @return a <code>BuildingType</code> value */ public BuildingType getBuildingType(int buildingTypeIndex) { return buildingTypeList.get(buildingTypeIndex); } public BuildingType getBuildingType(String id) { return (BuildingType) getType(id); } // -- Goods -- public List<GoodsType> getGoodsTypeList() { return goodsTypeList; } /** * Describe <code>numberOfGoodsTypes</code> method here. * * @return an <code>int</code> value */ public int numberOfGoodsTypes() { return goodsTypeList.size(); } public int numberOfStoredGoodsTypes() { return storableTypes; } public List<GoodsType> getFarmedGoodsTypeList() { return farmedGoodsTypeList; } public List<GoodsType> getNewWorldGoodsTypeList() { return newWorldGoodsTypeList; } /** * Describe <code>numberOfFarmedGoodsTypes</code> method here. * * @return an <code>int</code> value */ public int numberOfFarmedGoodsTypes() { return farmedGoodsTypeList.size(); } /** * Describe <code>getGoodsType</code> method here. * * @param id a <code>String</code> value * @return a <code>GoodsType</code> value */ public GoodsType getGoodsType(String id) { return (GoodsType) getType(id); } public List<GoodsType> getGoodsFood() { return foodGoodsTypeList; } // -- Resources -- public List<ResourceType> getResourceTypeList() { return resourceTypeList; } public int numberOfResourceTypes() { return resourceTypeList.size(); } public ResourceType getResourceType(String id) { return (ResourceType) getType(id); } // -- Tiles -- public List<TileType> getTileTypeList() { return tileTypeList; } public int numberOfTileTypes() { return tileTypeList.size(); } public TileType getTileType(String id) { return (TileType) getType(id); } // -- Improvements -- public List<TileImprovementType> getTileImprovementTypeList() { return tileImprovementTypeList; } public TileImprovementType getTileImprovementType(String id) { return (TileImprovementType) getType(id); } // -- Improvement Actions -- public List<ImprovementActionType> getImprovementActionTypeList() { return improvementActionTypeList; } public ImprovementActionType getImprovementActionType(String id) { return (ImprovementActionType) getType(id); } // -- Units -- public List<UnitType> getUnitTypeList() { return unitTypeList; } public int numberOfUnitTypes() { return unitTypeList.size(); } public UnitType getUnitType(String id) { return (UnitType) getType(id); } public UnitType getExpertForProducing(GoodsType goodsType) { return experts.get(goodsType); } /** * Return the unit types which have any of the given abilities * * @param abilities The abilities for the search * @return a <code>List</code> of <code>UnitType</code> */ public List<UnitType> getUnitTypesWithAbility(String... abilities) { ArrayList<UnitType> unitTypes = new ArrayList<UnitType>(); for (UnitType unitType : getUnitTypeList()) { for (String ability : abilities) { if (unitType.hasAbility(ability)) { unitTypes.add(unitType); break; } } } return unitTypes; } /** * Returns the unit types that can be trained in Europe. */ public List<UnitType> getUnitTypesTrainedInEurope() { return unitTypesTrainedInEurope; } /** * Returns the unit types that can be purchased in Europe. */ public List<UnitType> getUnitTypesPurchasedInEurope() { return unitTypesPurchasedInEurope; } // -- Founding Fathers -- public List<FoundingFather> getFoundingFathers() { return foundingFathers; } public int numberOfFoundingFathers() { return foundingFathers.size(); } public FoundingFather getFoundingFather(String id) { return (FoundingFather) getType(id); } // -- NationTypes -- public List<NationType> getNationTypes() { return nationTypes; } public List<EuropeanNationType> getEuropeanNationTypes() { return europeanNationTypes; } public List<EuropeanNationType> getREFNationTypes() { return REFNationTypes; } public List<IndianNationType> getIndianNationTypes() { return indianNationTypes; } public List<EuropeanNationType> getClassicNationTypes() { return classicNationTypes; } public int numberOfNationTypes() { return nationTypes.size(); } public NationType getNationType(String id) { return (NationType) getType(id); } // -- Nations -- public List<Nation> getNations() { return nations; } public Nation getNation(String id) { return (Nation) getType(id); } public List<Nation> getClassicNations() { return classicNations; } public List<Nation> getEuropeanNations() { return europeanNations; } public List<Nation> getIndianNations() { return indianNations; } public List<Nation> getREFNations() { return REFNations; } // -- EquipmentTypes -- public List<EquipmentType> getEquipmentTypeList() { return equipmentTypes; } public EquipmentType getEquipmentType(String id) { return (EquipmentType) getType(id); } // -- DifficultyLevels -- public List<DifficultyLevel> getDifficultyLevels() { return difficultyLevels; } /** * Describe <code>getDifficultyLevel</code> method here. * * @param id a <code>String</code> value * @return a <code>DifficultyLevel</code> value */ public DifficultyLevel getDifficultyLevel(String id) { return (DifficultyLevel) getType(id); } /** * Describe <code>getDifficultyLevel</code> method here. * * @param level an <code>int</code> value * @return a <code>DifficultyLevel</code> value */ public DifficultyLevel getDifficultyLevel(int level) { return difficultyLevels.get(level); } /** * Applies the difficulty level to the current specification. * * @param difficultyLevel difficulty level to apply */ public void applyDifficultyLevel(int difficultyLevel) { for (String key : difficultyLevels.get(difficultyLevel).getOptions().keySet()) { allOptions.put(key, difficultyLevels.get(difficultyLevel).getOptions().get(key)); } } /** * Loads the specification. * * @param is The stream to load the specification from. */ public static void createSpecification(InputStream is) { specification = new Specification(is); } // FIXME urgently! public static Specification getSpecification() { if (specification == null) { try { specification = new Specification(new FileInputStream("data/freecol/specification.xml")); logger.info("getSpecification()"); } catch (Exception e) { } } return specification; } /** * Returns the FreeColGameObjectType identified by the * attributeName, or the default value if there is no such * attribute. * * @param in the XMLStreamReader * @param attributeName the name of the attribute identifying the * FreeColGameObjectType * @param returnClass the class of the return value * @param defaultValue the value to return if there is no * attribute named attributeName * @return a FreeColGameObjectType value */ public <T extends FreeColGameObjectType> T getType(XMLStreamReader in, String attributeName, Class<T> returnClass, T defaultValue) { final String attributeString = in.getAttributeValue(null, attributeName); if (attributeString != null) { return returnClass.cast(getType(attributeString)); } else { return defaultValue; } } }

The table below shows all metrics for Specification.java.

MetricValueDescription
BLOCKS145.00Number of blocks
BLOCK_COMMENT 0.00Number of block comment lines
COMMENTS200.00Comment lines
COMMENT_DENSITY 0.44Comment density
COMPARISONS64.00Number of comparison operators
CYCLOMATIC134.00Cyclomatic complexity
DECL_COMMENTS41.00Comments in declarations
DOC_COMMENT179.00Number of javadoc comment lines
ELOC450.00Effective lines of code
EXEC_COMMENTS 5.00Comments in executable code
EXITS93.00Procedure exits
FUNCTIONS67.00Number of function declarations
HALSTEAD_DIFFICULTY76.57Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY128.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 1.00JAVA0008 Empty catch block
JAVA0009 2.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA004918.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 1.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 7.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 1.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 1.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 4.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 3.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA011743.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 3.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 1.00JAVA0144 Line exceeds maximum M characters
JAVA0145 0.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 1.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 1.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA025925.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 1.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES905.00Number of lines in the source file
LINE_COMMENT21.00Number of line comments
LOC562.00Lines of code
LOGICAL_LINES300.00Number of statements
LOOPS15.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS1441.00Number of operands
OPERATORS2724.00Number of operators
PARAMS35.00Number of formal parameter declarations
PROGRAM_LENGTH4165.00Halstead program length
PROGRAM_VOCAB458.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS93.00Number of return points from functions
SIZE32892.00Size of the file in bytes
UNIQUE_OPERANDS414.00Number of unique operands
UNIQUE_OPERATORS44.00Number of unique operators
WHITESPACE143.00Number of whitespace lines