net.sf.freecol.common.model
Class DiplomaticTrade

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.DiplomaticTrade

public class DiplomaticTrade
extends FreeColObject

The class DiplomaticTrade represents an offer one player can make another.


Nested Class Summary
static class DiplomaticTrade.TradeStatus
          A type for the trade status.
 
Field Summary
private  Game game
           
private  java.util.List<TradeItem> items
          The individual items the trade consists of.
private  Player recipient
          The player who is to accept this agreement.
private  Player sender
          The player who proposed agreement.
private  DiplomaticTrade.TradeStatus status
          The status of this agreement.
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, logger, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
DiplomaticTrade(Game game, org.w3c.dom.Element element)
          Creates a new DiplomaticTrade instance.
DiplomaticTrade(Game game, Player sender, Player recipient)
          Creates a new DiplomaticTrade instance.
DiplomaticTrade(Game game, Player sender, Player recipient, java.util.List<TradeItem> items)
          Creates a new DiplomaticTrade instance.
 
Method Summary
 void add(TradeItem newItem)
          Add to the DiplomaticTrade.
 java.util.List<Colony> getColoniesGivenBy(Player player)
          Get a list of colonies offered in this trade.
 java.util.List<Goods> getGoodsGivenBy(Player player)
          Get the goods being offered.
 Player getRecipient()
          Get the recipient player.
 Player getSender()
          Get the sending player.
 Player.Stance getStance()
          Get the stance being offered.
 DiplomaticTrade.TradeStatus getStatus()
          Get the trade status.
 java.util.List<TradeItem> getTradeItems()
          Get a list of all items to trade.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 java.util.Iterator<TradeItem> iterator()
          Get an iterator for all the TradeItems.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void remove(int index)
          Remove from the DiplomaticTrade.
 void remove(TradeItem newItem)
          Remove a from the DiplomaticTrade.
 void removeType(TradeItem someItem)
          Removes all trade items of the same class as the given argument.
 void setRecipient(Player newRecipient)
          Set the recieving player.
 void setSender(Player newSender)
          Set the sending player.
 void setStatus(DiplomaticTrade.TradeStatus status)
          Set the trade status.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
protected  void writeAttributes(javax.xml.stream.XMLStreamWriter out)
          Write the attributes of this object to a stream.
protected  void writeChildren(javax.xml.stream.XMLStreamWriter out)
          Write the children of this object to a stream.
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, getSpecification, hasAbility, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

private java.util.List<TradeItem> items
The individual items the trade consists of.


game

private final Game game

sender

private Player sender
The player who proposed agreement.


recipient

private Player recipient
The player who is to accept this agreement.


status

private DiplomaticTrade.TradeStatus status
The status of this agreement.

Constructor Detail

DiplomaticTrade

public DiplomaticTrade(Game game,
                       Player sender,
                       Player recipient)
Creates a new DiplomaticTrade instance.

Parameters:
game - a Game value
sender - a Player value
recipient - a Player value

DiplomaticTrade

public DiplomaticTrade(Game game,
                       Player sender,
                       Player recipient,
                       java.util.List<TradeItem> items)
Creates a new DiplomaticTrade instance.

Parameters:
game - The Game containing the trade.
sender - The sending Player.
recipient - The recipient Player.
items - A list of items to trade.

DiplomaticTrade

public DiplomaticTrade(Game game,
                       org.w3c.dom.Element element)
Creates a new DiplomaticTrade instance.

Parameters:
game - The Game containing the trade.
element - an Element value
Method Detail

getStatus

public DiplomaticTrade.TradeStatus getStatus()
Get the trade status.

Returns:
The status of this agreement.

setStatus

public void setStatus(DiplomaticTrade.TradeStatus status)
Set the trade status.

Parameters:
status - The new TradeStatus for this agreement.

getSender

public final Player getSender()
Get the sending player.

Returns:
The sending Player.

setSender

public final void setSender(Player newSender)
Set the sending player.

Parameters:
newSender - The new sending Player.

getRecipient

public final Player getRecipient()
Get the recipient player.

Returns:
The recipient Player.

setRecipient

public final void setRecipient(Player newRecipient)
Set the recieving player.

Parameters:
newRecipient - The new recipient Player.

add

public void add(TradeItem newItem)
Add to the DiplomaticTrade.

Parameters:
newItem - The TradeItem to add.

remove

public void remove(TradeItem newItem)
Remove a from the DiplomaticTrade.

Parameters:
newItem - The TradeItem to remove.

remove

public void remove(int index)
Remove from the DiplomaticTrade.

Parameters:
index - The index of the TradeItem to remove

removeType

public void removeType(TradeItem someItem)
Removes all trade items of the same class as the given argument.

Parameters:
someItem - a TradeItem value

getTradeItems

public java.util.List<TradeItem> getTradeItems()
Get a list of all items to trade.

Returns:
A list of all the TradeItems.

iterator

public java.util.Iterator<TradeItem> iterator()
Get an iterator for all the TradeItems.

Returns:
An iterator for all TradeItems.

getStance

public Player.Stance getStance()
Get the stance being offered.

Returns:
The Stance offered in this trade, or null if none.

getGoodsGivenBy

public java.util.List<Goods> getGoodsGivenBy(Player player)
Get the goods being offered.

Returns:
A list of Goods offered in this trade.

getColoniesGivenBy

public java.util.List<Colony> getColoniesGivenBy(Player player)
Get a list of colonies offered in this trade.

Returns:
A list of Colonys offered in this trade.

toXMLImpl

protected 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.

writeAttributes

protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                        throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream.

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

writeChildren

protected void writeChildren(javax.xml.stream.XMLStreamWriter out)
                      throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream.

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

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.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Returns:
"diplomaticTrade".