Package net.sf.freecol.common.model
Class NativeTradeItem
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.TradeItem
-
- net.sf.freecol.common.model.GoodsTradeItem
-
- net.sf.freecol.common.model.NativeTradeItem
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public class NativeTradeItem extends GoodsTradeItem
A trade item consisting of some goods to be traded with the natives. Therefore we include the current valuation and the haggle count.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Comparator<NativeTradeItem>
descendingPriceComparator
Compare the trade item price.private static java.lang.String
HAGGLE_COUNT_TAG
private int
haggleCount
The number of haggling rounds.private int
price
The current valuation by the natives.static int
PRICE_INVALID
Magic number for price to denote an invalid item.private static java.lang.String
PRICE_TAG
static int
PRICE_UNSET
Magic number to denote that the price has not been initialized.static java.lang.String
TAG
-
Fields inherited from class net.sf.freecol.common.model.GoodsTradeItem
goods
-
Fields inherited from class net.sf.freecol.common.model.TradeItem
INVALID_TRADE_ITEM
-
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 NativeTradeItem(Game game, FreeColXMLReader xr)
Creates a newNativeTradeItem
instance.NativeTradeItem(Game game, Player source, Player destination, Goods goods)
Creates a newNativeTradeItem
instance.NativeTradeItem(NativeTradeItem nti)
Copy a newNativeTradeItem
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.boolean
equals(java.lang.Object o)
int
getHaggleCount()
Get the haggle count for this item.int
getPrice()
Get the price for this item.java.lang.String
getXMLTagName()
Get the serialization tag for this object.java.util.function.Predicate<NativeTradeItem>
goodsMatcher()
Get a predicate to match this native trade item by its goods.int
hashCode()
boolean
priceIsSet()
Has a price been set for this item?boolean
priceIsValid()
Is the price valid for trade.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
setHaggleCount(int haggleCount)
Set the haggle count for this item.void
setPrice(int price)
Set the price for this item.java.lang.String
toString()
protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.GoodsTradeItem
evaluateFor, getGoods, getLabel, isUnique, isValid, readChild, readChildren, setGoods, writeChildren
-
Methods inherited from class net.sf.freecol.common.model.TradeItem
getColony, getDestination, getGold, getOther, getSource, getStance, getUnit, getVictim, isInternable, setDestination, setGold, setSource, setStance, setUnit
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, disposeResources, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, getSpecification, intern, internId, isDisposed, isInitialized, 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, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
descendingPriceComparator
public static final java.util.Comparator<NativeTradeItem> descendingPriceComparator
Compare the trade item price.
-
PRICE_UNSET
public static final int PRICE_UNSET
Magic number to denote that the price has not been initialized.- See Also:
- Constant Field Values
-
PRICE_INVALID
public static final int PRICE_INVALID
Magic number for price to denote an invalid item.- See Also:
- Constant Field Values
-
price
private int price
The current valuation by the natives.
-
haggleCount
private int haggleCount
The number of haggling rounds.
-
HAGGLE_COUNT_TAG
private static final java.lang.String HAGGLE_COUNT_TAG
- See Also:
- Constant Field Values
-
PRICE_TAG
private static final java.lang.String PRICE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NativeTradeItem
public NativeTradeItem(Game game, Player source, Player destination, Goods goods)
Creates a newNativeTradeItem
instance.- Parameters:
game
- The enclosingGame
.source
- The sourcePlayer
.destination
- The destinationPlayer
.goods
- TheGoods
to trade.
-
NativeTradeItem
public NativeTradeItem(NativeTradeItem nti)
Copy a newNativeTradeItem
instance. Used by readList.- Parameters:
nti
- TheNativeTradeItem
to copy.
-
NativeTradeItem
public NativeTradeItem(Game game, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newNativeTradeItem
instance.- Parameters:
game
- The enclosingGame
.xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is an error reading the stream.
-
-
Method Detail
-
priceIsSet
public boolean priceIsSet()
Has a price been set for this item?- Returns:
- True if a price has been set.
-
priceIsValid
public boolean priceIsValid()
Is the price valid for trade.- Returns:
- True if the price is positive.
-
getPrice
public int getPrice()
Get the price for this item.- Returns:
- The current price.
-
setPrice
public void setPrice(int price)
Set the price for this item.- Parameters:
price
- The new price.
-
getHaggleCount
public int getHaggleCount()
Get the haggle count for this item.- Returns:
- The current haggle count.
-
setHaggleCount
public void setHaggleCount(int haggleCount)
Set the haggle count for this item.- Parameters:
haggleCount
- The new haggle count.
-
goodsMatcher
public java.util.function.Predicate<NativeTradeItem> goodsMatcher()
Get a predicate to match this native trade item by its goods.- Returns:
- A suitable
Predicate
.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classGoodsTradeItem
- 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 classTradeItem
- 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 classTradeItem
- 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.- Overrides:
getXMLTagName
in classGoodsTradeItem
- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classGoodsTradeItem
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classGoodsTradeItem
-
toString
public java.lang.String toString()
- Overrides:
toString
in classGoodsTradeItem
-
-