Package net.sf.freecol.common.model
Class Goods
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.AbstractGoods
-
- net.sf.freecol.common.model.Goods
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Locatable
,Named
,Ownable
,ObjectWithId
public class Goods extends AbstractGoods implements Locatable, Ownable
Represents locatable goods of a specified type and amount. Use AbstractGoods to represent abstract or potential goods that need not be present in any particular location.- See Also:
AbstractGoods
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
AMOUNT_TAG
private Game
game
The game containing these goods.private Location
location
Where the goods are.private static java.lang.String
LOCATION_TAG
private static java.util.logging.Logger
logger
static java.lang.String
TAG
private static java.lang.String
TYPE_TAG
-
Fields inherited from class net.sf.freecol.common.model.AbstractGoods
amount, ascendingAmountComparator, descendingAmountComparator, type
-
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 Modifier Constructor Description private
Goods(Game game)
Fundamental constructor.Goods(Game game, java.lang.String id)
Creates a standardGoods
-instance given the place where the goods is.Goods(Game game, FreeColXMLReader xr)
Creates a newGoods
instance.Goods(Game game, Location location, GoodsType type, int amount)
Creates a standardGoods
-instance given the place where the goods is.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
adjustAmount()
If the amount of goods is greater than the container can hold, then this method adjusts the amount to the maximum amount possible.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.boolean
equals(java.lang.Object o)
FreeColObject
getDisplayObject()
Get an object to display when showing the user messages for this object.Game
getGame()
Gets the game this object belongs to.Location
getLocation()
Gets the location of thisLocatable
.Player
getOwner()
Gets the owner of thisOwnable
.int
getSpaceTaken()
Gets the number of cargo slots consumed when thisLocatable
if put onto a carrier.Specification
getSpecification()
Get the specification.Tile
getTile()
Get theTile
where thisLocatable
is located, ornull
if it is inEurope
.java.lang.String
getXMLTagName()
Get the serialization tag for this object.int
hashCode()
boolean
isInEurope()
Is this locatable in Europe.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
setGame(Game game)
Sets the game object this object belongs to.boolean
setLocation(Location location)
Sets the location for thisLocatable
.void
setOwner(Player p)
Sets the owner of thisOwnable
.void
setSpecification(Specification specification)
Sets the specification for this object.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.AbstractGoods
evaluateFor, getAbstractLabel, getAmount, getCount, getLabel, getLabel, getNameKey, getType, isFoodType, isPositive, isStorable, matches, setAmount, setType, toFullString, toString
-
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, getClassIndex, getDefenceModifiers, 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, readFromXML, 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
-
game
private final Game game
The game containing these goods. It would be nice to make this a FreeColGameObject, but then it could not extend AbstractGoods.
-
location
private Location location
Where the goods are. This should always be non-null except for the really special case of goods that are in the process of being looted from a ship --- we can not use the ship as it is removed/disposed at once while the looting is still being resolved.
-
AMOUNT_TAG
private static final java.lang.String AMOUNT_TAG
- See Also:
- Constant Field Values
-
LOCATION_TAG
private static final java.lang.String LOCATION_TAG
- See Also:
- Constant Field Values
-
TYPE_TAG
private static final java.lang.String TYPE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Goods
private Goods(Game game)
Fundamental constructor.- Parameters:
game
- The enclosingGame
.
-
Goods
public Goods(Game game, java.lang.String id)
Creates a standardGoods
-instance given the place where the goods is. Used by Game.newInstance.- Parameters:
game
- The enclosingGame
.id
- The identifier (ignored, type gives identifier here).
-
Goods
public Goods(Game game, Location location, GoodsType type, int amount)
Creates a standardGoods
-instance given the place where the goods is. This constructor only asserts that the game and that the location (if given) can store goods. The goods will not be added to the location (use Location.add for this).- Parameters:
game
- The enclosingGame
.location
- TheLocation
of the goods (may be null).type
- TheGoodsType
for the goods.amount
- The amount of the goods.
-
Goods
public Goods(Game game, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newGoods
instance.- Parameters:
game
- The enclosingGame
.xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if an error occurs
-
-
Method Detail
-
adjustAmount
public void adjustAmount()
If the amount of goods is greater than the container can hold, then this method adjusts the amount to the maximum amount possible.
-
getLocation
public Location getLocation()
Gets the location of thisLocatable
.- Specified by:
getLocation
in interfaceLocatable
- Returns:
- The location of this
Locatable
.
-
setLocation
public boolean setLocation(Location location)
Description copied from interface:Locatable
Sets the location for thisLocatable
.- Specified by:
setLocation
in interfaceLocatable
- Parameters:
location
- The Settlement that is located on this Tile- Returns:
- True if the location change succeeds.
-
isInEurope
public boolean isInEurope()
Is this locatable in Europe.- Specified by:
isInEurope
in interfaceLocatable
- Returns:
- True if the
Locatable
is inEurope
.
-
getTile
public Tile getTile()
Get theTile
where thisLocatable
is located, ornull
if it is inEurope
.
-
getSpaceTaken
public int getSpaceTaken()
Gets the number of cargo slots consumed when thisLocatable
if put onto a carrier.- Specified by:
getSpaceTaken
in interfaceLocatable
- Returns:
- The number of cargo slots required.
-
getOwner
public Player getOwner()
Gets the owner of thisOwnable
.
-
setOwner
public void setOwner(Player p)
Sets the owner of thisOwnable
.
-
getSpecification
public Specification getSpecification()
Get the specification.- Overrides:
getSpecification
in classFreeColObject
- Returns:
- The
Specification
used by this object.
-
setSpecification
public void setSpecification(Specification specification)
Sets the specification for this object.- Overrides:
setSpecification
in classFreeColObject
- Parameters:
specification
- TheSpecification
to use.
-
getGame
public Game getGame()
Gets the game this object belongs to.- Overrides:
getGame
in classFreeColObject
- Returns:
- The
Game
this object belongs to.
-
setGame
public void setGame(Game game)
Sets the game object this object belongs to.- Overrides:
setGame
in classFreeColObject
- Parameters:
game
- TheGame
to set.
-
getDisplayObject
public FreeColObject getDisplayObject()
Get an object to display when showing the user messages for this object. Example: If this object is a Building, the object to display will be the BuildingType.- Overrides:
getDisplayObject
in classFreeColObject
- Returns:
- A suitable
FreeColObject
to display, defaults to this.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classAbstractGoods
- 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 classFreeColObject
- 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 classAbstractGoods
- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classAbstractGoods
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractGoods
-
-