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 Player
destination
The player who is to receive this item.private static java.lang.String
DESTINATION_TAG
static int
INVALID_TRADE_ITEM
Flag for validity tests.private Player
source
The player who is to provide this item.private static java.lang.String
SOURCE_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.boolean
equals(java.lang.Object o)
abstract int
evaluateFor(Player player)
Evaluate this trade item for a given player.Colony
getColony(Game game)
Get the colony to trade.Player
getDestination()
Get the destination player.int
getGold()
Get the gold to trade.Goods
getGoods()
Get the goods to trade.abstract StringTemplate
getLabel()
Get a label for this item.Player
getOther(Player player)
Get the other player for this trade item.Player
getSource()
Get the source player.Stance
getStance()
Get the stance to trade.Unit
getUnit()
Get the unit to trade.Player
getVictim()
Get the victim player to incite war against.int
hashCode()
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.abstract boolean
isUnique()
Is this trade item unique? This is true for the StanceTradeItem and the GoldTradeItem, and false for all others.abstract boolean
isValid()
Is this trade item valid? That is, is the request well formed.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
setDestination(Player newDestination)
Set the destination player.void
setGold(int gold)
Set the gold to trade.void
setGoods(Goods goods)
Set the goods to trade.void
setSource(Player newSource)
Set the source player.void
setStance(Stance stance)
Set the stance to trade.void
setUnit(Unit unit)
Set the unit to trade.protected void
writeAttributes(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 newTradeItem
instance.- 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 newTradeItem
instance.- Parameters:
game
- The enclosingGame
.xr
- TheFreeColXMLReader
to 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
- ThePlayer
we do not want.- Returns:
- The
Player
we 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
StringTemplate
describing this item.
-
getColony
public Colony getColony(Game game)
Get the colony to trade.- Parameters:
game
- AGame
to look for the colony in.- Returns:
- The
Colony
to trade.
-
getGoods
public Goods getGoods()
Get the goods to trade.- Returns:
- The
Goods
to trade.
-
setGoods
public void setGoods(Goods goods)
Set the goods to trade.- Parameters:
goods
- The newGoods
to 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
Player
to trade.
-
getStance
public Stance getStance()
Get the stance to trade.- Returns:
- The
Stance
to trade.
-
setStance
public void setStance(Stance stance)
Set the stance to trade.- Parameters:
stance
- The newStance
to trade.
-
getUnit
public Unit getUnit()
Get the unit to trade.- Returns:
- The
Unit
to trade.
-
setUnit
public void setUnit(Unit unit)
Set the unit to trade.- Parameters:
unit
- The newUnit
to trade.
-
evaluateFor
public abstract int evaluateFor(Player player)
Evaluate this trade item for a given player.- Parameters:
player
- ThePlayer
to 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:
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
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:
writeAttributes
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.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classFreeColGameObject
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classFreeColGameObject
-
-