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>cargoThe cargo expected to be on board on leaving the stop.private static java.lang.StringCARGO_TAGprivate LocationlocationThe trade location of the stop.private static java.lang.StringLOCATION_TAGprivate static java.util.logging.Loggerloggerstatic 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 TradeRouteStop(Game game)Create an empty trade route stop.TradeRouteStop(Game game, FreeColXMLReader xr)Create a newTradeRouteStopfrom 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 voidaddCargo(GoodsType newCargo)Add cargo to this stop.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.booleanequals(java.lang.Object o)intgetAvailableGoodsCount(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.intgetExportAmount(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.intgetImportAmount(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.StringTemplategetLabelFor(java.lang.String key, Player player)Create a template for this trade route stop.LocationgetLocation()Get the location of this stop.java.lang.StringgetLocationName(TradeLocation tradeLocation)Function for returning the name of a TradeLocationTradeLocationgetTradeLocation()Get the location of this stop as a TradeLocation.java.lang.StringgetXMLTagName()Get the serialization tag for this object.booleanhasWork(Unit unit, int turns)Is there work for a unit to do at this stop?StringTemplateinvalidStopLabel(Player player)Create an invalid trade route stop label.booleanisInternable()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.booleanisValid(Player player)Is this stop valid?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.voidsetCargo(java.util.List<GoodsType> newCargo)Set the cargo value.java.lang.StringtoString()voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.voidwriteChildren(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- TheLocationof 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 newTradeRouteStopfrom a stream.- Parameters:
game- The enclosingGame.xr- TheFreeColXMLReaderto 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
Locationof this stop.
-
getTradeLocation
public TradeLocation getTradeLocation()
Get the location of this stop as a TradeLocation.- Returns:
- The
TradeLocationfor this stop.
-
isValid
public boolean isValid(Player player)
Is this stop valid?- Parameters:
player- ThePlayerthat 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
GoodsTypes.
-
setCargo
public final void setCargo(java.util.List<GoodsType> newCargo)
Set the cargo value.- Parameters:
newCargo- A list ofGoodsTypedefining the cargo.
-
addCargo
public void addCargo(GoodsType newCargo)
Add cargo to this stop.- Parameters:
newCargo- TheGoodsTypeto 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
AbstractGoodsto 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- ThePlayerwho will see the message.- Returns:
- A
StringTemplatefor this stop.
-
invalidStopLabel
public StringTemplate invalidStopLabel(Player player)
Create an invalid trade route stop label.- Parameters:
player- ThePlayerwho will see the message.- Returns:
- A
StringTemplatefor this stop.
-
hasWork
public boolean hasWork(Unit unit, int turns)
Is there work for a unit to do at this stop?- Parameters:
unit- TheUnitto 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:
getAvailableGoodsCountin interfaceTradeLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getExportAmountin interfaceTradeLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getImportAmountin interfaceTradeLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getLocationNamein interfaceTradeLocation- Parameters:
tradeLocation- TheTradeLocationto 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:
isInternablein 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:
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
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:
writeAttributesin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
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.
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:FreeColGameObject- Overrides:
equalsin classFreeColGameObject
-
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
-
-