net.sf.freecol.common.model
Class TradeItem

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.TradeItem
Direct Known Subclasses:
ColonyTradeItem, GoldTradeItem, GoodsTradeItem, StanceTradeItem, UnitTradeItem

public abstract class TradeItem
extends FreeColObject

One of the items a DiplomaticTrade consists of.


Field Summary
private  Player destination
          The player who is to receive this item.
private  Game game
          The game this TradeItem belongs to.
private  Player source
          The player who is to provide this item.
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE
 
Constructor Summary
TradeItem(Game game, java.lang.String id, Player source, Player destination)
          Creates a new TradeItem instance.
TradeItem(Game game, javax.xml.stream.XMLStreamReader in)
          Creates a new TradeItem instance.
 
Method Summary
 Player getDestination()
          Get the Destination value.
 Game getGame()
          Get the Game value.
 Player getSource()
          Get the Source value.
abstract  boolean isUnique()
          Returns whether this TradeItem must be unique.
abstract  boolean isValid()
          Returns whether this TradeItem is valid.
abstract  java.util.List<FreeColGameObject> makeTrade()
          Concludes the trade.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setDestination(Player newDestination)
          Set the Destination value.
 void setGame(Game newGame)
          Set the Game value.
 void setSource(Player newSource)
          Set the Source value.
 void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, getXMLElementTagName, hasAbility, hasAttribute, hasListeners, readAttributes, readChildren, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, setId, toArrayElement, toArrayElement, toListElement, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

game

private Game game
The game this TradeItem belongs to.


source

private Player source
The player who is to provide this item.


destination

private Player destination
The player who is to receive this item.

Constructor Detail

TradeItem

public TradeItem(Game game,
                 java.lang.String id,
                 Player source,
                 Player destination)
Creates a new TradeItem instance.

Parameters:
game - a Game value
id - a String value
source - a Player value
destination - a Player value

TradeItem

public TradeItem(Game game,
                 javax.xml.stream.XMLStreamReader in)
          throws javax.xml.stream.XMLStreamException
Creates a new TradeItem instance.

Parameters:
game - a Game value
in - a XMLStreamReader value
Throws:
javax.xml.stream.XMLStreamException
Method Detail

getGame

public final Game getGame()
Get the Game value.

Returns:
a Game value

setGame

public final void setGame(Game newGame)
Set the Game value.

Parameters:
newGame - The new Game value.

getSource

public final Player getSource()
Get the Source value.

Returns:
a Player value

setSource

public final void setSource(Player newSource)
Set the Source value.

Parameters:
newSource - The new Source value.

getDestination

public final Player getDestination()
Get the Destination value.

Returns:
a Player value

setDestination

public final void setDestination(Player newDestination)
Set the Destination value.

Parameters:
newDestination - The new Destination value.

isValid

public abstract boolean isValid()
Returns whether this TradeItem is valid.

Returns:
a boolean value

isUnique

public abstract boolean isUnique()
Returns whether this TradeItem must be unique. This is true for the StanceTradeItem and the GoldTradeItem, and false for all others.

Returns:
a boolean value

makeTrade

public abstract java.util.List<FreeColGameObject> makeTrade()
Concludes the trade.

Returns:
An item to be updated, or null if none required.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

toXMLImpl

public void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
               throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Specified by:
toXMLImpl in class FreeColObject
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.