IndianSettlement.java

Index Score
net.sf.freecol.common.model
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
COMPARISONSNumber of comparison operators
EXITSProcedure exits
CYCLOMATICCyclomatic complexity
SIZESize of the file in bytes
BLOCKSNumber of blocks
OPERATORSNumber of operators
DECL_COMMENTSComments in declarations
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
DOC_COMMENTNumber of javadoc comment lines
LINESNumber of lines in the source file
UNIQUE_OPERANDSNumber of unique operands
RETURNSNumber of return points from functions
ELOCEffective lines of code
LOCLines of code
LOGICAL_LINESNumber of statements
PROGRAM_VOCABHalstead program vocabulary
INTERFACE_COMPLEXITYInterface complexity
COMMENTSComment lines
EXEC_COMMENTSComments in executable code
JAVA0076JAVA0076 Use of magic number
LOOPSNumber of loops
FUNCTIONSNumber of function declarations
PARAMSNumber of formal parameter declarations
JAVA0031JAVA0031 Case statement not properly closed
LINE_COMMENTNumber of line comments
JAVA0116JAVA0116 Missing javadoc: field 'field'
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
WHITESPACENumber of whitespace lines
JAVA0034JAVA0034 Missing braces in if statement
UNIQUE_OPERATORSNumber of unique operators
JAVA0179JAVA0179 Local variable hides visible field
NEST_DEPTHMaximum nesting depth
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0094JAVA0094 Field hides a superclass field
PROGRAM_VOLUMEHalstead program volume
JAVA0259JAVA0259 Return of collection/array field
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0032JAVA0032 Switch statement missing default
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0171JAVA0171 Unused local variable
JAVA0067JAVA0067 Array descriptor on identifier name
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
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.model; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import java.util.StringTokenizer; import java.util.logging.Logger; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; import net.sf.freecol.FreeCol; import net.sf.freecol.client.gui.i18n.Messages; import net.sf.freecol.common.model.Map.Position; import net.sf.freecol.common.model.Unit.Role; import org.w3c.dom.Element; /** * Represents an Indian settlement. */ public class IndianSettlement extends Settlement { private static final Logger logger = Logger.getLogger(IndianSettlement.class.getName()); public static final int MISSIONARY_TENSION = -3; public static final int MAX_CONVERT_DISTANCE = 10; public static final int TURNS_PER_TRIBUTE = 5; public static final int ALARM_RADIUS = 2; public static final int ALARM_TILE_IN_USE = 2; public static final int ALARM_NEW_MISSIONARY = -100; public static final String UNITS_TAG_NAME = "units"; public static final String OWNED_UNITS_TAG_NAME = "ownedUnits"; public static final String ALARM_TAG_NAME = "alarm"; public static final String MISSIONARY_TAG_NAME = "missionary"; public static final String WANTED_GOODS_TAG_NAME = "wantedGoods"; /** The amount of goods a brave can produce a single turn. */ //private static final int WORK_AMOUNT = 5; /** The amount of raw material that should be available before producing manufactured goods. */ public static final int KEEP_RAW_MATERIAL = 50; /** * This is the skill that can be learned by Europeans at this * settlement. At the server side its value will be null when the * skill has already been taught to a European. At the client * side the value null is also possible in case the player hasn't * checked out the settlement yet. */ private UnitType learnableSkill = null; private GoodsType[] wantedGoods = new GoodsType[] {null, null, null}; /** * At the client side isVisited is true in case the player has * visited the settlement. */ private boolean isVisited = false; /** * Whether this is the capital of the tribe. */ private boolean isCapital = false; private List<Unit> units = Collections.emptyList(); private ArrayList<Unit> ownedUnits = new ArrayList<Unit>(); private Unit missionary = null; /** Used for monitoring the progress towards creating a convert. */ private int convertProgress = 0; /** The number of the turn during which the last tribute was paid. */ int lastTribute = 0; /** * Stores the alarm levels. <b>Only used by AI.</b> * 0-1000 with 1000 as the maximum alarm level. */ private java.util.Map<Player, Tension> alarm = new HashMap<Player, Tension>(); // sort goods types descending by price private final Comparator<GoodsType> wantedGoodsComparator = new Comparator<GoodsType>() { public int compare(GoodsType goodsType1, GoodsType goodsType2) { return getPrice(goodsType2, 100) - getPrice(goodsType1, 100); } }; // sort goods descending by amount and price when amounts are equal private final Comparator<Goods> exportGoodsComparator = new Comparator<Goods>() { public int compare(Goods goods1, Goods goods2) { if (goods2.getAmount() == goods1.getAmount()) { return getPrice(goods2) - getPrice(goods1); } else { return goods2.getAmount() - goods1.getAmount(); } } }; /** * The constructor to use. * * @param game The <code>Game</code> in which this object belong. * @param player The <code>Player</code> owning this settlement. * @param tile The location of the <code>IndianSettlement</code>. * @param isCapital True if settlement is tribe's capital * @param learnableSkill The skill that can be learned by Europeans at this settlement. * @param isVisited Indicates if any European scout has asked to speak with the chief. * @param missionary The missionary in this settlement (or null). * @exception IllegalArgumentException if an invalid tribe or kind is given */ public IndianSettlement(Game game, Player player, Tile tile, boolean isCapital, UnitType learnableSkill, boolean isVisited, Unit missionary) { super(game, player, tile); if (tile == null) { throw new IllegalArgumentException("Parameter 'tile' must not be 'null'."); } tile.setOwner(player); tile.setSettlement(this); goodsContainer = new GoodsContainer(game, this); this.learnableSkill = learnableSkill; this.isCapital = isCapital; this.isVisited = isVisited; this.missionary = missionary; convertProgress = 0; updateWantedGoods(); } /** * Initiates a new <code>IndianSettlement</code> from an <code>Element</code>. * * @param game The <code>Game</code> in which this object belong. * @param in The input stream containing the XML. * @throws XMLStreamException if a problem was encountered * during parsing. */ public IndianSettlement(Game game, XMLStreamReader in) throws XMLStreamException { super(game, in); readFromXML(in); } /** * Initiates a new <code>IndianSettlement</code> from an <code>Element</code>. * * @param game The <code>Game</code> in which this object belong. * @param e An XML-element that will be used to initialize * this object. */ public IndianSettlement(Game game, Element e) { super(game, e); readFromXMLElement(e); } /** * Initiates a new <code>IndianSettlement</code> * with the given ID. The object should later be * initialized by calling either * {@link #readFromXML(XMLStreamReader)} or * {@link #readFromXMLElement(Element)}. * * @param game The <code>Game</code> in which this object belong. * @param id The unique identifier for this object. */ public IndianSettlement(Game game, String id) { super(game, id); } /** * Returns a suitable (non-unique) name. * @return The name of this settlement. */ public String getLocationName() { if (isCapital()){ return Messages.message("indianCapital", "%nation%", getOwner().getNationAsString()); } else { return Messages.message("indianSettlement", "%nation%", getOwner().getNationAsString()); } } /** * Returns the alarm Map. * * @return the alarm Map. */ public java.util.Map<Player, Tension> getAlarm() { return alarm; } /** * Returns the amount of gold this settlement pays as a tribute. * * @param player a <code>Player</code> value * @return an <code>int</code> value */ public int getTribute(Player player) { // increase tension whether we pay or not // apply tension directly to this settlement and let propagation works modifyAlarm(player, Tension.TENSION_ADD_NORMAL); int gold = 0; if (getGame().getTurn().getNumber() > lastTribute + TURNS_PER_TRIBUTE) { switch(getOwner().getTension(player).getLevel()) { case HAPPY: case CONTENT: gold = Math.min(getOwner().getGold() / 10, 100); break; case DISPLEASED: gold = Math.min(getOwner().getGold() / 20, 100); break; case ANGRY: case HATEFUL: default: // do nothing } } getOwner().modifyGold(-gold); lastTribute = getGame().getTurn().getNumber(); return gold; } /** * Modifies the alarm level towards the given player. * * @param player The <code>Player</code>. * @param addToAlarm The amount to add to the current alarm level. */ public void modifyAlarm(Player player, int addToAlarm) { Tension tension = alarm.get(player); if(tension != null) { tension.modify(addToAlarm); } // propagate alarm upwards if (owner != null) { if (isCapital()) { // capital has a greater impact owner.modifyTension(player, addToAlarm, this); } else { owner.modifyTension(player, addToAlarm/2, this); } } } /** * Propagates the tension felt towards a given nation * from the tribe down to each settlement that has already met that nation. * * @param player The Player towards whom the alarm is felt. * @param addToAlarm The amount to add to the current alarm level. */ public void propagatedAlarm(Player player, int addToAlarm) { Tension tension = alarm.get(player); // only applies tension if settlement has met europeans if (tension != null && isVisited) { tension.modify(addToAlarm); } } /** * Sets alarm towards the given player. * * @param player The <code>Player</code>. * @param newAlarm The new alarm value. */ public void setAlarm(Player player, Tension newAlarm) { alarm.put(player, newAlarm); } /** * Gets the alarm level towards the given player. * @param player The <code>Player</code> to get the alarm level for. * @return An object representing the alarm level. */ public Tension getAlarm(Player player) { return alarm.get(player); } /** * Gets the ID of the alarm message associated with the alarm * level of this player. * * @param player The other player. * @return The ID of an alarm level message. */ public String getAlarmLevelMessage(Player player) { if (alarm.get(player) == null) { alarm.put(player, new Tension(0)); } return "indianSettlement.alarm." + alarm.get(player).getLevel().toString().toLowerCase(); } /** * Returns true if a European player has visited this settlement to speak with the chief. * @return true if a European player has visited this settlement to speak with the chief. */ public boolean hasBeenVisited() { return isVisited; } /** * Sets the visited status of this settlement to true, indicating * that a European has had a chat with the chief. * * @param player a <code>Player</code> value */ public void setVisited(Player player) { this.isVisited = true; if (alarm.get(player) == null) { alarm.put(player, new Tension(0)); } } /** * Adds the given <code>Unit</code> to the list of units that belongs to this * <code>IndianSettlement</code>. * * @param unit The <code>Unit</code> to be added. */ public void addOwnedUnit(Unit unit) { if (unit == null) { throw new IllegalArgumentException("Parameter 'unit' must not be 'null'."); } if (!ownedUnits.contains(unit)) { ownedUnits.add(unit); } } /** * Gets an iterator over all the units this * <code>IndianSettlement</code> is owning. * * @return The <code>Iterator</code>. */ public Iterator<Unit> getOwnedUnitsIterator() { return ownedUnits.iterator(); } /** * Removes the given <code>Unit</code> to the list of units that * belongs to this <code>IndianSettlement</code>. Returns true if * the Unit was removed. * * @param unit The <code>Unit</code> to be removed from the * list of the units this <code>IndianSettlement</code> * owns. * @return a <code>boolean</code> value */ public boolean removeOwnedUnit(Unit unit) { if (unit == null) { throw new IllegalArgumentException("Parameter 'unit' must not be 'null'."); } return ownedUnits.remove(unit); } /** * Returns the skill that can be learned at this settlement. * @return The skill that can be learned at this settlement. */ public UnitType getLearnableSkill() { return learnableSkill; } /** * Returns the missionary from this settlement if there is one or null if there is none. * @return The missionary from this settlement if there is one or null if there is none. */ public Unit getMissionary() { return missionary; } /** * Sets the missionary for this settlement. * @param missionary The missionary for this settlement. */ public void setMissionary(Unit missionary) { if (missionary != null) { if (missionary.getRole() != Role.MISSIONARY) { throw new IllegalArgumentException("Specified unit is not a missionary."); } missionary.setLocation(null); Tension currentAlarm = alarm.get(missionary.getOwner()); if (currentAlarm == null) { alarm.put(missionary.getOwner(), new Tension(0)); } else { currentAlarm.modify(ALARM_NEW_MISSIONARY); } } if (missionary != this.missionary) { convertProgress = 0; } if (this.missionary != null) { this.missionary.dispose(); } this.missionary = missionary; getTile().updatePlayerExploredTiles(); } /** * Gets the response to an attempt to create a mission * @return response */ public String getResponseToMissionaryAttempt(Tension.Level tension, String success) { String response = null; // Attempt Successful if(success.equals("true")){ switch(tension){ case HAPPY: response = "indianSettlement.mission.Happy"; break; case CONTENT: response = "indianSettlement.mission.Content"; break; case DISPLEASED: response = "indianSettlement.mission.Displeased"; break; default: logger.warning("Unknown response for tension " + tension); } } else { switch(tension){ case ANGRY: response = "indianSettlement.mission.Angry"; break; case HATEFUL: response = "indianSettlement.mission.Hateful"; break; default: logger.warning("Requesting reaction when no mission was established"); } } return response; } public GoodsType[] getWantedGoods() { return wantedGoods; } public void setWantedGoods(int index, GoodsType type) { if (0 <= index && index <= 2) { wantedGoods[index] = type; } } /** * Sets the learnable skill for this Indian settlement. * @param skill The new learnable skill for this Indian settlement. */ public void setLearnableSkill(UnitType skill) { learnableSkill = skill; } /** * Gets the kind of Indian settlement. */ public SettlementType getTypeOfSettlement() { return ((IndianNationType) owner.getNationType()).getTypeOfSettlement(); } /** * Gets the radius of what the <code>Settlement</code> considers * as it's own land. Cities dominate 2 tiles, other settlements 1 tile. * * @return Settlement radius */ @Override public int getRadius() { if (getTypeOfSettlement() == SettlementType.INCA_CITY || getTypeOfSettlement() == SettlementType.AZTEC_CITY) { return 2; } else { return 1; } } /** * Returns <code>true</code> if this is the Nation's capital. * * @return <code>true</code> if this is the Nation's capital. */ public boolean isCapital() { return isCapital; } public void setCapital(boolean isCapital) { this.isCapital = isCapital; } /** * Adds a <code>Locatable</code> to this Location. * * @param locatable The <code>Locatable</code> to add to this Location. */ @Override public void add(Locatable locatable) { if (locatable instanceof Unit) { if (!units.contains(locatable)) { if (units.equals(Collections.emptyList())) { units = new ArrayList<Unit>(); } units.add((Unit) locatable); } } else if (locatable instanceof Goods) { goodsContainer.addGoods((Goods)locatable); } else { logger.warning("Tried to add an unrecognized 'Locatable' to a IndianSettlement."); } } /** * Removes a <code>Locatable</code> from this Location. * * @param locatable The <code>Locatable</code> to remove from this Location. */ @Override public void remove(Locatable locatable) { if (locatable instanceof Unit) { units.remove((Unit) locatable); } else if (locatable instanceof Goods) { goodsContainer.removeGoods((Goods)locatable); } else { logger.warning("Tried to remove an unrecognized 'Locatable' from a IndianSettlement."); } } /** * Returns the amount of Units at this Location. * * @return The amount of Units at this Location. */ @Override public int getUnitCount() { return units.size(); } public List<Unit> getUnitList() { return units; } public Iterator<Unit> getUnitIterator() { return units.iterator(); } public Unit getFirstUnit() { if (units.isEmpty()) { return null; } else { return units.get(0); } } public Unit getLastUnit() { if (units.isEmpty()) { return null; } else { return units.get(units.size() - 1); } } /** * Gets the <code>Unit</code> that is currently defending this <code>IndianSettlement</code>. * @param attacker The unit that would be attacking this <code>IndianSettlement</code>. * @return The <code>Unit</code> that has been chosen to defend this <code>IndianSettlement</code>. */ @Override public Unit getDefendingUnit(Unit attacker) { Unit defender = null; float defencePower = -1.0f; for (Unit nextUnit : units) { float tmpPower = attacker.getGame().getCombatModel().getDefencePower(attacker, nextUnit); if (tmpPower > defencePower) { defender = nextUnit; defencePower = tmpPower; } } return defender; } /** * Gets the amount of gold this <code>IndianSettlment</code> * is willing to pay for the given <code>Goods</code>. * * <br><br> * * It is only meaningful to call this method from the * server, since the settlement's {@link GoodsContainer} * is hidden from the clients. * * @param goods The <code>Goods</code> to price. * @return The price. */ public int getPrice(Goods goods) { return getPrice(goods.getType(), goods.getAmount()); } /** * Gets the amount of gold this <code>IndianSettlment</code> * is willing to pay for the given <code>Goods</code>. * * <br><br> * * It is only meaningful to call this method from the * server, since the settlement's {@link GoodsContainer} * is hidden from the clients. * * @param type The type of <code>Goods</code> to price. * @param amount The amount of <code>Goods</code> to price. * @return The price. */ public int getPrice(GoodsType type, int amount) { int returnPrice = 0; if (amount > 100) { throw new IllegalArgumentException(); } if (type == Goods.MUSKETS) { int need = 0; int supply = getGoodsCount(Goods.MUSKETS); for (int i=0; i<ownedUnits.size(); i++) { need += Unit.MUSKETS_TO_ARM_INDIAN; if (ownedUnits.get(i).isArmed()) { supply += Unit.MUSKETS_TO_ARM_INDIAN; } } int sets = ((getGoodsCount(Goods.MUSKETS) + amount) / Unit.MUSKETS_TO_ARM_INDIAN) - (getGoodsCount(Goods.MUSKETS) / Unit.MUSKETS_TO_ARM_INDIAN); int startPrice = (19+getPriceAddition()) - (supply / Unit.MUSKETS_TO_ARM_INDIAN); for (int i=0; i<sets; i++) { if ((startPrice-i) < 8 && (need > supply || getGoodsCount(Goods.MUSKETS) < Unit.MUSKETS_TO_ARM_INDIAN * 2)) { startPrice = 8+i; } returnPrice += Unit.MUSKETS_TO_ARM_INDIAN * (startPrice-i); } } else if (type == Goods.HORSES) { int need = 0; int supply = getGoodsCount(Goods.HORSES); for (int i=0; i<ownedUnits.size(); i++) { need += Unit.HORSES_TO_MOUNT_INDIAN; if (ownedUnits.get(i).isMounted()) { supply += Unit.HORSES_TO_MOUNT_INDIAN; } } int sets = (getGoodsCount(Goods.HORSES) + amount) / Unit.HORSES_TO_MOUNT_INDIAN - (getGoodsCount(Goods.HORSES) / Unit.HORSES_TO_MOUNT_INDIAN); int startPrice = (24+getPriceAddition()) - (supply/Unit.HORSES_TO_MOUNT_INDIAN); for (int i=0; i<sets; i++) { if ((startPrice-(i*4)) < 4 && (need > supply || getGoodsCount(Goods.HORSES) < Unit.HORSES_TO_MOUNT_INDIAN * 2)) { startPrice = 4+(i*4); } returnPrice += Unit.HORSES_TO_MOUNT_INDIAN * (startPrice-(i*4)); } } else if (type.isFarmed()) { returnPrice = 0; } else { int currentGoods = getGoodsCount(type); // Increase amount if raw materials are produced: GoodsType rawType = type.getRawMaterial(); if (rawType != null) { int rawProduction = getMaximumProduction(rawType); if (currentGoods < 100) { if (rawProduction < 5) { currentGoods += rawProduction * 10; } else if (rawProduction < 10) { currentGoods += 50 + Math.max((rawProduction-5) * 5, 0); } else if (rawProduction < 20) { currentGoods += 75 + Math.max((rawProduction-10) * 2, 0); } else { currentGoods += 100; } } } if (type.isTradeGoods()) { currentGoods += 20; } int valueGoods = Math.min(currentGoods + amount, 200) - currentGoods; if (valueGoods < 0) { valueGoods = 0; } returnPrice = (int) (((20.0+getPriceAddition())-(0.05*(currentGoods+valueGoods)))*(currentGoods+valueGoods) - ((20.0+getPriceAddition())-(0.05*(currentGoods)))*(currentGoods)); } // Bonus for top 3 types of goods: if (type == wantedGoods[0]) { returnPrice = (returnPrice*12)/10; } else if (type == wantedGoods[1]) { returnPrice = (returnPrice*11)/10; } else if (type == wantedGoods[2]) { returnPrice = (returnPrice*105)/100; } return returnPrice; } /** * Gets the maximum possible production of the given type of goods. * @param goodsType The type of goods to check. * @return The maximum amount, of the given type of goods, that can * be produced in one turn. */ public int getMaximumProduction(GoodsType goodsType) { int amount = 0; Iterator<Position> it = getGame().getMap().getCircleIterator(getTile().getPosition(), true, getRadius()); while (it.hasNext()) { Tile workTile = getGame().getMap().getTile(it.next()); if (workTile.getOwningSettlement() == null || workTile.getOwningSettlement() == this) { amount += workTile.potential(goodsType); } } return amount; } /** * Updates the variable wantedGoods. * * <br><br> * * It is only meaningful to call this method from the * server, since the settlement's {@link GoodsContainer} * is hidden from the clients. */ public void updateWantedGoods() { /* TODO: Try the different types goods in "random" order * (based on the numbers of units on this tile etc): */ List<GoodsType> goodsTypes = new ArrayList<GoodsType>(FreeCol.getSpecification().getGoodsTypeList()); Collections.sort(goodsTypes, wantedGoodsComparator); int wantedIndex = 0; for (GoodsType goodsType : goodsTypes) { // Indians do not ask for horses or guns if (goodsType.isMilitaryGoods()) continue; // no sense asking for bells or crosses if (!goodsType.isStorable()) continue; if (wantedIndex < wantedGoods.length) { wantedGoods[wantedIndex] = goodsType; wantedIndex++; } else { break; } } } /** * Get the extra bonus if this is a <code>LONGHOUSE</code>, * <code>CITY</code> or a capital. */ private int getPriceAddition() { return getBonusMultiplier() - 1; } /** * Get general bonus multiplier. This is >1 if this is a <code>LONGHOUSE</code>, * <code>CITY</code> or a capital. * * @return The bonus multiplier. */ public int getBonusMultiplier() { int multiplier = 0; switch (getTypeOfSettlement()) { case INDIAN_CAMP: multiplier = 1; break; case INDIAN_VILLAGE: multiplier = 2; break; case AZTEC_CITY: case INCA_CITY: multiplier = 3; break; } if (isCapital()) { multiplier++; } return multiplier; } @Override public boolean contains(Locatable locatable) { if (locatable instanceof Unit) { return units.contains((Unit) locatable); } else { return false; } } @Override public boolean canAdd(Locatable locatable) { return true; } public int getProductionOf(GoodsType type) { int potential = 0; Iterator<Position> it = getGame().getMap().getCircleIterator(getTile().getPosition(), true, getRadius()); while (it.hasNext()) { Tile workTile = getGame().getMap().getTile(it.next()); if ((workTile.getOwningSettlement() == null || workTile.getOwningSettlement() == this) && !workTile.isOccupied()) { potential += workTile.potential(type); } } if (type.isFoodType()) { potential = Math.min(potential, ownedUnits.size()*3); } return potential; } @Override public void newTurn() { if (isUninitialized()) { logger.warning("Uninitialized when calling newTurn"); return; } List<GoodsType> goodsList = FreeCol.getSpecification().getGoodsTypeList(); int workers = ownedUnits.size(); for (GoodsType g : goodsList) { /* Determine the maximum possible production for each type of goods: */ goodsContainer.addGoods(g, getProductionOf(g)); } /* Use tools (if available) to produce manufactured goods: */ if (getGoodsCount(Goods.TOOLS) > 0) { GoodsType typeWithSmallestAmount = null; for (GoodsType g : goodsList) { if (g.isFoodType() || g.isBuildingMaterial() || g.isRawBuildingMaterial()) { continue; } if (g.isRawMaterial() && getGoodsCount(g) > KEEP_RAW_MATERIAL) { if (typeWithSmallestAmount == null || getGoodsCount(g.getProducedMaterial()) < getGoodsCount(typeWithSmallestAmount)) { typeWithSmallestAmount = g.getProducedMaterial(); } } } if (typeWithSmallestAmount != null) { int production = Math.min(getGoodsCount(typeWithSmallestAmount.getRawMaterial()), Math.min(10, getGoodsCount(Goods.TOOLS))); goodsContainer.removeGoods(Goods.TOOLS, production); goodsContainer.removeGoods(typeWithSmallestAmount.getRawMaterial(), production); goodsContainer.addGoods(typeWithSmallestAmount, production * 5); } } /* Consume goods: TODO: make this more generic */ consumeGoods(Goods.FOOD, getFoodConsumption()); consumeGoods(Goods.RUM, 2 * workers); consumeGoods(Goods.TRADEGOODS, 2 * workers); for (GoodsType goodsType : FreeCol.getSpecification().getNewWorldGoodsTypeList()) { consumeGoods(goodsType, workers); } consumeGoods(Goods.ORE, workers); consumeGoods(Goods.SILVER, workers); consumeGoods(Goods.CIGARS, workers); consumeGoods(Goods.COATS, workers); consumeGoods(Goods.CLOTH, workers); goodsContainer.removeAbove(500); checkForNewIndian(); /* Increase alarm: */ if (getUnitCount() > 0) { increaseAlarm(); } /* Increase convert progress and generate convert if needed. */ if (missionary != null && getGame().getViewOwner() == null) { int increment = 8; // Update increment if missionary is an expert. if (missionary.hasAbility("model.ability.expertMissionary")) { increment = 13; } // Increase increment if alarm level is high. increment += 2 * alarm.get(missionary.getOwner()).getValue() / 100; convertProgress += increment; int extra = Math.max(0, 8-getUnitCount()*getUnitCount()); extra *= extra; extra *= extra; if (convertProgress >= 100 + extra && getUnitCount() > 2) { Tile targetTile = null; Iterator<Position> ffi = getGame().getMap().getFloodFillIterator(getTile().getPosition()); while (ffi.hasNext()) { Tile t = getGame().getMap().getTile(ffi.next()); if (getTile().getDistanceTo(t) > MAX_CONVERT_DISTANCE) { break; } if (t.getSettlement() != null && t.getSettlement().getOwner() == missionary.getOwner()) { targetTile = t; break; } } if (targetTile != null) { convertProgress = 0; List<UnitType> converts = FreeCol.getSpecification().getUnitTypesWithAbility("model.ability.convert"); if (converts.size() > 0) { getUnitIterator().next().dispose(); ModelController modelController = getGame().getModelController(); int random = modelController.getRandom(getId() + "getNewConvertType", converts.size()); Unit u = modelController.createUnit(getId() + "newTurn100missionary", targetTile, missionary.getOwner(), converts.get(random)); addModelMessage(u, ModelMessage.MessageType.UNIT_ADDED, u, "model.colony.newConvert", "%nation%", getOwner().getNationAsString(), "%colony%", targetTile.getColony().getName()); logger.info("New convert created for " + missionary.getOwner().getName() + " with ID=" + u.getId()); } } } } updateWantedGoods(); } // Create a new colonist if there is enough food: private void checkForNewIndian() { // Alcohol also contributes to create children. if (getFoodCount() + 4*getGoodsCount(Goods.RUM) > 200+KEEP_RAW_MATERIAL ) { if (ownedUnits.size() <= 6 + getTypeOfSettlement().ordinal()) { // up to a limit. Anyway cities produce more children than camps List<UnitType> unitTypes = FreeCol.getSpecification().getUnitTypesWithAbility("model.ability.bornInIndianSettlement"); if (unitTypes.size() > 0) { int random = getGame().getModelController().getRandom(getId() + "bornInIndianSettlement", unitTypes.size()); Unit u = getGame().getModelController().createUnit(getId() + "newTurn200food", getTile(), getOwner(), unitTypes.get(random)); consumeGoods(Goods.FOOD, 200); // All food will be consumed, even if RUM helped consumeGoods(Goods.RUM, 200/4); // Also, some available RUM is consumed // I know that consumeGoods will produce gold, which is explained because children are always a gift addOwnedUnit(u); // New indians quickly go out of their city and start annoying. logger.info("New indian native created in " + getTile() + " with ID=" + u.getId()); } } } } private void increaseAlarm() { java.util.Map<Player, Integer> extraAlarm = new HashMap<Player, Integer>(); for (Player enemy : getGame().getEuropeanPlayers()) { extraAlarm.put(enemy, new Integer(0)); } int alarmRadius = getRadius() + ALARM_RADIUS; // the radius in which Europeans cause alarm Iterator<Position> ci = getGame().getMap().getCircleIterator(getTile().getPosition(), true, alarmRadius); while (ci.hasNext()) { Tile tile = getGame().getMap().getTile(ci.next()); Colony colony = tile.getColony(); if (colony == null) { // Nearby military units: if (tile.getFirstUnit() != null) { Player enemy = tile.getFirstUnit().getOwner(); if (enemy.isEuropean()) { int alarm = extraAlarm.get(enemy); for (Unit unit : tile.getUnitList()) { if (unit.isOffensiveUnit() && !unit.isNaval()) { alarm += unit.getType().getOffence(); } } extraAlarm.put(enemy, alarm); } } // Land being used by another settlement: if (tile.getOwningSettlement() != null) { Player enemy = tile.getOwningSettlement().getOwner(); if (enemy.isEuropean()) { extraAlarm.put(enemy, extraAlarm.get(enemy).intValue() + ALARM_TILE_IN_USE); } } } else { // Settlement: Player enemy = colony.getOwner(); extraAlarm.put(enemy, extraAlarm.get(enemy).intValue() + colony.getUnitCount()); } } // Missionary helps reducing alarm a bit, here and to the tribe as a whole. // No reduction effect on other settlements (1/4 of this) unless this is capital. if (missionary != null) { Player enemy = missionary.getOwner(); int missionaryAlarm = MISSIONARY_TENSION; if (missionary.hasAbility("model.ability.expertMissionary")) { missionaryAlarm *= 2; } extraAlarm.put(enemy, extraAlarm.get(enemy).intValue() + missionaryAlarm); } for (Entry<Player, Integer> entry : extraAlarm.entrySet()) { Integer newAlarm = entry.getValue(); if (alarm != null) { Player player = entry.getKey(); int modifiedAlarm = (int) player.getFeatureContainer() .applyModifier(newAlarm.intValue(), "model.modifier.nativeAlarmModifier", null, getGame().getTurn()); Tension oldAlarm = alarm.get(player); if (oldAlarm != null) { modifiedAlarm -= 4 + oldAlarm.getValue()/100; } modifyAlarm(player, modifiedAlarm); } } } private void consumeGoods(GoodsType type, int amount) { if (getGoodsCount(type) > 0) { amount = Math.min(amount, getGoodsCount(type)); getOwner().modifyGold(amount); goodsContainer.removeGoods(type, amount); } } /** * Disposes this settlement and removes its claims to adjacent * tiles. */ @Override public void dispose() { while (ownedUnits.size() > 0) { ownedUnits.remove(0).setIndianSettlement(null); } for (Unit unit : units) { unit.dispose(); } Tile settlementTile = getTile(); Map map = getGame().getMap(); Position position = settlementTile.getPosition(); Iterator<Position> circleIterator = map.getCircleIterator(position, true, getRadius()); super.dispose(); } /** * Creates the {@link GoodsContainer}. * <br><br> * DO NOT USE OTHER THAN IN {@link net.sf.freecol.server.FreeColServer#loadGame}: * Only for compatibility when loading savegames with pre-0.0.3 protocols. */ public void createGoodsContainer() { goodsContainer = new GoodsContainer(getGame(), this); } private void unitsToXML(XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame) throws XMLStreamException { if (!units.isEmpty()) { out.writeStartElement(UNITS_TAG_NAME); for (Unit unit : units) { unit.toXML(out, player, showAll, toSavedGame); } out.writeEndElement(); } } /** * This method writes an XML-representation of this object to * the given stream. * * <br><br> * * Only attributes visible to the given <code>Player</code> will * be added to that representation if <code>showAll</code> is * set to <code>false</code>. * * @param out The target stream. * @param player The <code>Player</code> this XML-representation * should be made for, or <code>null</code> if * <code>showAll == true</code>. * @param showAll Only attributes visible to <code>player</code> * will be added to the representation if <code>showAll</code> * is set to <i>false</i>. * @param toSavedGame If <code>true</code> then information that * is only needed when saving a game is added. * @throws XMLStreamException if there are any problems writing * to the stream. */ @Override protected void toXMLImpl(XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame) throws XMLStreamException { // Start element: out.writeStartElement(getXMLElementTagName()); if (toSavedGame && !showAll) { logger.warning("toSavedGame is true, but showAll is false"); } out.writeAttribute(ID_ATTRIBUTE, getId()); out.writeAttribute("tile", tile.getId()); out.writeAttribute("owner", owner.getId()); out.writeAttribute("lastTribute", Integer.toString(lastTribute)); out.writeAttribute("isCapital", Boolean.toString(isCapital)); if (getGame().isClientTrusted() || showAll || player == getOwner()) { out.writeAttribute("hasBeenVisited", Boolean.toString(isVisited)); out.writeAttribute("convertProgress", Integer.toString(convertProgress)); writeAttribute(out, "learnableSkill", learnableSkill); for (int i = 0; i < wantedGoods.length; i++) { String tag = "wantedGoods" + Integer.toString(i); out.writeAttribute(tag, wantedGoods[i].getId()); } } // attributes end here for (Entry<Player, Tension> entry : alarm.entrySet()) { out.writeStartElement(ALARM_TAG_NAME); out.writeAttribute("player", entry.getKey().getId()); out.writeAttribute("value", String.valueOf(entry.getValue().getValue())); out.writeEndElement(); } if (missionary != null) { out.writeStartElement(MISSIONARY_TAG_NAME); missionary.toXML(out, player, showAll, toSavedGame); out.writeEndElement(); } if (getGame().isClientTrusted() || showAll || player == getOwner()) { unitsToXML(out, player, showAll, toSavedGame); goodsContainer.toXML(out, player, showAll, toSavedGame); for (Unit unit : ownedUnits) { out.writeStartElement(OWNED_UNITS_TAG_NAME); out.writeAttribute(ID_ATTRIBUTE, unit.getId()); out.writeEndElement(); } } else { GoodsContainer emptyGoodsContainer = new GoodsContainer(getGame(), this); emptyGoodsContainer.setFakeID(goodsContainer.getId()); emptyGoodsContainer.toXML(out, player, showAll, toSavedGame); } out.writeEndElement(); } /** * Initialize this object from an XML-representation of this object. * @param in The input stream with the XML. * @throws XMLStreamException if a problem was encountered * during parsing. */ @Override protected void readFromXMLImpl(XMLStreamReader in) throws XMLStreamException { setId(in.getAttributeValue(null, ID_ATTRIBUTE)); tile = (Tile) getGame().getFreeColGameObject(in.getAttributeValue(null, "tile")); if (tile == null) { tile = new Tile(getGame(), in.getAttributeValue(null, "tile")); } owner = (Player)getGame().getFreeColGameObject(in.getAttributeValue(null, "owner")); if (owner == null) { owner = new Player(getGame(), in.getAttributeValue(null, "owner")); } isCapital = getAttribute(in, "isCapital", false); owner.addSettlement(this); featureContainer.addModifier(Settlement.DEFENCE_MODIFIER); ownedUnits.clear(); // TODO: this is support for 0.7 savegames, remove sometime final String ownedUnitsStr = in.getAttributeValue(null, "ownedUnits"); if (ownedUnitsStr != null) { StringTokenizer st = new StringTokenizer(ownedUnitsStr, ", ", false); while (st.hasMoreTokens()) { final String token = st.nextToken(); Unit u = (Unit) getGame().getFreeColGameObject(token); if (u == null) { u = new Unit(getGame(), token); owner.setUnit(u); } ownedUnits.add(u); } } // end TODO for (int i = 0; i < wantedGoods.length; i++) { String tag = WANTED_GOODS_TAG_NAME + Integer.toString(i); String wantedGoodsId = getAttribute(in, tag, null); if (wantedGoodsId != null) { wantedGoods[i] = FreeCol.getSpecification().getGoodsType(wantedGoodsId); } } isVisited = getAttribute(in, "hasBeenVisited", false); convertProgress = getAttribute(in, "convertProgress", 0); lastTribute = getAttribute(in, "lastTribute", 0); learnableSkill = FreeCol.getSpecification().getType(in, "learnableSkill", UnitType.class, null); alarm = new HashMap<Player, Tension>(); while (in.nextTag() != XMLStreamConstants.END_ELEMENT) { if (ALARM_TAG_NAME.equals(in.getLocalName())) { Player player = (Player) getGame().getFreeColGameObject(in.getAttributeValue(null, "player")); alarm.put(player, new Tension(getAttribute(in, "value", 0))); in.nextTag(); // close element } else if (WANTED_GOODS_TAG_NAME.equals(in.getLocalName())) { String[] wantedGoodsID = readFromArrayElement(WANTED_GOODS_TAG_NAME, in, new String[0]); for (int i = 0; i < wantedGoodsID.length; i++) { if (i == 3) break; wantedGoods[i] = FreeCol.getSpecification().getGoodsType(wantedGoodsID[i]); } } else if (MISSIONARY_TAG_NAME.equals(in.getLocalName())) { in.nextTag(); missionary = updateFreeColGameObject(in, Unit.class); in.nextTag(); } else if (UNITS_TAG_NAME.equals(in.getLocalName())) { units = new ArrayList<Unit>(); while (in.nextTag() != XMLStreamConstants.END_ELEMENT) { if (in.getLocalName().equals(Unit.getXMLElementTagName())) { units.add(updateFreeColGameObject(in, Unit.class)); } } } else if (OWNED_UNITS_TAG_NAME.equals(in.getLocalName())) { Unit unit = getFreeColGameObject(in, ID_ATTRIBUTE, Unit.class); ownedUnits.add(unit); owner.setUnit(unit); in.nextTag(); } else if (in.getLocalName().equals(GoodsContainer.getXMLElementTagName())) { goodsContainer = (GoodsContainer) getGame().getFreeColGameObject(in.getAttributeValue(null, ID_ATTRIBUTE)); if (goodsContainer != null) { goodsContainer.readFromXML(in); } else { goodsContainer = new GoodsContainer(getGame(), this, in); } } } } /** * Returns the tag name of the root element representing this object. * @return "indianSettlement". */ public static String getXMLElementTagName() { return "indianSettlement"; } /** * An Indian settlement is no colony. * * @return null */ public Colony getColony() { return null; } /** * Returns an array with goods to sell */ public Goods[] getSellGoods() { List<Goods> settlementGoods = getCompactGoods(); for(Goods goods : settlementGoods) { if (goods.getAmount() > 100) { goods.setAmount(100); } } Collections.sort(settlementGoods, exportGoodsComparator); Goods sellGoods[] = {null, null, null}; int i = 0; for(Goods goods : settlementGoods) { if (goods.getType().isNewWorldGoodsType()) { sellGoods[i] = goods; i++; if (i == sellGoods.length) break; } } return sellGoods; } /** * Gets the amount of gold this <code>IndianSettlment</code> * is willing to pay for the given <code>Goods</code>. * * <br><br> * * It is only meaningful to call this method from the * server, since the settlement's {@link GoodsContainer} * is hidden from the clients. * * @param goods The <code>Goods</code> to price. * @return The price. */ public int getPriceToSell(Goods goods) { return getPriceToSell(goods.getType(), goods.getAmount()); } /** * Gets the amount of gold this <code>IndianSettlment</code> * is willing to pay for the given <code>Goods</code>. * * <br><br> * * It is only meaningful to call this method from the * server, since the settlement's {@link GoodsContainer} * is hidden from the clients. * * @param type The type of <code>Goods</code> to price. * @param amount The amount of <code>Goods</code> to price. * @return The price. */ public int getPriceToSell(GoodsType type, int amount) { if (amount > 100) { throw new IllegalArgumentException(); } int price = 10 - getProductionOf(type); if (price < 1) price = 1; return amount * price; } }

The table below shows all metrics for IndianSettlement.java.

MetricValueDescription
BLOCKS210.00Number of blocks
BLOCK_COMMENT 7.00Number of block comment lines
COMMENTS377.00Comment lines
COMMENT_DENSITY 0.57Comment density
COMPARISONS182.00Number of comparison operators
CYCLOMATIC221.00Cyclomatic complexity
DECL_COMMENTS58.00Comments in declarations
DOC_COMMENT341.00Number of javadoc comment lines
ELOC657.00Effective lines of code
EXEC_COMMENTS29.00Comments in executable code
EXITS186.00Procedure exits
FUNCTIONS61.00Number of function declarations
HALSTEAD_DIFFICULTY107.06Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY170.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 0.00JAVA0008 Empty catch block
JAVA0009 0.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 3.00JAVA0031 Case statement not properly closed
JAVA0032 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 5.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'
JAVA0049 1.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 1.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 1.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
JAVA007638.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 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.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 1.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 1.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 2.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 3.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 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA011611.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 6.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 0.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 1.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
JAVA014513.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 0.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 1.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 0.00JAVA0177 Variable declaration missing initializer
JAVA0179 2.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 1.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 4.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 1.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 2.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 0.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
LINES1388.00Number of lines in the source file
LINE_COMMENT29.00Number of line comments
LOC842.00Lines of code
LOGICAL_LINES404.00Number of statements
LOOPS15.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS2092.00Number of operands
OPERATORS4285.00Number of operators
PARAMS60.00Number of formal parameter declarations
PROGRAM_LENGTH6377.00Halstead program length
PROGRAM_VOCAB657.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS110.00Number of return points from functions
SIZE50139.00Size of the file in bytes
UNIQUE_OPERANDS596.00Number of unique operands
UNIQUE_OPERATORS61.00Number of unique operators
WHITESPACE169.00Number of whitespace lines