net.sf.freecol.common.model
Class TradeRoute

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObject
          extended by net.sf.freecol.common.model.TradeRoute
All Implemented Interfaces:
java.lang.Cloneable, Ownable

public class TradeRoute
extends FreeColGameObject
implements java.lang.Cloneable, Ownable

A TradeRoute holds all information for a unit to follow along a trade route.


Nested Class Summary
 class TradeRoute.Stop
           
 
Field Summary
private static java.lang.String CARGO_TAG
           
private  int count
          The number of carriers using this route.
private static java.util.logging.Logger logger
           
private  boolean modified
          Whether the trade route has been modified.
private  java.lang.String name
          The name of this trade route.
private  Player owner
          The Player who owns this trade route.
private  java.util.List<TradeRoute.Stop> stops
          A list of stops.
 
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
UNITS_TAG_NAME
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
TradeRoute(Game game, org.w3c.dom.Element e)
          Creates a new TradeRoute instance.
TradeRoute(Game game, java.lang.String name, Player player)
          Creates a new TradeRoute instance.
TradeRoute(Game game, javax.xml.stream.XMLStreamReader in)
          Creates a new TradeRoute instance.
 
Method Summary
 void addStop(TradeRoute.Stop stop)
          Add a new Stop to this trade route.
 TradeRoute clone()
          Clone the trade route and return a deep copy.
private  Location findLocation(Game game, java.lang.String id)
          Nasty hack to find the stop location.
 java.util.List<Unit> getAssignedUnits()
           
 int getCount()
          Get the Count value.
 java.lang.String getName()
          Get the Name value.
 Player getOwner()
          Get the Owner value.
 java.util.List<TradeRoute.Stop> getStops()
          Get the Stops value.
static java.lang.String getStopXMLElementTagName()
          Returns the tag name of the root element representing this object.
static java.lang.String getXMLElementTagName()
          Returns the tag name of the root element representing this object.
 boolean isModified()
          Get the Modified value.
static boolean isStopValid(Player player, TradeRoute.Stop stop)
           
static boolean isStopValid(Unit unit, TradeRoute.Stop stop)
           
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
private  void replaceStops(java.util.List<TradeRoute.Stop> otherStops)
          Replace all the stops for this trade route with the stops passed from another trade route.
 void setCount(int newCount)
          Set the Count value.
 void setModified(boolean newModified)
          Set the Modified value.
 void setName(java.lang.String newName)
          Set the Name value.
 void setOwner(Player newOwner)
          Set the Owner value.
 void setStops(java.util.List<TradeRoute.Stop> newStops)
          Set the Stops value.
 java.lang.String toString()
          Gets a string representation of the object.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          This method writes an XML-representation of this object to the given stream.
 void updateFrom(TradeRoute other)
          Copy all fields from another trade route to this one.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, disposeList, equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

CARGO_TAG

private static final java.lang.String CARGO_TAG
See Also:
Constant Field Values

name

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


count

private int count
The number of carriers using this route. (Only used in TradeRouteDialog for the present)


modified

private boolean modified
Whether the trade route has been modified. This is of interest only to the client and can be ignored for XML serialization.


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 java.util.List<TradeRoute.Stop> stops
A list of stops.

Constructor Detail

TradeRoute

public TradeRoute(Game game,
                  java.lang.String name,
                  Player player)
Creates a new TradeRoute instance.

Parameters:
game - a Game value
name - a String value
player - a Player value

TradeRoute

public TradeRoute(Game game,
                  javax.xml.stream.XMLStreamReader in)
           throws javax.xml.stream.XMLStreamException
Creates a new TradeRoute instance.

Parameters:
game - a Game value
in - a XMLStreamReader value
Throws:
javax.xml.stream.XMLStreamException - if an error occurs

TradeRoute

public TradeRoute(Game game,
                  org.w3c.dom.Element e)
Creates a new TradeRoute instance.

Parameters:
game - a Game value
e - an Element value
Method Detail

updateFrom

public void updateFrom(TradeRoute other)
Copy all fields from another trade route to this one. This is useful when an updated route is received on the server side from the client.

Parameters:
other - The route to copy from.

isModified

public final boolean isModified()
Get the Modified value.

Returns:
a boolean value

setModified

public final void setModified(boolean newModified)
Set the Modified value.

Parameters:
newModified - The new Modified value.

getName

public final java.lang.String getName()
Get the Name value.

Returns:
a String value

setName

public final void setName(java.lang.String newName)
Set the Name value.

Parameters:
newName - The new Name value.

getCount

public int getCount()
Get the Count value.

Returns:
The count of trade route users.

setCount

public void setCount(int newCount)
Set the Count value.

Parameters:
newCount - The new Count value.

addStop

public void addStop(TradeRoute.Stop stop)
Add a new Stop to this trade route.

Parameters:
stop - The Stop to add.

getOwner

public final Player getOwner()
Get the Owner value.

Specified by:
getOwner in interface Ownable
Returns:
a Player value

setOwner

public final void setOwner(Player newOwner)
Set the Owner value.

Specified by:
setOwner in interface Ownable
Parameters:
newOwner - The new Owner value.

getAssignedUnits

public java.util.List<Unit> getAssignedUnits()

getStops

public final java.util.List<TradeRoute.Stop> getStops()
Get the Stops value.

Returns:
an ArrayList value

setStops

public final void setStops(java.util.List<TradeRoute.Stop> newStops)
Set the Stops value.

Parameters:
newStops - The new Stops value.

clone

public TradeRoute clone()
Clone the trade route and return a deep copy.

The copied trade route has no reference back to the original and can safely be used as a temporary copy. It is NOT registered with the game, but will have the same unique id as the original.

Overrides:
clone in class java.lang.Object
Returns:
deep copy of trade route.

replaceStops

private void replaceStops(java.util.List<TradeRoute.Stop> otherStops)
Replace all the stops for this trade route with the stops passed from another trade route. This method will create a deep copy as it creates new stops based on the given ones.

Parameters:
otherStops - The new stops to use.
See Also:
clone()

isStopValid

public static boolean isStopValid(Unit unit,
                                  TradeRoute.Stop stop)

isStopValid

public static boolean isStopValid(Player player,
                                  TradeRoute.Stop stop)

getStopXMLElementTagName

public static java.lang.String getStopXMLElementTagName()
Returns the tag name of the root element representing this object.

Returns:
"tradeRouteStop".

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
                         Player player,
                         boolean showAll,
                         boolean toSavedGame)
                  throws javax.xml.stream.XMLStreamException
Description copied from class: FreeColGameObject
This method writes an XML-representation of this object to the given stream.

Only attributes visible to the given Player will be added to that representation if showAll is set to false.

Specified by:
toXMLImpl in class FreeColGameObject
Parameters:
out - The target stream.
player - The Player this XML-representation should be made for, or null if showAll == true.
showAll - Only attributes visible to player will be added to the representation if showAll is set to false.
toSavedGame - If true then information that is only needed when saving a game is added.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

findLocation

private Location findLocation(Game game,
                              java.lang.String id)
Nasty hack to find the stop location. Trade routes tend to precede the map so colonies are not yet defined when trade routes are read.


readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

toString

public java.lang.String toString()
Description copied from class: FreeColGameObject
Gets a string representation of the object.

Overrides:
toString in class FreeColGameObject
Returns:
A string representation of the object.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Returns the tag name of the root element representing this object.

Returns:
"tradeRoute".