Package net.sf.freecol.common.model
Class TradeRoute
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.TradeRoute
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Nameable
,Ownable
,ObjectWithId
public class TradeRoute extends FreeColGameObject implements Nameable, Ownable
A TradeRoute holds all information for a unit to follow along a trade route.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Logger
logger
private java.lang.String
name
The name of this trade route.private static java.lang.String
NAME_TAG
private Player
owner
ThePlayer
who owns this trade route.private static java.lang.String
OWNER_TAG
private boolean
silent
Silence the messaging for this trade route.private static java.lang.String
SILENT_TAG
private java.util.List<TradeRouteStop>
stops
A list of stops.static java.lang.String
TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description TradeRoute(Game game, java.lang.String id)
Creates a newTradeRoute
instance.TradeRoute(Game game, java.lang.String name, Player player)
Creates a newTradeRoute
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addStop(TradeRouteStop stop)
Add a newTradeRouteStop
to this trade route.Constants.IntegrityType
checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.void
clearStops()
Clear the stops in this trade route.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.java.util.List<Unit>
getAssignedUnits()
Get the units assigned to this route.int
getIndex(TradeRouteStop stop)
Get the index of a stop in this trade route.java.lang.String
getName()
Gets the name of thisNameable
.Player
getOwner()
Gets the owner of thisOwnable
.TradeRouteStop
getStop(int index)
Get a stop in the trade route by index.int
getStopCount()
Get the number of stops in this trade route.java.util.List<TradeRouteStop>
getStopList()
Get the stops in this trade route.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).java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
isSilent()
Does this trade route generate no messages to the player?static boolean
isStopValid(Player player, TradeRouteStop stop)
Is a stop valid for a given player?static boolean
isStopValid(Unit unit, TradeRouteStop stop)
Is a stop valid for a given unit?protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.boolean
removeMatchingStops(Location loc)
Remove any stops matching a given location.void
removeStop(TradeRouteStop stop)
Remove aTradeRouteStop
from this trade route.void
setName(java.lang.String newName)
Sets the name for thisNameable
.void
setOwner(Player newOwner)
Sets the owner of thisOwnable
.void
setSilent(boolean silent)
Set the silence status of this trade route.java.lang.String
toString()
StringTemplate
verify()
Check that the trade route is valid.StringTemplate
verifyUniqueName()
Check the uniqueness of the trade route name.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, disposeResources, equals, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, getSpecification, hashCode, intern, internId, isDisposed, isInitialized, isInternable, readFromXML, setGame, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
name
private java.lang.String name
The name of this trade route.
-
owner
private Player owner
ThePlayer
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.
-
NAME_TAG
private static final java.lang.String NAME_TAG
- See Also:
- Constant Field Values
-
OWNER_TAG
private static final java.lang.String OWNER_TAG
- See Also:
- Constant Field Values
-
SILENT_TAG
private static final java.lang.String SILENT_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TradeRoute
public TradeRoute(Game game, java.lang.String name, Player player)
Creates a newTradeRoute
instance.- Parameters:
game
- The enclosingGame
.name
- The name of the trade route.player
- The ownerPlayer
.
-
TradeRoute
public TradeRoute(Game game, java.lang.String id)
Creates a newTradeRoute
instance.- Parameters:
game
- The enclosingGame
.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
TradeRouteStop
s.
-
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 startingTradeRouteStop
.end
- The endTradeRouteStop
.- Returns:
- A list of stops, or null on error.
-
addStop
public void addStop(TradeRouteStop stop)
Add a newTradeRouteStop
to this trade route.- Parameters:
stop
- TheTradeRouteStop
to add.
-
removeStop
public void removeStop(TradeRouteStop stop)
Remove aTradeRouteStop
from this trade route.- Parameters:
stop
- TheTradeRouteStop
to remove.
-
removeMatchingStops
public boolean removeMatchingStops(Location loc)
Remove any stops matching a given location.- Parameters:
loc
- TheLocation
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
- TheTradeRouteStop
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
Unit
s.
-
isStopValid
public static boolean isStopValid(Unit unit, TradeRouteStop stop)
Is a stop valid for a given unit?- Parameters:
unit
- TheUnit
to check.stop
- TheTradeRouteStop
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
- ThePlayer
to check.stop
- TheTradeRouteStop
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 thisNameable
.
-
setName
public final void setName(java.lang.String newName)
Sets the name for thisNameable
.
-
getOwner
public final Player getOwner()
Gets the owner of thisOwnable
.
-
setOwner
public final void setOwner(Player newOwner)
Sets the owner of thisOwnable
.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.- Overrides:
checkIntegrity
in classFreeColGameObject
- Parameters:
fix
- If true, fix problems if possible.lb
- ALogBuilder
to log to.- Returns:
- A suitable
IntegrityType
.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColGameObject
- Type Parameters:
T
- TheFreeColObject
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColGameObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-