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.StringAMOUNT_TAGprivate GamegameThe game containing these goods.private LocationlocationWhere the goods are.private static java.lang.StringLOCATION_TAGprivate static java.util.logging.Loggerloggerstatic java.lang.StringTAGprivate static java.lang.StringTYPE_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 privateGoods(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 newGoodsinstance.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 voidadjustAmount()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.booleanequals(java.lang.Object o)FreeColObjectgetDisplayObject()Get an object to display when showing the user messages for this object.GamegetGame()Gets the game this object belongs to.LocationgetLocation()Gets the location of thisLocatable.PlayergetOwner()Gets the owner of thisOwnable.intgetSpaceTaken()Gets the number of cargo slots consumed when thisLocatableif put onto a carrier.SpecificationgetSpecification()Get the specification.TilegetTile()Get theTilewhere thisLocatableis located, ornullif it is inEurope.java.lang.StringgetXMLTagName()Get the serialization tag for this object.inthashCode()booleanisInEurope()Is this locatable in Europe.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidsetGame(Game game)Sets the game object this object belongs to.booleansetLocation(Location location)Sets the location for thisLocatable.voidsetOwner(Player p)Sets the owner of thisOwnable.voidsetSpecification(Specification specification)Sets the specification for this object.protected voidwriteAttributes(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- TheLocationof the goods (may be null).type- TheGoodsTypefor the goods.amount- The amount of the goods.
-
Goods
public Goods(Game game, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newGoodsinstance.- Parameters:
game- The enclosingGame.xr- TheFreeColXMLReaderto 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:
getLocationin interfaceLocatable- Returns:
- The location of this
Locatable.
-
setLocation
public boolean setLocation(Location location)
Description copied from interface:LocatableSets the location for thisLocatable.- Specified by:
setLocationin 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:
isInEuropein interfaceLocatable- Returns:
- True if the
Locatableis inEurope.
-
getTile
public Tile getTile()
Get theTilewhere thisLocatableis located, ornullif it is inEurope.
-
getSpaceTaken
public int getSpaceTaken()
Gets the number of cargo slots consumed when thisLocatableif put onto a carrier.- Specified by:
getSpaceTakenin 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:
getSpecificationin classFreeColObject- Returns:
- The
Specificationused by this object.
-
setSpecification
public void setSpecification(Specification specification)
Sets the specification for this object.- Overrides:
setSpecificationin classFreeColObject- Parameters:
specification- TheSpecificationto use.
-
getGame
public Game getGame()
Gets the game this object belongs to.- Overrides:
getGamein classFreeColObject- Returns:
- The
Gamethis object belongs to.
-
setGame
public void setGame(Game game)
Sets the game object this object belongs to.- Overrides:
setGamein classFreeColObject- Parameters:
game- TheGameto 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:
getDisplayObjectin classFreeColObject- Returns:
- A suitable
FreeColObjectto display, defaults to this.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classAbstractGoods- Type Parameters:
T- TheFreeColObjectsubclass 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:
writeAttributesin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
readAttributesin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classAbstractGoods- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classAbstractGoods
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractGoods
-
-