Package net.sf.freecol.common.model
Class TradeItem
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.TradeItem
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
- Direct Known Subclasses:
ColonyTradeItem,GoldTradeItem,GoodsTradeItem,InciteTradeItem,StanceTradeItem,UnitTradeItem
public abstract class TradeItem extends FreeColGameObject
One of the items a DiplomaticTrade consists of.
-
-
Field Summary
Fields Modifier and Type Field Description private PlayerdestinationThe player who is to receive this item.private static java.lang.StringDESTINATION_TAGstatic intINVALID_TRADE_ITEMFlag for validity tests.private PlayersourceThe player who is to provide this item.private static java.lang.StringSOURCE_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
-
-
Method Summary
All Methods Instance Methods Abstract 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 o)abstract intevaluateFor(Player player)Evaluate this trade item for a given player.ColonygetColony(Game game)Get the colony to trade.PlayergetDestination()Get the destination player.intgetGold()Get the gold to trade.GoodsgetGoods()Get the goods to trade.abstract StringTemplategetLabel()Get a label for this item.PlayergetOther(Player player)Get the other player for this trade item.PlayergetSource()Get the source player.StancegetStance()Get the stance to trade.UnitgetUnit()Get the unit to trade.PlayergetVictim()Get the victim player to incite war against.inthashCode()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.abstract booleanisUnique()Is this trade item unique? This is true for the StanceTradeItem and the GoldTradeItem, and false for all others.abstract booleanisValid()Is this trade item valid? That is, is the request well formed.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidsetDestination(Player newDestination)Set the destination player.voidsetGold(int gold)Set the gold to trade.voidsetGoods(Goods goods)Set the goods to trade.voidsetSource(Player newSource)Set the source player.voidsetStance(Stance stance)Set the stance to trade.voidsetUnit(Unit unit)Set the unit to trade.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes 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, 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, getXMLTagName, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readChild, readChildren, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toString, toXML, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
Field Detail
-
INVALID_TRADE_ITEM
public static final int INVALID_TRADE_ITEM
Flag for validity tests.- See Also:
- Constant Field Values
-
source
private Player source
The player who is to provide this item.
-
destination
private Player destination
The player who is to receive this item.
-
DESTINATION_TAG
private static final java.lang.String DESTINATION_TAG
- See Also:
- Constant Field Values
-
SOURCE_TAG
private static final java.lang.String SOURCE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TradeItem
protected TradeItem(Game game, java.lang.String id, Player source, Player destination)
Creates a newTradeIteminstance.- Parameters:
game- The enclosingGame.id- The object identifier.source- The sourcePlayer.destination- The destinationPlayer.
-
TradeItem
protected TradeItem(Game game, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newTradeIteminstance.- Parameters:
game- The enclosingGame.xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
-
Method Detail
-
getSource
public final Player getSource()
Get the source player.- Returns:
- The source
Player.
-
setSource
public final void setSource(Player newSource)
Set the source player.- Parameters:
newSource- The new sourcePlayer.
-
getDestination
public final Player getDestination()
Get the destination player.- Returns:
- The destination
Player.
-
setDestination
public final void setDestination(Player newDestination)
Set the destination player.- Parameters:
newDestination- The new destinationPlayer.
-
getOther
public final Player getOther(Player player)
Get the other player for this trade item.- Parameters:
player- ThePlayerwe do not want.- Returns:
- The
Playerwe want.
-
isValid
public abstract boolean isValid()
Is this trade item valid? That is, is the request well formed.- Returns:
- True if the item is valid.
-
isUnique
public abstract boolean isUnique()
Is this trade item unique? This is true for the StanceTradeItem and the GoldTradeItem, and false for all others.- Returns:
- True if the item is unique.
-
getLabel
public abstract StringTemplate getLabel()
Get a label for this item.- Returns:
- A
StringTemplatedescribing this item.
-
getColony
public Colony getColony(Game game)
Get the colony to trade.- Parameters:
game- AGameto look for the colony in.- Returns:
- The
Colonyto trade.
-
getGoods
public Goods getGoods()
Get the goods to trade.- Returns:
- The
Goodsto trade.
-
setGoods
public void setGoods(Goods goods)
Set the goods to trade.- Parameters:
goods- The newGoodsto trade.
-
getGold
public int getGold()
Get the gold to trade.- Returns:
- The gold to trade.
-
setGold
public void setGold(int gold)
Set the gold to trade.- Parameters:
gold- The new gold to trade.
-
getVictim
public Player getVictim()
Get the victim player to incite war against.- Returns:
- The
Playerto trade.
-
getStance
public Stance getStance()
Get the stance to trade.- Returns:
- The
Stanceto trade.
-
setStance
public void setStance(Stance stance)
Set the stance to trade.- Parameters:
stance- The newStanceto trade.
-
getUnit
public Unit getUnit()
Get the unit to trade.- Returns:
- The
Unitto trade.
-
setUnit
public void setUnit(Unit unit)
Set the unit to trade.- Parameters:
unit- The newUnitto trade.
-
evaluateFor
public abstract int evaluateFor(Player player)
Evaluate this trade item for a given player.- Parameters:
player- ThePlayerto evaluate for.- Returns:
- A value for the player, INVALID_TRADE_ITEM for invalid.
-
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
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.
-
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.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classFreeColGameObject
-
hashCode
public int hashCode()
- Overrides:
hashCodein classFreeColGameObject
-
-