Class TradeRouteStop

    • Field Detail

      • logger

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

        private Location location
        The trade location of the stop.
      • cargo

        private final java.util.List<GoodsType> cargo
        The cargo expected to be on board on leaving the stop.
    • Constructor Detail

      • TradeRouteStop

        public TradeRouteStop​(Game game)
        Create an empty trade route stop.
        Parameters:
        game - The enclosing Game.
      • TradeRouteStop

        public TradeRouteStop​(Game game,
                              Location location)
        Create a stop for the given location from a stream.
        Parameters:
        game - The enclosing Game.
        location - The Location of this stop.
      • TradeRouteStop

        public TradeRouteStop​(TradeRouteStop other)
        Copy constructor. Creates a stop based on the given one.
        Parameters:
        other - The other TradeRouteStop.
      • TradeRouteStop

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

      • getLocation

        public final Location getLocation()
        Get the location of this stop.
        Returns:
        The Location of this stop.
      • getTradeLocation

        public TradeLocation getTradeLocation()
        Get the location of this stop as a TradeLocation.
        Returns:
        The TradeLocation for this stop.
      • isValid

        public boolean isValid​(Player player)
        Is this stop valid?
        Parameters:
        player - The Player that owns this route.
        Returns:
        True if the stop is valid.
      • getCargo

        public final java.util.List<GoodsType> getCargo()
        Get the current cargo for this stop.
        Returns:
        A list of cargo GoodsTypes.
      • setCargo

        public final void setCargo​(java.util.List<GoodsType> newCargo)
        Set the cargo value.
        Parameters:
        newCargo - A list of GoodsType defining the cargo.
      • addCargo

        public void addCargo​(GoodsType newCargo)
        Add cargo to this stop.
        Parameters:
        newCargo - The GoodsType to add.
      • getCompactCargo

        public java.util.List<AbstractGoods> getCompactCargo()
        Get a list of the maximum abstract goods that could be loaded at this stop. That is, a list of all the cargo goods types normally with amount equal to one CARGO_SIZE, but with duplicates removed and amounts accumulated.
        Returns:
        A list of AbstractGoods to load.
      • getLabelFor

        public StringTemplate getLabelFor​(java.lang.String key,
                                          Player player)
        Create a template for this trade route stop.
        Parameters:
        key - A message key.
        player - The Player who will see the message.
        Returns:
        A StringTemplate for this stop.
      • invalidStopLabel

        public StringTemplate invalidStopLabel​(Player player)
        Create an invalid trade route stop label.
        Parameters:
        player - The Player who will see the message.
        Returns:
        A StringTemplate for this stop.
      • hasWork

        public boolean hasWork​(Unit unit,
                               int turns)
        Is there work for a unit to do at this stop?
        Parameters:
        unit - The Unit to test.
        turns - Account for production from this many turns.
        Returns:
        True if this unit should load or unload cargo at the stop.
      • getAvailableGoodsCount

        public int getAvailableGoodsCount​(GoodsType goodsType)
        Get the amount of a given goods type at this trade location.
        Specified by:
        getAvailableGoodsCount in interface TradeLocation
        Parameters:
        goodsType - The GoodsType to check.
        Returns:
        The amount of goods present.
      • getExportAmount

        public int getExportAmount​(GoodsType goodsType,
                                   int turns)
        Gets the amount of a given goods type that can be exported from this trade location after a given number of turns.
        Specified by:
        getExportAmount in interface TradeLocation
        Parameters:
        goodsType - The GoodsType to check.
        turns - The number of turns before the goods is required.
        Returns:
        The amount of goods to export.
      • getImportAmount

        public int getImportAmount​(GoodsType goodsType,
                                   int turns)
        Gets the amount of a given goods type that can be imported to this trade location after a given number of turns.
        Specified by:
        getImportAmount in interface TradeLocation
        Parameters:
        goodsType - The GoodsType to check.
        turns - The number of turns before the goods will arrive.
        Returns:
        The amount of goods to import.
      • getLocationName

        public java.lang.String getLocationName​(TradeLocation tradeLocation)
        Function for returning the name of a TradeLocation
        Specified by:
        getLocationName in interface TradeLocation
        Parameters:
        tradeLocation - The TradeLocation to return the name.
        Returns:
        The name.
      • isInternable

        public boolean isInternable()
        Should this object be interned into its Game? Usually true, but there are some special containers that have to be FCGOs but are unsuitable to be interned. These classes will override this routine.
        Overrides:
        isInternable in class FreeColGameObject
        Returns:
        True if this object should be interned.
      • 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

        public 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

        public 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

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