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.


Field Summary
private  boolean accept
          Whether this is the accept instance.
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.
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE
 
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 a TradeItem to the DiplomaticTrade.
 java.util.List<Colony> getColoniesGivenBy(Player player)
          Returns a list of colonies given by Player
 Game getGame()
          Gets the game object this DiplomaticTrade belongs to.
 java.util.List<Goods> getGoodsGivenBy(Player player)
          Returns a list of goods given by Player
 Player getRecipient()
          Get the Recipient value.
 Player getSender()
          Get the Sender value.
 Player.Stance getStance()
          Returns the stance being offered, or null if none is being offered.
 java.util.List<TradeItem> getTradeItems()
          Returns all TradeItems.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean isAccept()
          Get the Accept value.
 java.util.Iterator<TradeItem> iterator()
          Returns an iterator for all TradeItems.
 java.util.List<FreeColGameObject> makeTrade()
          Calls the makeTrade method of all TradeItems.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void remove(int index)
          Remove a TradeItem from the DiplomaticTrade.
 void remove(TradeItem newItem)
          Remove a TradeItem from the DiplomaticTrade.
 void removeType(TradeItem someItem)
          Removes all trade items of the same class as the given argument.
 void setAccept(boolean newAccept)
          Set the Accept value.
 void setRecipient(Player newRecipient)
          Set the Recipient value.
 void setSender(Player newSender)
          Set the Sender 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, 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

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.


accept

private boolean accept
Whether this is the accept instance.

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 - a Game value
sender - a Player value
recipient - a Player value

DiplomaticTrade

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

Parameters:
game - a Game value
element - an Element value
Method Detail

getGame

public Game getGame()
Gets the game object this DiplomaticTrade belongs to.

Returns:
The game.

isAccept

public final boolean isAccept()
Get the Accept value.

Returns:
a boolean value

setAccept

public final void setAccept(boolean newAccept)
Set the Accept value.

Parameters:
newAccept - The new Accept value.

getSender

public final Player getSender()
Get the Sender value.

Returns:
a Player value

setSender

public final void setSender(Player newSender)
Set the Sender value.

Parameters:
newSender - The new Sender value.

getRecipient

public final Player getRecipient()
Get the Recipient value.

Returns:
a Player value

setRecipient

public final void setRecipient(Player newRecipient)
Set the Recipient value.

Parameters:
newRecipient - The new Recipient value.

add

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

Parameters:
newItem - a TradeItem value

remove

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

Parameters:
newItem - a TradeItem value

remove

public void remove(int index)
Remove a TradeItem 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

getStance

public Player.Stance getStance()
Returns the stance being offered, or null if none is being offered.

Returns:
an int value

getGoodsGivenBy

public java.util.List<Goods> getGoodsGivenBy(Player player)
Returns a list of goods given by Player

Returns:
a list of Goods offered by the player, empty if none given

getColoniesGivenBy

public java.util.List<Colony> getColoniesGivenBy(Player player)
Returns a list of colonies given by Player

Returns:
a list of Colony offered by the player, empty if none given

makeTrade

public java.util.List<FreeColGameObject> makeTrade()
Calls the makeTrade method of all TradeItems.

Returns:
A list of all objects traded.

getTradeItems

public java.util.List<TradeItem> getTradeItems()
Returns all TradeItems.

Returns:
a List of TradeItems

iterator

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

Returns:
an iterator for all TradeItems.

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.

getXMLElementTagName

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

Returns:
"goods".