|
|||||||||
| 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 where a market holds all goods to be sold and the price of a particular goods type is determined solely by its availability in that market.
| Nested Class Summary | |
|---|---|
static class |
Market.Access
Constant for specifying the access to this Market
when selling goods. |
| Field Summary | |
|---|---|
private java.util.Map<GoodsType,MarketData> |
marketData
|
static int |
MINIMUM_AMOUNT
European markets are bottomless. |
private Player |
owner
|
private java.util.ArrayList<TransactionListener> |
transactionListeners
|
| Fields inherited from class net.sf.freecol.common.model.FreeColGameObject |
|---|
UNITS_TAG_NAME |
| Fields inherited from class net.sf.freecol.common.model.FreeColObject |
|---|
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG |
| Constructor Summary | |
|---|---|
Market(Game game,
Player player)
Main constructor for creating a market for a new 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 | |
|---|---|
void |
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 |
flushPriceChange(GoodsType goodsType)
Clear any price changes for a type of goods. |
int |
getAmountInMarket(GoodsType goodsType)
Gets the amount of a goods type in the market. |
int |
getArrears(GoodsType goodsType)
Gets the arrears for of a given goods type. |
int |
getBidPrice(GoodsType type,
int amount)
Gets the price of a given goods when the Player buys. |
int |
getCostToBuy(GoodsType type)
Determines the cost to buy a single unit of a particular type of good. |
int |
getIncomeAfterTaxes(GoodsType goodsType)
Gets the income after taxes for a type of goods. |
int |
getIncomeBeforeTaxes(GoodsType goodsType)
Gets the income before taxes for a type of goods. |
int |
getInitialPrice(GoodsType goodsType)
Gets the initial price of a given goods type. |
MarketData |
getMarketData(GoodsType goodsType)
Return the market data for a type of goods. |
Player |
getOwner()
Gets the owner of this Market. |
int |
getPaidForSale(GoodsType type)
Determines the price paid for the sale of a single unit of a particular type of goods. |
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. |
int |
getSales(GoodsType goodsType)
Gets the sales of a type of goods. |
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. |
boolean |
hasBeenTraded(GoodsType type)
Has a type of goods been traded in this market? |
boolean |
hasPriceChanged(GoodsType goodsType)
Has the price of a type of goods changed in this market? |
ModelMessage |
makePriceChangeMessage(GoodsType goodsType)
Make up a ModelMessage describing the change in this
Market for a specified type of goods. |
void |
modifyIncomeAfterTaxes(GoodsType goodsType,
int amount)
Modifies the income after taxes on sales of a type of goods. |
void |
modifyIncomeBeforeTaxes(GoodsType goodsType,
int amount)
Modifies the income before taxes on sales of a type of goods. |
void |
modifySales(GoodsType goodsType,
int amount)
Modifies the sales of a type of goods. |
private void |
putMarketData(GoodsType goodsType,
MarketData data)
Describe putMarketData method here. |
void |
randomizeInitialPrice(java.util.Random random)
Makes a slight randomization to all the new world and luxury goods types. |
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 |
private MarketData |
requireMarketData(GoodsType goodsType)
Gets the market data for a specified goods type, creating it if it does not exist yet. |
void |
setArrears(GoodsType goodsType,
int value)
Sets the arrears associated with a type of goods. |
void |
setInitialPrice(GoodsType goodsType,
int amount)
Sets the initial price of a given goods type. |
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 |
|---|
dispose, disposeList, equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toString, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int MINIMUM_AMOUNT
private final java.util.Map<GoodsType,MarketData> marketData
private Player owner
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,
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 void putMarketData(GoodsType goodsType,
MarketData data)
putMarketData method here.
goodsType - a GoodsType valuedata - a MarketData valueprivate MarketData requireMarketData(GoodsType goodsType)
goodsType - The GoodsType to query.
MarketData required.public void randomizeInitialPrice(java.util.Random random)
random - A pseudo-random number source.public MarketData getMarketData(GoodsType goodsType)
goodsType - a GoodsType value
MarketData valuepublic Player getOwner()
Market.
getOwner in interface OwnableMarket.public void setOwner(Player owner)
Market.
setOwner in interface Ownableowner - The Player to own this Market.public boolean hasBeenTraded(GoodsType type)
type - The type of goods to consider.
public int getCostToBuy(GoodsType type)
type - A GoodsType value.
public int getPaidForSale(GoodsType type)
type - A GoodsType value.
public void addGoodsToMarket(GoodsType goodsType,
int amount)
goodsType - The GoodsType to add.amount - The amount of goods.public int getInitialPrice(GoodsType goodsType)
goodsType - The GoodsType to get the initial price of.
public void setInitialPrice(GoodsType goodsType,
int amount)
goodsType - The GoodsType to set the initial price of.amount - The new initial price.
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 int getArrears(GoodsType goodsType)
goodsType - The GoodsType to get arrears for.
public void setArrears(GoodsType goodsType,
int value)
goodsType - The GoodsType to set the arrears for.value - The amount of arrears to set.public int getSales(GoodsType goodsType)
goodsType - The GoodsType to get the sales for.
public void modifySales(GoodsType goodsType,
int amount)
goodsType - The GoodsType to set the sales for.amount - The amount of sales to add to the current amount.public int getIncomeBeforeTaxes(GoodsType goodsType)
goodsType - The GoodsType to get the income for.
public void modifyIncomeBeforeTaxes(GoodsType goodsType,
int amount)
goodsType - The GoodsType to set the income for.amount - The amount of tax income to add to the current amount.public int getIncomeAfterTaxes(GoodsType goodsType)
goodsType - The GoodsType to get the income for.
public void modifyIncomeAfterTaxes(GoodsType goodsType,
int amount)
goodsType - The GoodsType to set the income for.amount - The amount of tax income to add to the current amount.public int getAmountInMarket(GoodsType goodsType)
goodsType - The GoodsType to get the amount of.
public boolean hasPriceChanged(GoodsType goodsType)
goodsType - The type of goods to consider.
public void flushPriceChange(GoodsType goodsType)
goodsType - The type of goods to consider.public ModelMessage makePriceChangeMessage(GoodsType goodsType)
ModelMessage describing the change in this
Market for a specified type of goods.
goodsType - The GoodsType that has changed price.
public void addTransactionListener(TransactionListener listener)
listener - the listenerpublic void removeTransactionListener(TransactionListener listener)
listener - the listenerpublic TransactionListener[] getTransactionListener()
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 price() 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 | ||||||||