Class GoodsTradeItem

    • Field Detail

      • goods

        protected Goods goods
        The goods to change hands.
    • Constructor Detail

      • GoodsTradeItem

        public GoodsTradeItem​(Game game,
                              Player source,
                              Player destination,
                              Goods goods)
        Creates a new GoodsTradeItem instance.
        Parameters:
        game - The enclosing Game.
        source - The source Player.
        destination - The destination Player.
        goods - The Goods to trade.
      • GoodsTradeItem

        public GoodsTradeItem​(Game game,
                              FreeColXMLReader xr)
                       throws javax.xml.stream.XMLStreamException
        Creates a new GoodsTradeItem instance.
        Parameters:
        game - The enclosing Game.
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is an error reading the stream.
    • Method Detail

      • isValid

        public boolean isValid()
        Is this trade item valid? That is, is the request well formed.
        Specified by:
        isValid in class TradeItem
        Returns:
        True if the item is valid.
      • isUnique

        public boolean isUnique()
        Is this trade item unique? This is true for the StanceTradeItem and the GoldTradeItem, and false for all others.
        Specified by:
        isUnique in class TradeItem
        Returns:
        True if the item is unique.
      • getLabel

        public StringTemplate getLabel()
        Get a label for this item.
        Specified by:
        getLabel in class TradeItem
        Returns:
        A StringTemplate describing this item.
      • getGoods

        public Goods getGoods()
        Get the goods to trade.
        Overrides:
        getGoods in class TradeItem
        Returns:
        The Goods to trade.
      • setGoods

        public void setGoods​(Goods goods)
        Set the goods to trade.
        Overrides:
        setGoods in class TradeItem
        Parameters:
        goods - The new Goods to trade.
      • evaluateFor

        public int evaluateFor​(Player player)
        Evaluate this trade item for a given player.
        Specified by:
        evaluateFor in class TradeItem
        Parameters:
        player - The Player to evaluate for.
        Returns:
        A value for the player, INVALID_TRADE_ITEM for invalid.
      • 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.
      • readChildren

        protected 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

        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:
        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.
      • copyIn

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

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class TradeItem