Package net.sf.freecol.common.model
Class TradeRouteStop
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.TradeRouteStop
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,TradeLocation
,ObjectWithId
public class TradeRouteStop extends FreeColGameObject implements TradeLocation
A stop along a trade route.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<GoodsType>
cargo
The cargo expected to be on board on leaving the stop.private static java.lang.String
CARGO_TAG
private Location
location
The trade location of the stop.private static java.lang.String
LOCATION_TAG
private static java.util.logging.Logger
logger
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 TradeRouteStop(Game game)
Create an empty trade route stop.TradeRouteStop(Game game, FreeColXMLReader xr)
Create a newTradeRouteStop
from a stream.TradeRouteStop(Game game, Location location)
Create a stop for the given location from a stream.TradeRouteStop(TradeRouteStop other)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCargo(GoodsType newCargo)
Add cargo to this stop.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.boolean
equals(java.lang.Object o)
int
getAvailableGoodsCount(GoodsType goodsType)
Get the amount of a given goods type at this trade location.java.util.List<GoodsType>
getCargo()
Get the current cargo for this stop.java.util.List<AbstractGoods>
getCompactCargo()
Get a list of the maximum abstract goods that could be loaded at this stop.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.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.StringTemplate
getLabelFor(java.lang.String key, Player player)
Create a template for this trade route stop.Location
getLocation()
Get the location of this stop.java.lang.String
getLocationName(TradeLocation tradeLocation)
Function for returning the name of a TradeLocationTradeLocation
getTradeLocation()
Get the location of this stop as a TradeLocation.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
hasWork(Unit unit, int turns)
Is there work for a unit to do at this stop?StringTemplate
invalidStopLabel(Player player)
Create an invalid trade route stop label.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.boolean
isValid(Player player)
Is this stop valid?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.void
setCargo(java.util.List<GoodsType> newCargo)
Set the cargo value.java.lang.String
toString()
void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, disposeResources, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, getSpecification, hashCode, intern, internId, isDisposed, isInitialized, 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
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.freecol.common.model.TradeLocation
canBeInput, getNameAsJlabel
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
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.
-
CARGO_TAG
private static final java.lang.String CARGO_TAG
- See Also:
- Constant Field Values
-
LOCATION_TAG
private static final java.lang.String LOCATION_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TradeRouteStop
public TradeRouteStop(Game game)
Create an empty trade route stop.- Parameters:
game
- The enclosingGame
.
-
TradeRouteStop
public TradeRouteStop(Game game, Location location)
Create a stop for the given location from a stream.- Parameters:
game
- The enclosingGame
.location
- TheLocation
of this stop.
-
TradeRouteStop
public TradeRouteStop(TradeRouteStop other)
Copy constructor. Creates a stop based on the given one.- Parameters:
other
- The otherTradeRouteStop
.
-
TradeRouteStop
public TradeRouteStop(Game game, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Create a newTradeRouteStop
from a stream.- Parameters:
game
- The enclosingGame
.xr
- TheFreeColXMLReader
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
- ThePlayer
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
GoodsType
s.
-
setCargo
public final void setCargo(java.util.List<GoodsType> newCargo)
Set the cargo value.- Parameters:
newCargo
- A list ofGoodsType
defining the cargo.
-
addCargo
public void addCargo(GoodsType newCargo)
Add cargo to this stop.- Parameters:
newCargo
- TheGoodsType
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
- ThePlayer
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
- ThePlayer
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
- TheUnit
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 interfaceTradeLocation
- Parameters:
goodsType
- TheGoodsType
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 interfaceTradeLocation
- Parameters:
goodsType
- TheGoodsType
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 interfaceTradeLocation
- Parameters:
goodsType
- TheGoodsType
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 interfaceTradeLocation
- Parameters:
tradeLocation
- TheTradeLocation
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 classFreeColGameObject
- 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 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
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 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.
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:FreeColGameObject
- Overrides:
equals
in classFreeColGameObject
-
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
-
-