Class ProductionType

    • Field Detail

      • 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.
      • 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 - The Specification 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 the AbstractGoods 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 the AbstractGoods consumed.
        outputs - A list of the AbstractGoods produced.
      • ProductionType

        public ProductionType​(AbstractGoods output,
                              boolean unattended,
                              java.lang.String level)
        Convenience constructor for a production type with a single output.
        Parameters:
        output - The AbstractGoods 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 new ProductionType instance with a single input and output.
        Parameters:
        input - The GoodsType consumed.
        output - The GoodsType produced.
        amount - The amount of goods both produced and consumed.
      • ProductionType

        public ProductionType​(FreeColXMLReader xr,
                              Specification specification)
                       throws javax.xml.stream.XMLStreamException
        Creates a new ProductionType instance.
        Parameters:
        xr - The FreeColXMLReader to read from.
        specification - The Specification 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 input AbstractGoods.
      • addInput

        private void addInput​(GoodsType type,
                              int amount)
        Add a new input.
        Parameters:
        type - The GoodsType 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 output AbstractGoods.
      • addOutput

        private void addOutput​(GoodsType type,
                               int amount)
        Add a new output.
        Parameters:
        type - The GoodsType to add.
        amount - The amount of goods.
      • addOutput

        public void addOutput​(AbstractGoods ag)
        Add a new output.
        Parameters:
        ag - The AbstractGoods to add.
      • getOutput

        public AbstractGoods getOutput​(GoodsType goodsType)
        Get the goods of the given goods type in this production type.
        Parameters:
        goodsType - The GoodsType 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 - The GoodsType to use.
        types - A list of ProductionTypes 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 optional GoodsType to restrict the choice of outputs with.
        types - A collection of ProductionTypes 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 optional GoodsType 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 class FreeColSpecObject
        Type Parameters:
        T - The FreeColObject 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 class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter 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 class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Returns:
        The tag.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class FreeColObject