Class MarketData

    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • MINIMUM_PRICE

        public static final int MINIMUM_PRICE
        Inclusive lower bound on goods price.
        See Also:
        Constant Field Values
      • MAXIMUM_PRICE

        public static final int MAXIMUM_PRICE
        Inclusive upper bound on goods price.
        See Also:
        Constant Field Values
      • goodsType

        private GoodsType goodsType
        What type of goods is this.
      • costToBuy

        private int costToBuy
        Current purchase price.
      • paidForSale

        private int paidForSale
        Current selling price.
      • amountInMarket

        private int amountInMarket
        Amount of this goods in the market.
      • initialPrice

        private int initialPrice
        The initial price.
      • arrears

        private int arrears
        Arrears owed to the crown.
      • sales

        private int sales
        Total sales.
      • incomeBeforeTaxes

        private int incomeBeforeTaxes
        Total income before taxes.
      • incomeAfterTaxes

        private int incomeAfterTaxes
        Total income after taxes.
      • oldPrice

        private int oldPrice
        Place to save to old price so as to be able to tell when a price change message should be generated. Not necessary to serialize.
      • traded

        private boolean traded
        Has this good been traded?
      • INCOME_AFTER_TAXES_TAG

        private static final java.lang.String INCOME_AFTER_TAXES_TAG
        See Also:
        Constant Field Values
      • INCOME_BEFORE_TAXES_TAG

        private static final java.lang.String INCOME_BEFORE_TAXES_TAG
        See Also:
        Constant Field Values
      • INITIAL_PRICE_TAG

        private static final java.lang.String INITIAL_PRICE_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • MarketData

        public MarketData​(Game game,
                          GoodsType goodsType)
        Creates a new MarketData instance.
        Parameters:
        game - The enclosing Game.
        goodsType - The GoodsType this market data describes.
      • MarketData

        public MarketData​(Game game,
                          java.lang.String id)
        Creates a new MarketData with the given identifier. The object should be initialized later.
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
    • Method Detail

      • getGoodsType

        public final GoodsType getGoodsType()
        Get the type of goods of this MarketData.
        Returns:
        The goods type for this data.
      • getCostToBuy

        public final int getCostToBuy()
        Get the current purchase price.
        Returns:
        The purchase price.
      • setCostToBuy

        public final void setCostToBuy​(int newCostToBuy)
        Set the current purchase price.
        Parameters:
        newCostToBuy - The new purchase price.
      • getPaidForSale

        public final int getPaidForSale()
        Get the current sale price.
        Returns:
        The sale price.
      • setPaidForSale

        public final void setPaidForSale​(int newPaidForSale)
        Set the current sale price.
        Parameters:
        newPaidForSale - The new sale price.
      • getAmountInMarket

        public final int getAmountInMarket()
        Get the amount of the goods type in the market.
        Returns:
        The amount of goods.
      • setAmountInMarket

        public final void setAmountInMarket​(int newAmountInMarket)
        Set the amount of goods in the market.
        Parameters:
        newAmountInMarket - The new amount of goods in the market.
      • getInitialPrice

        public final int getInitialPrice()
        Get the initial price of these goods.
        Returns:
        The initial price.
      • setInitialPrice

        public final void setInitialPrice​(int newInitialPrice)
        Set the initial price value.
        Parameters:
        newInitialPrice - The new initial price value.
      • getArrears

        public final int getArrears()
        Get the amount of arrears owned to the crown for this goods type.
        Returns:
        The arrears amount.
      • setArrears

        public final void setArrears​(int newArrears)
        Set the amount of arrears owed to the crown.
        Parameters:
        newArrears - The new amount of arrears.
      • getSales

        public final int getSales()
        Get the total sales.
        Returns:
        The total sales.
      • setSales

        public final void setSales​(int newSales)
        Set the total sales value.
        Parameters:
        newSales - The new total sales value.
      • getIncomeBeforeTaxes

        public final int getIncomeBeforeTaxes()
        Get the income before taxes from trading in this goods type.
        Returns:
        The income before taxes.
      • setIncomeBeforeTaxes

        public final void setIncomeBeforeTaxes​(int newIncomeBeforeTaxes)
        Set the income before taxes value.
        Parameters:
        newIncomeBeforeTaxes - The new income before taxes value.
      • getIncomeAfterTaxes

        public final int getIncomeAfterTaxes()
        Get the income after taxes from trading in this goods type.
        Returns:
        The income after taxes.
      • setIncomeAfterTaxes

        public final void setIncomeAfterTaxes​(int newIncomeAfterTaxes)
        Set the income after taxes value.
        Parameters:
        newIncomeAfterTaxes - The new income after taxes value.
      • getOldPrice

        public final int getOldPrice()
        Get the old price.
        Returns:
        The old price.
      • setOldPrice

        public void setOldPrice​(int oldPrice)
        Set the old price.
        Parameters:
        oldPrice - A `new' old price.
      • getTraded

        public final boolean getTraded()
        Has there been trading in this MarketData?
        Returns:
        True if trading has occurred.
      • setTraded

        public void setTraded​(boolean traded)
        Set the trading status of this MarketData.
        Parameters:
        traded - The trade status to set.
      • price

        public boolean price()
        Adjust the prices. Sets the costToBuy and paidForSale fields from the amount in the market, initial price and goods-type specific information. Ensures that prices change incrementally with a clamping mechanism.
        Returns:
        True if the price changes.
      • update

        public void update()
        Update the pricing of this datum, ignoring the price change clamp.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class FreeColGameObject
        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.
      • readAttributes

        protected void readAttributes​(FreeColXMLReader xr)
                               throws javax.xml.stream.XMLStreamException
        Reads the attributes of this object from an XML stream.
        Overrides:
        readAttributes in class FreeColGameObject
        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.