Package net.sf.freecol.common.model
Class ProductionType
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.ProductionType
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public class ProductionType extends FreeColSpecObject
This class describes a possible production type of a tile or building.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.List<AbstractGoods>
EMPTY_LIST
private static java.lang.String
GOODS_TYPE_TAG
private static java.lang.String
INPUT_TAG
private java.util.List<AbstractGoods>
inputs
The goods that are consumed by this production type.private static java.lang.String
OLD_PRODUCTION_LEVEL_TAG
private static java.lang.String
OUTPUT_TAG
private java.util.List<AbstractGoods>
outputs
The goods that are produced by this production type.private static java.lang.String
PRODUCTION_LEVEL_TAG
private java.lang.String
productionLevel
The production level of this production type (usually a difficulty level key).static java.lang.String
TAG
private boolean
unattended
Whether this production type applies only to colony center tiles.private static java.lang.String
UNATTENDED_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 Modifier Constructor Description private
ProductionType(java.util.List<AbstractGoods> outputs)
Creates a new production type that consumes no raw materials and produces the given output.ProductionType(java.util.List<AbstractGoods> inputs, java.util.List<AbstractGoods> outputs)
Creates a new production type that consumes the given raw materials and produces the given output.ProductionType(FreeColXMLReader xr, Specification specification)
Creates a newProductionType
instance.ProductionType(AbstractGoods output, boolean unattended, java.lang.String level)
Convenience constructor for a production type with a single output.ProductionType(GoodsType input, GoodsType output, int amount)
Convenience constructor for a newProductionType
instance with a single input and output.ProductionType(Specification specification)
Simple constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addInput(GoodsType type, int amount)
Add a new input.void
addOutput(AbstractGoods ag)
Add a new output.private void
addOutput(GoodsType type, int amount)
Add a new output.boolean
appliesExactly(java.lang.String level)
Does this production apply exactly to a given difficulty level, that is without using wildcard matches on null.boolean
appliesTo(java.lang.String level)
Does this production apply to a given difficulty level.static boolean
canProduce(GoodsType goodsType, java.util.Collection<ProductionType> types)
Convenience function to check if there is an output for a given goods type in a collection of production types.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.boolean
equals(java.lang.Object o)
private AbstractGoods
getBestOutputFor(GoodsType goodsType)
Get the output the maximizes production for an optional goods type.GoodsType
getBestOutputType()
Get the type of the most productive output.static ProductionType
getBestProductionType(GoodsType goodsType, java.util.Collection<ProductionType> types)
Get the production type with the greatest total output of an optional goods type from a collection of production typesjava.util.List<AbstractGoods>
getInputList()
Get the input goods list.java.util.stream.Stream<AbstractGoods>
getInputs()
Get the input goods as a stream.AbstractGoods
getOutput(GoodsType goodsType)
Get the goods of the given goods type in this production type.java.util.List<AbstractGoods>
getOutputList()
Get the output goods list.java.util.stream.Stream<AbstractGoods>
getOutputs()
Get the output goods as a stream.java.lang.String
getProductionLevel()
The production level of this type of production (used by difficulty levels).boolean
getUnattended()
Get the unattended production state.java.lang.String
getXMLTagName()
Get the serialization tag for this object.int
hashCode()
void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
readChild(FreeColXMLReader xr)
Reads a single child object.void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.void
setInputs(java.util.List<AbstractGoods> newInputs)
Set the input goods.void
setOutputs(java.util.List<AbstractGoods> newOutputs)
Set the output goods.void
setUnattended(boolean unattended)
Set the unattended state of this production.java.lang.String
toString()
protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
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, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, 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
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
EMPTY_LIST
public static final java.util.List<AbstractGoods> EMPTY_LIST
-
unattended
private boolean unattended
Whether this production type applies only to colony center tiles.
-
productionLevel
private java.lang.String productionLevel
The production level of this production type (usually a difficulty level key).
-
outputs
private java.util.List<AbstractGoods> outputs
The goods that are produced by this production type.
-
inputs
private java.util.List<AbstractGoods> inputs
The goods that are consumed by this production type.
-
UNATTENDED_TAG
private static final java.lang.String UNATTENDED_TAG
- See Also:
- Constant Field Values
-
GOODS_TYPE_TAG
private static final java.lang.String GOODS_TYPE_TAG
- See Also:
- Constant Field Values
-
INPUT_TAG
private static final java.lang.String INPUT_TAG
- See Also:
- Constant Field Values
-
OUTPUT_TAG
private static final java.lang.String OUTPUT_TAG
- See Also:
- Constant Field Values
-
PRODUCTION_LEVEL_TAG
private static final java.lang.String PRODUCTION_LEVEL_TAG
- See Also:
- Constant Field Values
-
OLD_PRODUCTION_LEVEL_TAG
private static final java.lang.String OLD_PRODUCTION_LEVEL_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ProductionType
public ProductionType(Specification specification)
Simple constructor.- Parameters:
specification
- TheSpecification
to refer to.
-
ProductionType
private ProductionType(java.util.List<AbstractGoods> outputs)
Creates a new production type that consumes no raw materials and produces the given output.- Parameters:
outputs
- A list of theAbstractGoods
produced.
-
ProductionType
public ProductionType(java.util.List<AbstractGoods> inputs, java.util.List<AbstractGoods> outputs)
Creates a new production type that consumes the given raw materials and produces the given output.- Parameters:
inputs
- A list of theAbstractGoods
consumed.outputs
- A list of theAbstractGoods
produced.
-
ProductionType
public ProductionType(AbstractGoods output, boolean unattended, java.lang.String level)
Convenience constructor for a production type with a single output.- Parameters:
output
- TheAbstractGoods
produced.unattended
- True if this is unattended production.level
- The difficulty level key.
-
ProductionType
public ProductionType(GoodsType input, GoodsType output, int amount)
Convenience constructor for a newProductionType
instance with a single input and output.- Parameters:
input
- TheGoodsType
consumed.output
- TheGoodsType
produced.amount
- The amount of goods both produced and consumed.
-
ProductionType
public ProductionType(FreeColXMLReader xr, Specification specification) throws javax.xml.stream.XMLStreamException
Creates a newProductionType
instance.- Parameters:
xr
- TheFreeColXMLReader
to read from.specification
- TheSpecification
to refer to.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
-
Method Detail
-
getUnattended
public final boolean getUnattended()
Get the unattended production state.- Returns:
- True if this is unattended production.
-
setUnattended
public final void setUnattended(boolean unattended)
Set the unattended state of this production.- Parameters:
unattended
- The new unattended production state.
-
getProductionLevel
public final java.lang.String getProductionLevel()
The production level of this type of production (used by difficulty levels).- Returns:
- The production level key.
-
appliesTo
public boolean appliesTo(java.lang.String level)
Does this production apply to a given difficulty level.- Parameters:
level
- The difficulty level key to check.- Returns:
- True if this production applies.
-
appliesExactly
public boolean appliesExactly(java.lang.String level)
Does this production apply exactly to a given difficulty level, that is without using wildcard matches on null.- Parameters:
level
- The difficulty level key to check.- Returns:
- True if this production applies.
-
getInputList
public final java.util.List<AbstractGoods> getInputList()
Get the input goods list.- Returns:
- A list of the input
AbstractGoods
.
-
getInputs
public final java.util.stream.Stream<AbstractGoods> getInputs()
Get the input goods as a stream.- Returns:
- A stream of the input
AbstractGoods
.
-
setInputs
public final void setInputs(java.util.List<AbstractGoods> newInputs)
Set the input goods.- Parameters:
newInputs
- The new list of inputAbstractGoods
.
-
addInput
private void addInput(GoodsType type, int amount)
Add a new input.- Parameters:
type
- TheGoodsType
to add.amount
- The amount of goods.
-
getOutputList
public final java.util.List<AbstractGoods> getOutputList()
Get the output goods list.- Returns:
- A list of the output
AbstractGoods
.
-
getOutputs
public final java.util.stream.Stream<AbstractGoods> getOutputs()
Get the output goods as a stream.- Returns:
- A stream of the output
AbstractGoods
.
-
setOutputs
public final void setOutputs(java.util.List<AbstractGoods> newOutputs)
Set the output goods.- Parameters:
newOutputs
- The new list of outputAbstractGoods
.
-
addOutput
private void addOutput(GoodsType type, int amount)
Add a new output.- Parameters:
type
- TheGoodsType
to add.amount
- The amount of goods.
-
addOutput
public void addOutput(AbstractGoods ag)
Add a new output.- Parameters:
ag
- TheAbstractGoods
to add.
-
getOutput
public AbstractGoods getOutput(GoodsType goodsType)
Get the goods of the given goods type in this production type.- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- The
AbstractGoods
output if any, otherwise null.
-
getBestOutputType
public GoodsType getBestOutputType()
Get the type of the most productive output.- Returns:
- The
GoodsType
of the most productive output.
-
canProduce
public static boolean canProduce(GoodsType goodsType, java.util.Collection<ProductionType> types)
Convenience function to check if there is an output for a given goods type in a collection of production types.- Parameters:
goodsType
- TheGoodsType
to use.types
- A list ofProductionType
s to consider.- Returns:
- The most productive output that produces the goods type, or null if none found.
-
getBestProductionType
public static ProductionType getBestProductionType(GoodsType goodsType, java.util.Collection<ProductionType> types)
Get the production type with the greatest total output of an optional goods type from a collection of production types- Parameters:
goodsType
- An optionalGoodsType
to restrict the choice of outputs with.types
- A collection ofProductionType
s to consider.- Returns:
- The most productive
ProductionType
.
-
getBestOutputFor
private AbstractGoods getBestOutputFor(GoodsType goodsType)
Get the output the maximizes production for an optional goods type.- Parameters:
goodsType
- The optionalGoodsType
to check.- Returns:
- The best production.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColSpecObject
- Type Parameters:
T
- TheFreeColObject
subclass 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:
writeAttributes
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to 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:
writeChildren
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
public void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChildren
public void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChild
public 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:
readChild
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classFreeColObject
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classFreeColObject
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-