Package net.sf.freecol.common.model
Class BuildableType
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.FreeColSpecObjectType
-
- net.sf.freecol.common.model.BuildableType
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,Named,ObjectWithId
- Direct Known Subclasses:
BuildingType,Role,UnitType
public abstract class BuildableType extends FreeColSpecObjectType
Contains information on buildable types.
-
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_REQUIRED_POPULATIONThe required population for an ordinary buildable.private java.util.List<Limit>limitsLimits on the production of this type.private static java.lang.StringREQUIRED_ABILITY_TAGprivate static java.lang.StringREQUIRED_GOODS_TAGstatic java.lang.StringREQUIRED_POPULATION_TAGprivate java.util.Map<java.lang.String,java.lang.Boolean>requiredAbilitiesStores the abilities required by this Type.private java.util.List<AbstractGoods>requiredGoodsA list of AbstractGoods required to build this type.private intrequiredPopulationThe minimum population that a Colony needs in order to build this type.-
Fields inherited from class net.sf.freecol.common.model.FreeColSpecObjectType
DELETE_TAG, EXTENDS_TAG, PRESERVE_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description BuildableType(java.lang.String id, Specification specification)Creates a new buildable type.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidaddLimit(Limit limit)Add a new limit.voidaddRequiredAbility(java.lang.String tag, boolean value)Add a new required ability.private voidaddRequiredGoods(AbstractGoods ag)Add a new goods requirement.abstract Colony.NoBuildReasoncanBeBuiltInColony(Colony colony, java.util.List<BuildableType> assumeBuilt)Check to see if this buildable type can be built in a colony based on the buildings or units available.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.StringTemplategetCurrentlyBuildingLabel()Get a label describing this buildable type as being currently built.java.util.List<Limit>getLimits()Get the limits on this buildable.intgetMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)intgetMinimumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)java.util.Map<java.lang.String,java.lang.Boolean>getRequiredAbilities()Gets the abilities required by this type.intgetRequiredAmountOf(GoodsType type)Get the amount required of a givenGoodsTypeto build an instance of this buildable.java.util.stream.Stream<AbstractGoods>getRequiredGoods()Get the goods required to build an instance of this buildable as a stream.java.util.List<AbstractGoods>getRequiredGoodsList()Get the goods required to build an instance of this buildable.intgetRequiredPopulation()Get the population required to build this buildable type.booleanisAvailableTo(FreeColObject... fco)Is this buildable available to a given FreeColObject?booleanneedsGoodsToBuild()Does this buildable need goods to build?protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.voidremoveRequiredAbility(java.lang.String tag)Remove a required ability.booleanrequiresAbility(java.lang.String key)voidsetLimits(java.util.List<Limit> newLimits)Set the limits on this buildable.voidsetRequiredAbilities(java.util.Map<java.lang.String,java.lang.Boolean> abilities)Sets the abilities required by this type.voidsetRequiredGoods(java.util.List<AbstractGoods> goods)Set the goods required to build an instance of this buildable.voidsetRequiredPopulation(int newPopulation)Set the population required to build this buildable type.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(FreeColXMLWriter xw)Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObjectType
addScope, appliesTo, copyScopes, getDescriptionKey, getFeatureContainer, getIndex, getNameKey, getScopeList, getScopes, isAbstractType, removeScope, setIndex, toString
-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObject
getSpecification, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, getXMLTagName, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
DEFAULT_REQUIRED_POPULATION
private static final int DEFAULT_REQUIRED_POPULATION
The required population for an ordinary buildable.- See Also:
- Constant Field Values
-
requiredPopulation
private int requiredPopulation
The minimum population that a Colony needs in order to build this type.
-
requiredAbilities
private java.util.Map<java.lang.String,java.lang.Boolean> requiredAbilities
Stores the abilities required by this Type.
-
requiredGoods
private java.util.List<AbstractGoods> requiredGoods
A list of AbstractGoods required to build this type.
-
limits
private java.util.List<Limit> limits
Limits on the production of this type.
-
REQUIRED_ABILITY_TAG
private static final java.lang.String REQUIRED_ABILITY_TAG
- See Also:
- Constant Field Values
-
REQUIRED_GOODS_TAG
private static final java.lang.String REQUIRED_GOODS_TAG
- See Also:
- Constant Field Values
-
REQUIRED_POPULATION_TAG
public static final java.lang.String REQUIRED_POPULATION_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BuildableType
public BuildableType(java.lang.String id, Specification specification)Creates a new buildable type.- Parameters:
id- The object identifier.specification- TheSpecificationto refer to.
-
-
Method Detail
-
getRequiredPopulation
public int getRequiredPopulation()
Get the population required to build this buildable type.- Returns:
- The population required.
-
setRequiredPopulation
public void setRequiredPopulation(int newPopulation)
Set the population required to build this buildable type.- Parameters:
newPopulation- The new population required.
-
getRequiredAbilities
public java.util.Map<java.lang.String,java.lang.Boolean> getRequiredAbilities()
Gets the abilities required by this type.- Returns:
- A copy of the required abilities map.
-
requiresAbility
public boolean requiresAbility(java.lang.String key)
-
setRequiredAbilities
public void setRequiredAbilities(java.util.Map<java.lang.String,java.lang.Boolean> abilities)
Sets the abilities required by this type.- Parameters:
abilities- The new required abilities.
-
addRequiredAbility
public void addRequiredAbility(java.lang.String tag, boolean value)Add a new required ability. Public for specification fixes.- Parameters:
tag- The ability name.value- The ability value.
-
removeRequiredAbility
public void removeRequiredAbility(java.lang.String tag)
Remove a required ability. Public for specification fixes.- Parameters:
tag- The ability name to remove.
-
isAvailableTo
public boolean isAvailableTo(FreeColObject... fco)
Is this buildable available to a given FreeColObject?- Parameters:
fco- TheFreeColObjects to check.- Returns:
- True if the buildable is available.
-
getRequiredGoodsList
public java.util.List<AbstractGoods> getRequiredGoodsList()
Get the goods required to build an instance of this buildable. Note we must take care to return a deep copy, as these lists are subject to complex manipulations in the role code.- Returns:
- A deep copy of the list of required goods.
-
getRequiredGoods
public java.util.stream.Stream<AbstractGoods> getRequiredGoods()
Get the goods required to build an instance of this buildable as a stream.- Returns:
- A stream of the required goods.
-
setRequiredGoods
public void setRequiredGoods(java.util.List<AbstractGoods> goods)
Set the goods required to build an instance of this buildable.- Parameters:
goods- The new required goods.
-
getRequiredAmountOf
public int getRequiredAmountOf(GoodsType type)
Get the amount required of a givenGoodsTypeto build an instance of this buildable.- Parameters:
type- TheGoodsTypeto check.- Returns:
- The amount of goods required.
-
addRequiredGoods
private void addRequiredGoods(AbstractGoods ag)
Add a new goods requirement.- Parameters:
ag- The requiredAbstractGoodsto add.
-
needsGoodsToBuild
public boolean needsGoodsToBuild()
Does this buildable need goods to build?- Returns:
- True if goods are required to build this buildable.
-
getLimits
public java.util.List<Limit> getLimits()
Get the limits on this buildable.- Returns:
- A list of
Limits.
-
setLimits
public void setLimits(java.util.List<Limit> newLimits)
Set the limits on this buildable.- Parameters:
newLimits- The newLimitsvalue.
-
addLimit
private void addLimit(Limit limit)
Add a new limit.- Parameters:
limit- TheLimitto add.
-
getCurrentlyBuildingLabel
public StringTemplate getCurrentlyBuildingLabel()
Get a label describing this buildable type as being currently built.- Returns:
- A suitable label.
-
canBeBuiltInColony
public abstract Colony.NoBuildReason canBeBuiltInColony(Colony colony, java.util.List<BuildableType> assumeBuilt)
Check to see if this buildable type can be built in a colony based on the buildings or units available.- Parameters:
colony- TheColonyto check.assumeBuilt- A list ofBuildableTypes.- Returns:
- The reason the for failure, or NoBuildReason.NONE on success.
-
getMinimumIndex
public int getMinimumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
-
getMaximumIndex
public int getMaximumIndex(Colony colony, javax.swing.JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD)
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classFreeColSpecObjectType- Type Parameters:
T- TheFreeColObjectsubclass of the object to copy in.- Parameters:
other- The other object.- Returns:
- True if the copy in is succesful.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributesin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto write to.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildrenin classFreeColSpecObjectType- Parameters:
xw- TheFreeColXMLWriterto write to.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributesin classFreeColSpecObjectType- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildrenin classFreeColSpecObjectType- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
readChild
protected void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChildin classFreeColSpecObjectType- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
-