Package net.sf.freecol.common.model
Class GoodsTradeItem
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.TradeItem
-
- net.sf.freecol.common.model.GoodsTradeItem
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
- Direct Known Subclasses:
NativeTradeItem
public class GoodsTradeItem extends TradeItem
A trade item consisting of some goods.
-
-
Field Summary
Fields Modifier and Type Field Description protected GoodsgoodsThe goods to change hands.static java.lang.StringTAG-
Fields inherited from class net.sf.freecol.common.model.TradeItem
INVALID_TRADE_ITEM
-
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 GoodsTradeItem(Game game, FreeColXMLReader xr)Creates a newGoodsTradeIteminstance.GoodsTradeItem(Game game, Player source, Player destination, Goods goods)Creates a newGoodsTradeIteminstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.booleanequals(java.lang.Object other)intevaluateFor(Player player)Evaluate this trade item for a given player.GoodsgetGoods()Get the goods to trade.StringTemplategetLabel()Get a label for this item.java.lang.StringgetXMLTagName()Get the serialization tag for this object.inthashCode()booleanisUnique()Is this trade item unique? This is true for the StanceTradeItem and the GoldTradeItem, and false for all others.booleanisValid()Is this trade item valid? That is, is the request well formed.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.voidsetGoods(Goods goods)Set the goods to trade.java.lang.StringtoString()protected voidwriteChildren(FreeColXMLWriter xw)Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.TradeItem
getColony, getDestination, getGold, getOther, getSource, getStance, getUnit, getVictim, isInternable, readAttributes, setDestination, setGold, setSource, setStance, setUnit, writeAttributes
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, disposeResources, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, getSpecification, 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
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
goods
protected Goods goods
The goods to change hands.
-
-
Constructor Detail
-
GoodsTradeItem
public GoodsTradeItem(Game game, Player source, Player destination, Goods goods)
Creates a newGoodsTradeIteminstance.- Parameters:
game- The enclosingGame.source- The sourcePlayer.destination- The destinationPlayer.goods- TheGoodsto trade.
-
GoodsTradeItem
public GoodsTradeItem(Game game, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newGoodsTradeIteminstance.- Parameters:
game- The enclosingGame.xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is an error reading the stream.
-
-
Method Detail
-
isValid
public boolean isValid()
Is this trade item valid? That is, is the request well formed.
-
isUnique
public boolean isUnique()
Is this trade item unique? This is true for the StanceTradeItem and the GoldTradeItem, and false for all others.
-
getLabel
public StringTemplate getLabel()
Get a label for this item.
-
getGoods
public Goods getGoods()
Get the goods to trade.
-
setGoods
public void setGoods(Goods goods)
Set the goods to trade.
-
evaluateFor
public int evaluateFor(Player player)
Evaluate this trade item for a given player.- Specified by:
evaluateForin classTradeItem- Parameters:
player- ThePlayerto evaluate for.- Returns:
- A value for the player, INVALID_TRADE_ITEM for invalid.
-
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.
-
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.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColObject
-
-