Package net.sf.freecol.common.model
Class GoodsLocation
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.UnitLocation
-
- net.sf.freecol.common.model.GoodsLocation
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Location
,ObjectWithId
- Direct Known Subclasses:
Settlement
,Unit
public abstract class GoodsLocation extends UnitLocation
AGoodsLocation
is a place whereUnit
s andGoods
can be put. It can not store any other Locatables, such asTileItem
s.- See Also:
Locatable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
-
-
Field Summary
Fields Modifier and Type Field Description private GoodsContainer
goodsContainer
The container for the goods.private static java.util.logging.Logger
logger
-
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
-
Fields inherited from interface net.sf.freecol.common.model.Location
LOCATION_RANK_EUROPE, LOCATION_RANK_HIGHSEAS, LOCATION_RANK_NOWHERE
-
-
Constructor Summary
Constructors Constructor Description GoodsLocation(Game game)
Creates a newGoodsLocation
instance.GoodsLocation(Game game, java.lang.String id)
Creates a newGoodsLocation
instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
add(Locatable locatable)
Adds aLocatable
to this Location.boolean
addGoods(java.util.List<AbstractGoods> goods)
Adds a list of goods to this location.boolean
addGoods(AbstractGoods goods)
Adds some goods to this location.boolean
addGoods(GoodsType type, int amount)
Adds a specified amount of a type of goods to this location.boolean
contains(Locatable locatable)
Checks if thisLocation
contains the specifiedLocatable
.boolean
containsGoods(java.util.List<AbstractGoods> goods)
Does this location contain enough goods to satisfy a list of requirements?<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.java.util.List<Goods>
getCompactGoodsList()
Gets an list of all the goods in this location.java.util.stream.Stream<FreeColGameObject>
getDisposables()
Collect this object and all its subparts that should be disposed of when this object goes away.abstract int
getGoodsCapacity()
Gets the maximum number ofGoods
this Location can hold.GoodsContainer
getGoodsContainer()
Gets theGoodsContainer
thisLocation
use for storing it's goods.int
getGoodsCount(GoodsType type)
Gets the amount of one type of goods at this location.java.util.List<Goods>
getGoodsList()
Gets a list of all the goods in this location.UnitLocation.NoAddReason
getNoAddReason(Locatable locatable)
Gets the reason why a givenLocatable
can not be added to this Location.abstract void
invalidateCache()
Invalidate any cache dependent on the goods levels.static void
moveGoods(GoodsLocation src, GoodsType goodsType, int amount, GoodsLocation dst)
Move goods from one location to another.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.boolean
remove(Locatable locatable)
Removes aLocatable
from this Location.void
removeAll()
Remove all the goods.Goods
removeGoods(AbstractGoods goods)
Removes the some goods from this location.Goods
removeGoods(GoodsType type)
Removes all Goods of the given type from this location.Goods
removeGoods(GoodsType type, int amount)
Removes a specified amount of a type of Goods from this location.void
setGoodsContainer(GoodsContainer goodsContainer)
protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.UnitLocation
canAdd, clearUnitList, disposeResources, equipForRole, getCarrierForUnit, getColony, getFirstUnit, getIndianSettlement, getLastUnit, getLocationLabel, getLocationLabelFor, getNavalUnits, getSettlement, getSpaceTaken, getTile, getTotalUnitCount, getUnitCapacity, getUnitCount, getUnitList, getUnits, hasCarrierWithSpace, intern, isEmpty, isFull, moveToFront, priceGoods
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, equals, fundamentalDispose, getClassIndex, getGame, getLinkTarget, getSpecification, hashCode, internId, isDisposed, isInitialized, isInternable, readAttributes, 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, getXMLTagName, 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, toString, toXML, toXML, toXMLPartial, toXMLPartial, writeAttributes
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.freecol.common.model.Location
getId, getLocationImageKey, getRank, toShortString, up
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
goodsContainer
private GoodsContainer goodsContainer
The container for the goods.
-
-
Constructor Detail
-
GoodsLocation
public GoodsLocation(Game game)
Creates a newGoodsLocation
instance.- Parameters:
game
- The enclosingGame
.
-
GoodsLocation
public GoodsLocation(Game game, java.lang.String id)
Creates a newGoodsLocation
instance.- Parameters:
game
- The enclosingGame
.id
- The object identifier.
-
-
Method Detail
-
setGoodsContainer
public final void setGoodsContainer(GoodsContainer goodsContainer)
-
addGoods
public final boolean addGoods(AbstractGoods goods)
Adds some goods to this location.- Parameters:
goods
- TheAbstractGoods
to add.- Returns:
- True if the goods were added.
-
addGoods
public final boolean addGoods(java.util.List<AbstractGoods> goods)
Adds a list of goods to this location.- Parameters:
goods
- The list ofAbstractGoods
to add.- Returns:
- True if the goods were all added.
-
removeGoods
public final Goods removeGoods(AbstractGoods goods)
Removes the some goods from this location.- Parameters:
goods
- TheAbstractGoods
to remove.- Returns:
- The goods that was removed, which may be less than that requested, or null if none.
-
removeGoods
public final Goods removeGoods(GoodsType type)
Removes all Goods of the given type from this location.- Parameters:
type
- TheGoodsType
to remove.- Returns:
- The goods that was removed, or null if none.
-
getGoodsCount
public final int getGoodsCount(GoodsType type)
Gets the amount of one type of goods at this location.- Parameters:
type
- TheGoodsType
to look for.- Returns:
- The amount of goods.
-
containsGoods
public final boolean containsGoods(java.util.List<AbstractGoods> goods)
Does this location contain enough goods to satisfy a list of requirements?- Parameters:
goods
- A list ofAbstractGoods
to check.- Returns:
- True if the goods are all present.
-
removeAll
public final void removeAll()
Remove all the goods.
-
getGoodsList
public java.util.List<Goods> getGoodsList()
Gets a list of all the goods in this location. Each list member is limited to a maximum amount of CARGO_SIZE, thus there may be multiple entries with the same goods type.- Returns:
- A list of goods.
-
getCompactGoodsList
public java.util.List<Goods> getCompactGoodsList()
Gets an list of all the goods in this location. There is only oneGoods
for eachGoodsType
, thus the amount of goods may exceed CARGO_SIZE.- Returns:
- A list of goods.
-
moveGoods
public static void moveGoods(GoodsLocation src, GoodsType goodsType, int amount, GoodsLocation dst)
Move goods from one location to another.- Parameters:
src
- The sourceGoodsLocation
.goodsType
- TheGoodsType
to move.amount
- The amount of goods to move.dst
- The newGoodsLocation
.
-
add
public boolean add(Locatable locatable)
Adds aLocatable
to this Location.- Specified by:
add
in interfaceLocation
- Overrides:
add
in classUnitLocation
- Parameters:
locatable
- TheLocatable
to add to this Location.- Returns:
- True if the locatable was added.
-
remove
public boolean remove(Locatable locatable)
Removes aLocatable
from this Location.- Specified by:
remove
in interfaceLocation
- Overrides:
remove
in classUnitLocation
- Parameters:
locatable
- TheLocatable
to remove from this Location.- Returns:
- True if the locatable was removed.
-
contains
public boolean contains(Locatable locatable)
Checks if thisLocation
contains the specifiedLocatable
.- Specified by:
contains
in interfaceLocation
- Overrides:
contains
in classUnitLocation
- Parameters:
locatable
- TheLocatable
to test the presence of.- Returns:
- True if the locatable is present at this location.
-
getGoodsContainer
public final GoodsContainer getGoodsContainer()
Gets theGoodsContainer
thisLocation
use for storing it's goods.- Specified by:
getGoodsContainer
in interfaceLocation
- Overrides:
getGoodsContainer
in classUnitLocation
- Returns:
- The
GoodsContainer
ornull
if theLocation
cannot store any goods.
-
getNoAddReason
public UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
Gets the reason why a givenLocatable
can not be added to this Location. Be careful to test for unit presence last before success (NoAddReason.NONE) except perhaps for the capacity test, so that we can treat ALREADY_PRESENT as success in some cases (e.g. if the unit changes type --- does it still have a required skill?) FIXME: consider moving this up to Location?- Overrides:
getNoAddReason
in classUnitLocation
- Parameters:
locatable
- TheLocatable
to test.- Returns:
- The reason why adding would fail.
-
invalidateCache
public abstract void invalidateCache()
Invalidate any cache dependent on the goods levels.
-
getGoodsCapacity
public abstract int getGoodsCapacity()
Gets the maximum number ofGoods
this Location can hold.- Returns:
- The capacity for goods
-
addGoods
public boolean addGoods(GoodsType type, int amount)
Adds a specified amount of a type of goods to this location.- Parameters:
type
- TheGoodsType
to add.amount
- The amount of goods to add.- Returns:
- True if the goods were added.
-
removeGoods
public Goods removeGoods(GoodsType type, int amount)
Removes a specified amount of a type of Goods from this location.- Parameters:
type
- The type of goods to remove.amount
- The amount of goods to remove.- Returns:
- The goods that was removed, which may be less than that requested, or null if none.
-
getDisposables
public java.util.stream.Stream<FreeColGameObject> getDisposables()
Collect this object and all its subparts that should be disposed of when this object goes away. Overriding routines should call upwards towards this routine, arranging that the object itself is last.- Overrides:
getDisposables
in classUnitLocation
- Returns:
- A stream of
FreeColGameObject
s to dispose of.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classUnitLocation
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildren
in classUnitLocation
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
in classUnitLocation
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChild
protected void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChild
in classUnitLocation
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
-