Class TradeRoute

    • Field Detail

      • logger

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

        private java.lang.String name
        The name of this trade route.
      • owner

        private Player owner
        The Player who owns this trade route. This is necessary to ensure that malicious clients can not modify the trade routes of other players.
      • stops

        private final java.util.List<TradeRouteStop> stops
        A list of stops.
      • silent

        private boolean silent
        Silence the messaging for this trade route.
    • Constructor Detail

      • TradeRoute

        public TradeRoute​(Game game,
                          java.lang.String name,
                          Player player)
        Creates a new TradeRoute instance.
        Parameters:
        game - The enclosing Game.
        name - The name of the trade route.
        player - The owner Player.
      • TradeRoute

        public TradeRoute​(Game game,
                          java.lang.String id)
        Creates a new TradeRoute instance.
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
    • Method Detail

      • isSilent

        public boolean isSilent()
        Does this trade route generate no messages to the player?
        Returns:
        True if this trade route is silent.
      • setSilent

        public void setSilent​(boolean silent)
        Set the silence status of this trade route.
        Parameters:
        silent - The new silence status of this trade route.
      • getStopCount

        public final int getStopCount()
        Get the number of stops in this trade route.
        Returns:
        The number of stops, or negative on error.
      • getStop

        public final TradeRouteStop getStop​(int index)
        Get a stop in the trade route by index.
        Parameters:
        index - The index to look up.
        Returns:
        The TradeRouteStop found, or null if the index is invalid.
      • getStopList

        public final java.util.List<TradeRouteStop> getStopList()
        Get the stops in this trade route.
        Returns:
        A list of TradeRouteStops.
      • getStopSublist

        public java.util.List<TradeRouteStop> getStopSublist​(TradeRouteStop start,
                                                             TradeRouteStop end)
        Get a list of the trade route stops in this trade route, starting at a given stop (inclusive) and a final stop (exclusive).
        Parameters:
        start - The starting TradeRouteStop.
        end - The end TradeRouteStop.
        Returns:
        A list of stops, or null on error.
      • addStop

        public void addStop​(TradeRouteStop stop)
        Add a new TradeRouteStop to this trade route.
        Parameters:
        stop - The TradeRouteStop to add.
      • removeStop

        public void removeStop​(TradeRouteStop stop)
        Remove a TradeRouteStop from this trade route.
        Parameters:
        stop - The TradeRouteStop to remove.
      • removeMatchingStops

        public boolean removeMatchingStops​(Location loc)
        Remove any stops matching a given location.
        Parameters:
        loc - The Location to match.
        Returns:
        True if any stop was removed.
      • getIndex

        public int getIndex​(TradeRouteStop stop)
        Get the index of a stop in this trade route.
        Parameters:
        stop - The TradeRouteStop to look for.
        Returns:
        The index of the given stop, or negative on failure.
      • clearStops

        public void clearStops()
        Clear the stops in this trade route.
      • getAssignedUnits

        public java.util.List<Unit> getAssignedUnits()
        Get the units assigned to this route.
        Returns:
        A list of assigned Units.
      • isStopValid

        public static boolean isStopValid​(Unit unit,
                                          TradeRouteStop stop)
        Is a stop valid for a given unit?
        Parameters:
        unit - The Unit to check.
        stop - The TradeRouteStop to check.
        Returns:
        True if the stop is valid.
      • isStopValid

        public static boolean isStopValid​(Player player,
                                          TradeRouteStop stop)
        Is a stop valid for a given player?
        Parameters:
        player - The Player to check.
        stop - The TradeRouteStop to check.
        Returns:
        True if the stop is valid.
      • verifyUniqueName

        public StringTemplate verifyUniqueName()
        Check the uniqueness of the trade route name.
        Returns:
        Null if the name is unique, or a StringTemplate containing an error message if not.
      • verify

        public StringTemplate verify()
        Check that the trade route is valid.
        Returns:
        Null if the route is valid, or a StringTemplate explaining the problem if invalid.
      • getName

        public final java.lang.String getName()
        Gets the name of this Nameable.
        Specified by:
        getName in interface Nameable
        Returns:
        The name of the Nameable.
      • setName

        public final void setName​(java.lang.String newName)
        Sets the name for this Nameable.
        Specified by:
        setName in interface Nameable
        Parameters:
        newName - The new name for the Nameable.
      • getOwner

        public final Player getOwner()
        Gets the owner of this Ownable.
        Specified by:
        getOwner in interface Ownable
        Returns:
        The Player controlling this Ownable.
      • setOwner

        public final void setOwner​(Player newOwner)
        Sets the owner of this Ownable.
        Specified by:
        setOwner in interface Ownable
        Parameters:
        newOwner - The Player that should take ownership of this Ownable.
      • 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.
      • 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

        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.