Package net.sf.freecol.common.model
Class MarketData
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.MarketData
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public class MarketData extends FreeColGameObject
Objects of this class hold the market data for a particular type of goods.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
AMOUNT_TAG
private int
amountInMarket
Amount of this goods in the market.private int
arrears
Arrears owed to the crown.private static java.lang.String
ARREARS_TAG
private int
costToBuy
Current purchase price.private static java.lang.String
GOODS_TYPE_TAG
private GoodsType
goodsType
What type of goods is this.private static java.lang.String
INCOME_AFTER_TAXES_TAG
private static java.lang.String
INCOME_BEFORE_TAXES_TAG
private int
incomeAfterTaxes
Total income after taxes.private int
incomeBeforeTaxes
Total income before taxes.private static java.lang.String
INITIAL_PRICE_TAG
private int
initialPrice
The initial price.private static java.util.logging.Logger
logger
static int
MAXIMUM_PRICE
Inclusive upper bound on goods price.static int
MINIMUM_PRICE
Inclusive lower bound on goods price.private int
oldPrice
Place to save to old price so as to be able to tell when a price change message should be generated.private int
paidForSale
Current selling price.private int
sales
Total sales.private static java.lang.String
SALES_TAG
static java.lang.String
TAG
private boolean
traded
Has this good been traded?private static java.lang.String
TRADED_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description MarketData(Game game, java.lang.String id)
Creates a newMarketData
with the given identifier.MarketData(Game game, GoodsType goodsType)
Creates a newMarketData
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.int
getAmountInMarket()
Get the amount of the goods type in the market.int
getArrears()
Get the amount of arrears owned to the crown for this goods type.int
getCostToBuy()
Get the current purchase price.GoodsType
getGoodsType()
Get the type of goods of thisMarketData
.int
getIncomeAfterTaxes()
Get the income after taxes from trading in this goods type.int
getIncomeBeforeTaxes()
Get the income before taxes from trading in this goods type.int
getInitialPrice()
Get the initial price of these goods.int
getOldPrice()
Get the old price.int
getPaidForSale()
Get the current sale price.int
getSales()
Get the total sales.boolean
getTraded()
Has there been trading in thisMarketData
?java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
price()
Adjust the prices.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
setAmountInMarket(int newAmountInMarket)
Set the amount of goods in the market.void
setArrears(int newArrears)
Set the amount of arrears owed to the crown.void
setCostToBuy(int newCostToBuy)
Set the current purchase price.void
setIncomeAfterTaxes(int newIncomeAfterTaxes)
Set the income after taxes value.void
setIncomeBeforeTaxes(int newIncomeBeforeTaxes)
Set the income before taxes value.void
setInitialPrice(int newInitialPrice)
Set the initial price value.void
setOldPrice(int oldPrice)
Set the old price.void
setPaidForSale(int newPaidForSale)
Set the current sale price.void
setSales(int newSales)
Set the total sales value.void
setTraded(boolean traded)
Set the trading status of thisMarketData
.java.lang.String
toString()
void
update()
Update the pricing of this datum, ignoring the price change clamp.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, disposeResources, equals, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, getSpecification, hashCode, intern, internId, isDisposed, isInitialized, isInternable, readFromXML, setGame, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readChild, readChildren, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
MINIMUM_PRICE
public static final int MINIMUM_PRICE
Inclusive lower bound on goods price.- See Also:
- Constant Field Values
-
MAXIMUM_PRICE
public static final int MAXIMUM_PRICE
Inclusive upper bound on goods price.- See Also:
- Constant Field Values
-
goodsType
private GoodsType goodsType
What type of goods is this.
-
costToBuy
private int costToBuy
Current purchase price.
-
paidForSale
private int paidForSale
Current selling price.
-
amountInMarket
private int amountInMarket
Amount of this goods in the market.
-
initialPrice
private int initialPrice
The initial price.
-
arrears
private int arrears
Arrears owed to the crown.
-
sales
private int sales
Total sales.
-
incomeBeforeTaxes
private int incomeBeforeTaxes
Total income before taxes.
-
incomeAfterTaxes
private int incomeAfterTaxes
Total income after taxes.
-
oldPrice
private int oldPrice
Place to save to old price so as to be able to tell when a price change message should be generated. Not necessary to serialize.
-
traded
private boolean traded
Has this good been traded?
-
AMOUNT_TAG
private static final java.lang.String AMOUNT_TAG
- See Also:
- Constant Field Values
-
ARREARS_TAG
private static final java.lang.String ARREARS_TAG
- See Also:
- Constant Field Values
-
GOODS_TYPE_TAG
private static final java.lang.String GOODS_TYPE_TAG
- See Also:
- Constant Field Values
-
INCOME_AFTER_TAXES_TAG
private static final java.lang.String INCOME_AFTER_TAXES_TAG
- See Also:
- Constant Field Values
-
INCOME_BEFORE_TAXES_TAG
private static final java.lang.String INCOME_BEFORE_TAXES_TAG
- See Also:
- Constant Field Values
-
INITIAL_PRICE_TAG
private static final java.lang.String INITIAL_PRICE_TAG
- See Also:
- Constant Field Values
-
SALES_TAG
private static final java.lang.String SALES_TAG
- See Also:
- Constant Field Values
-
TRADED_TAG
private static final java.lang.String TRADED_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MarketData
public MarketData(Game game, GoodsType goodsType)
Creates a newMarketData
instance.- Parameters:
game
- The enclosingGame
.goodsType
- TheGoodsType
this market data describes.
-
MarketData
public MarketData(Game game, java.lang.String id)
Creates a newMarketData
with the given identifier. The object should be initialized later.- Parameters:
game
- The enclosingGame
.id
- The object identifier.
-
-
Method Detail
-
getGoodsType
public final GoodsType getGoodsType()
Get the type of goods of thisMarketData
.- Returns:
- The goods type for this data.
-
getCostToBuy
public final int getCostToBuy()
Get the current purchase price.- Returns:
- The purchase price.
-
setCostToBuy
public final void setCostToBuy(int newCostToBuy)
Set the current purchase price.- Parameters:
newCostToBuy
- The new purchase price.
-
getPaidForSale
public final int getPaidForSale()
Get the current sale price.- Returns:
- The sale price.
-
setPaidForSale
public final void setPaidForSale(int newPaidForSale)
Set the current sale price.- Parameters:
newPaidForSale
- The new sale price.
-
getAmountInMarket
public final int getAmountInMarket()
Get the amount of the goods type in the market.- Returns:
- The amount of goods.
-
setAmountInMarket
public final void setAmountInMarket(int newAmountInMarket)
Set the amount of goods in the market.- Parameters:
newAmountInMarket
- The new amount of goods in the market.
-
getInitialPrice
public final int getInitialPrice()
Get the initial price of these goods.- Returns:
- The initial price.
-
setInitialPrice
public final void setInitialPrice(int newInitialPrice)
Set the initial price value.- Parameters:
newInitialPrice
- The new initial price value.
-
getArrears
public final int getArrears()
Get the amount of arrears owned to the crown for this goods type.- Returns:
- The arrears amount.
-
setArrears
public final void setArrears(int newArrears)
Set the amount of arrears owed to the crown.- Parameters:
newArrears
- The new amount of arrears.
-
getSales
public final int getSales()
Get the total sales.- Returns:
- The total sales.
-
setSales
public final void setSales(int newSales)
Set the total sales value.- Parameters:
newSales
- The new total sales value.
-
getIncomeBeforeTaxes
public final int getIncomeBeforeTaxes()
Get the income before taxes from trading in this goods type.- Returns:
- The income before taxes.
-
setIncomeBeforeTaxes
public final void setIncomeBeforeTaxes(int newIncomeBeforeTaxes)
Set the income before taxes value.- Parameters:
newIncomeBeforeTaxes
- The new income before taxes value.
-
getIncomeAfterTaxes
public final int getIncomeAfterTaxes()
Get the income after taxes from trading in this goods type.- Returns:
- The income after taxes.
-
setIncomeAfterTaxes
public final void setIncomeAfterTaxes(int newIncomeAfterTaxes)
Set the income after taxes value.- Parameters:
newIncomeAfterTaxes
- The new income after taxes value.
-
getOldPrice
public final int getOldPrice()
Get the old price.- Returns:
- The old price.
-
setOldPrice
public void setOldPrice(int oldPrice)
Set the old price.- Parameters:
oldPrice
- A `new' old price.
-
getTraded
public final boolean getTraded()
Has there been trading in thisMarketData
?- Returns:
- True if trading has occurred.
-
setTraded
public void setTraded(boolean traded)
Set the trading status of thisMarketData
.- Parameters:
traded
- The trade status to set.
-
price
public boolean price()
Adjust the prices. Sets the costToBuy and paidForSale fields from the amount in the market, initial price and goods-type specific information. Ensures that prices change incrementally with a clamping mechanism.- Returns:
- True if the price changes.
-
update
public void update()
Update the pricing of this datum, ignoring the price change clamp.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColGameObject
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributes
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classFreeColGameObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-