Class NativeTradeItem

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, ObjectWithId

    public class NativeTradeItem
    extends GoodsTradeItem
    A trade item consisting of some goods to be traded with the natives. Therefore we include the current valuation and the haggle count.
    • Field Detail

      • descendingPriceComparator

        public static final java.util.Comparator<NativeTradeItem> descendingPriceComparator
        Compare the trade item price.
      • PRICE_UNSET

        public static final int PRICE_UNSET
        Magic number to denote that the price has not been initialized.
        See Also:
        Constant Field Values
      • PRICE_INVALID

        public static final int PRICE_INVALID
        Magic number for price to denote an invalid item.
        See Also:
        Constant Field Values
      • price

        private int price
        The current valuation by the natives.
      • haggleCount

        private int haggleCount
        The number of haggling rounds.
      • HAGGLE_COUNT_TAG

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

      • NativeTradeItem

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

        public NativeTradeItem​(NativeTradeItem nti)
        Copy a new NativeTradeItem instance. Used by readList.
        Parameters:
        nti - The NativeTradeItem to copy.
      • NativeTradeItem

        public NativeTradeItem​(Game game,
                               FreeColXMLReader xr)
                        throws javax.xml.stream.XMLStreamException
        Creates a new NativeTradeItem 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

      • priceIsSet

        public boolean priceIsSet()
        Has a price been set for this item?
        Returns:
        True if a price has been set.
      • priceIsValid

        public boolean priceIsValid()
        Is the price valid for trade.
        Returns:
        True if the price is positive.
      • getPrice

        public int getPrice()
        Get the price for this item.
        Returns:
        The current price.
      • setPrice

        public void setPrice​(int price)
        Set the price for this item.
        Parameters:
        price - The new price.
      • getHaggleCount

        public int getHaggleCount()
        Get the haggle count for this item.
        Returns:
        The current haggle count.
      • setHaggleCount

        public void setHaggleCount​(int haggleCount)
        Set the haggle count for this item.
        Parameters:
        haggleCount - The new haggle count.
      • goodsMatcher

        public java.util.function.Predicate<NativeTradeItem> goodsMatcher()
        Get a predicate to match this native trade item by its goods.
        Returns:
        A suitable Predicate.
      • copyIn

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

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