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.Loggerloggerprivate java.lang.StringnameThe name of this trade route.private static java.lang.StringNAME_TAGprivate PlayerownerThePlayerwho owns this trade route.private static java.lang.StringOWNER_TAGprivate booleansilentSilence the messaging for this trade route.private static java.lang.StringSILENT_TAGprivate java.util.List<TradeRouteStop>stopsA list of stops.static java.lang.StringTAG-
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 newTradeRouteinstance.TradeRoute(Game game, java.lang.String name, Player player)Creates a newTradeRouteinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddStop(TradeRouteStop stop)Add a newTradeRouteStopto this trade route.Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)Checks the integrity of this game object.voidclearStops()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.intgetIndex(TradeRouteStop stop)Get the index of a stop in this trade route.java.lang.StringgetName()Gets the name of thisNameable.PlayergetOwner()Gets the owner of thisOwnable.TradeRouteStopgetStop(int index)Get a stop in the trade route by index.intgetStopCount()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.StringgetXMLTagName()Get the serialization tag for this object.booleanisSilent()Does this trade route generate no messages to the player?static booleanisStopValid(Player player, TradeRouteStop stop)Is a stop valid for a given player?static booleanisStopValid(Unit unit, TradeRouteStop stop)Is a stop valid for a given unit?protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.booleanremoveMatchingStops(Location loc)Remove any stops matching a given location.voidremoveStop(TradeRouteStop stop)Remove aTradeRouteStopfrom this trade route.voidsetName(java.lang.String newName)Sets the name for thisNameable.voidsetOwner(Player newOwner)Sets the owner of thisOwnable.voidsetSilent(boolean silent)Set the silence status of this trade route.java.lang.StringtoString()StringTemplateverify()Check that the trade route is valid.StringTemplateverifyUniqueName()Check the uniqueness of the trade route name.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(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
ThePlayerwho 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 newTradeRouteinstance.- 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 newTradeRouteinstance.- 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
TradeRouteStopfound, 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 startingTradeRouteStop.end- The endTradeRouteStop.- Returns:
- A list of stops, or null on error.
-
addStop
public void addStop(TradeRouteStop stop)
Add a newTradeRouteStopto this trade route.- Parameters:
stop- TheTradeRouteStopto add.
-
removeStop
public void removeStop(TradeRouteStop stop)
Remove aTradeRouteStopfrom this trade route.- Parameters:
stop- TheTradeRouteStopto remove.
-
removeMatchingStops
public boolean removeMatchingStops(Location loc)
Remove any stops matching a given location.- Parameters:
loc- TheLocationto 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- TheTradeRouteStopto 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- TheUnitto check.stop- TheTradeRouteStopto 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- ThePlayerto check.stop- TheTradeRouteStopto 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
StringTemplatecontaining 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
StringTemplateexplaining 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:
checkIntegrityin classFreeColGameObject- Parameters:
fix- If true, fix problems if possible.lb- ALogBuilderto 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:
copyInin classFreeColGameObject- Type Parameters:
T- TheFreeColObjectsubclass 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:
writeAttributesin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
writeChildrenin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
readAttributesin classFreeColGameObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildrenin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColObject
-
-