|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.freecol.common.model.FreeColObject
net.sf.freecol.common.model.FreeColGameObject
net.sf.freecol.common.model.Market
public final class Market
This class implements a simple economic model whereby a market holds all goods that have been sold and the price of a particular type of good is determined solely by its availability in that market.
| Field Summary | |
|---|---|
static int |
CUSTOM_HOUSE
Constant for specifying the access to this Market
when buying and
selling goods. |
static int |
EUROPE
Constant for specifying the access to this Market
when buying and
selling goods. |
private java.util.Map<GoodsType,MarketData> |
marketData
|
static int |
MAXIMUM_PRICE
|
static int |
MINIMUM_PRICE
|
private Player |
owner
|
private java.util.ArrayList<TransactionListener> |
transactionListeners
|
| Fields inherited from class net.sf.freecol.common.model.FreeColObject |
|---|
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE |
| Constructor Summary | |
|---|---|
Market(Game game,
org.w3c.dom.Element e)
Initiates a new Market from an
XML representation. |
|
Market(Game game,
Player player)
|
|
Market(Game game,
java.lang.String id)
Initiates a new Market with the given ID. |
|
Market(Game game,
javax.xml.stream.XMLStreamReader in)
Initiates a new Market from an
XML representation. |
|
| Method Summary | |
|---|---|
boolean |
addGoodsToMarket(GoodsType goodsType,
int amount)
Add (or remove) some goods to this market. |
void |
addTransactionListener(TransactionListener listener)
Adds a transaction listener for notification of any transaction |
void |
buy(GoodsType goodsType,
int amount,
Player player)
Buys an amount of a particular type of good with the cost being met by a supplied player. |
int |
costToBuy(GoodsType type)
Determines the cost to buy a single unit of a particular type of good. |
int |
getBidPrice(GoodsType type,
int amount)
Gets the price of a given goods when the Player buys. |
MarketData |
getMarketData(GoodsType goodsType)
Return the market data for a type of goods. |
Player |
getOwner()
Gets the owner of this Market. |
int |
getSalePrice(Goods goods)
Gets the price of a given goods when the Player sells. |
int |
getSalePrice(GoodsType type,
int amount)
Gets the price of a given goods when the Player sells. |
TransactionListener[] |
getTransactionListener()
Returns an array of all the TransactionListener added to this Market. |
static java.lang.String |
getXMLElementTagName()
Returns the tag name of the root element representing this object. |
ModelMessage |
makePriceMessage(GoodsType goodsType)
Make up a ModelMessage describing the change in this
Market for a specified type of goods. |
int |
paidForSale(GoodsType type)
Determines the price paid for the sale of a single unit of a particular type of goods. |
private boolean |
priceGoods(GoodsType goodsType)
Adjust the price for a particular type of goods. |
void |
putMarketData(GoodsType goodsType,
MarketData data)
Describe putMarketData method here. |
protected void |
readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
Initialize this object from an XML-representation of this object. |
void |
removeTransactionListener(TransactionListener listener)
Removes a transaction listener |
void |
sell(Goods goods,
Player player)
Sells an amount of a particular type of good with the proceeds of the sale being paid to a supplied player. |
void |
sell(GoodsType type,
int amount,
Player player)
Sells an amount of a particular type of good with the proceeds of the sale being paid to a supplied player. |
void |
sell(GoodsType type,
int amount,
Player player,
int marketAccess)
Sells an amount of a particular type of good with the proceeds of the sale being paid to a supplied player. |
void |
setOwner(Player owner)
Sets the owner of this Market. |
protected void |
toXMLImpl(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
This method writes an XML-representation of this object to the given stream. |
| Methods inherited from class net.sf.freecol.common.model.FreeColGameObject |
|---|
addModelMessage, addModelMessage, addModelMessage, addToRemoveElement, dispose, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, readFromXMLPartialByClass, setFakeID, setGame, setId, toSavedXML, toString, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject, updateID |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int MINIMUM_PRICE
public static final int MAXIMUM_PRICE
private Player owner
public static final int EUROPE
Market
when buying and
selling goods.
public static final int CUSTOM_HOUSE
Market
when buying and
selling goods.
private final java.util.Map<GoodsType,MarketData> marketData
private java.util.ArrayList<TransactionListener> transactionListeners
| Constructor Detail |
|---|
public Market(Game game,
Player player)
public Market(Game game,
javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
Market from an
XML representation.
game - The Game this object belongs to.in - The input stream containing the XML.
javax.xml.stream.XMLStreamException - if a problem was encountered
during parsing.
public Market(Game game,
org.w3c.dom.Element e)
Market from an
XML representation.
game - The Game this object belongs to.e - An XML-element that will be used to initialize
this object.
public Market(Game game,
java.lang.String id)
Market with the given ID.
The object should later be initialized by calling either
FreeColGameObject.readFromXML(XMLStreamReader) or
FreeColObject.readFromXMLElement(Element).
game - The Game in which this object belong.id - The unique identifier for this object.| Method Detail |
|---|
private boolean priceGoods(GoodsType goodsType)
goodsType - a GoodsType value
public MarketData getMarketData(GoodsType goodsType)
goodsType - a GoodsType value
MarketData value
public void putMarketData(GoodsType goodsType,
MarketData data)
putMarketData method here.
goodsType - a GoodsType valuedata - a MarketData valuepublic Player getOwner()
Market.
getOwner in interface OwnableMarket.public void setOwner(Player owner)
Market.
setOwner in interface Ownableowner - The Player that shall own this Market.public int costToBuy(GoodsType type)
type - A GoodsType value.
public int paidForSale(GoodsType type)
type - A GoodsType value.
public void sell(Goods goods,
Player player)
EUROPE as the accesspoint for this market.
Note that post-independence this no longer refers to a specific port.
goods - The Goods object being sold.player - The Player selling the goods.
public void sell(GoodsType type,
int amount,
Player player)
EUROPE as the accesspoint for this market.
type - The type of goods to be sold.amount - The amount of goods to be sold.player - The Player selling the goods.
public void sell(GoodsType type,
int amount,
Player player,
int marketAccess)
type - The type of goods to be sold.amount - The amount of goods to be sold.player - The Player selling the goods.marketAccess - The place where goods are traded.
public void buy(GoodsType goodsType,
int amount,
Player player)
goodsType - The type of the good that is being bought.amount - The amount of goods that are being bought.player - The Player buying the goods.
java.lang.IllegalStateException - If the player cannot afford
to buy the goods.
public boolean addGoodsToMarket(GoodsType goodsType,
int amount)
goodsType - The GoodsType to add.amount - The amount of goods.
public int getBidPrice(GoodsType type,
int amount)
Player buys.
type - a GoodsType valueamount - The amount of goods.
public int getSalePrice(GoodsType type,
int amount)
Player sells.
type - a GoodsType valueamount - The amount of goods.
public int getSalePrice(Goods goods)
Player sells.
goods - a Goods value
int valuepublic void addTransactionListener(TransactionListener listener)
listener - the listenerpublic void removeTransactionListener(TransactionListener listener)
listener - the listenerpublic TransactionListener[] getTransactionListener()
public ModelMessage makePriceMessage(GoodsType goodsType)
ModelMessage describing the change in this
Market for a specified type of goods.
goodsType - The GoodsType that has changed price.
protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
throws javax.xml.stream.XMLStreamException
Player will
be added to that representation if showAll is
set to false.
toXMLImpl in class FreeColGameObjectout - The target stream.player - The Player this XML-representation
should be made for, or null if
showAll == true.showAll - Only attributes visible to player
will be added to the representation if showAll
is set to false.toSavedGame - If true then information that
is only needed when saving a game is added.
javax.xml.stream.XMLStreamException - if there are any problems writing
to the stream.
protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readFromXMLImpl in class FreeColObjectin - The input stream with the XML.
javax.xml.stream.XMLStreamException - on problems with the stream.
TODO: Get rid of the for-priceGoods() when the server sends all
price changes.public static java.lang.String getXMLElementTagName()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||