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
AGoodsLocationis a place whereUnits andGoodscan be put. It can not store any other Locatables, such asTileItems.- 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 GoodsContainergoodsContainerThe container for the goods.private static java.util.logging.Loggerlogger-
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 newGoodsLocationinstance.GoodsLocation(Game game, java.lang.String id)Creates a newGoodsLocationinstance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(Locatable locatable)Adds aLocatableto this Location.booleanaddGoods(java.util.List<AbstractGoods> goods)Adds a list of goods to this location.booleanaddGoods(AbstractGoods goods)Adds some goods to this location.booleanaddGoods(GoodsType type, int amount)Adds a specified amount of a type of goods to this location.booleancontains(Locatable locatable)Checks if thisLocationcontains the specifiedLocatable.booleancontainsGoods(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 intgetGoodsCapacity()Gets the maximum number ofGoodsthis Location can hold.GoodsContainergetGoodsContainer()Gets theGoodsContainerthisLocationuse for storing it's goods.intgetGoodsCount(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.NoAddReasongetNoAddReason(Locatable locatable)Gets the reason why a givenLocatablecan not be added to this Location.abstract voidinvalidateCache()Invalidate any cache dependent on the goods levels.static voidmoveGoods(GoodsLocation src, GoodsType goodsType, int amount, GoodsLocation dst)Move goods from one location to another.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.booleanremove(Locatable locatable)Removes aLocatablefrom this Location.voidremoveAll()Remove all the goods.GoodsremoveGoods(AbstractGoods goods)Removes the some goods from this location.GoodsremoveGoods(GoodsType type)Removes all Goods of the given type from this location.GoodsremoveGoods(GoodsType type, int amount)Removes a specified amount of a type of Goods from this location.voidsetGoodsContainer(GoodsContainer goodsContainer)protected voidwriteChildren(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 newGoodsLocationinstance.- Parameters:
game- The enclosingGame.
-
GoodsLocation
public GoodsLocation(Game game, java.lang.String id)
Creates a newGoodsLocationinstance.- 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- TheAbstractGoodsto 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 ofAbstractGoodsto 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- TheAbstractGoodsto 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- TheGoodsTypeto 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- TheGoodsTypeto 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 ofAbstractGoodsto 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 oneGoodsfor 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- TheGoodsTypeto move.amount- The amount of goods to move.dst- The newGoodsLocation.
-
add
public boolean add(Locatable locatable)
Adds aLocatableto this Location.- Specified by:
addin interfaceLocation- Overrides:
addin classUnitLocation- Parameters:
locatable- TheLocatableto add to this Location.- Returns:
- True if the locatable was added.
-
remove
public boolean remove(Locatable locatable)
Removes aLocatablefrom this Location.- Specified by:
removein interfaceLocation- Overrides:
removein classUnitLocation- Parameters:
locatable- TheLocatableto remove from this Location.- Returns:
- True if the locatable was removed.
-
contains
public boolean contains(Locatable locatable)
Checks if thisLocationcontains the specifiedLocatable.- Specified by:
containsin interfaceLocation- Overrides:
containsin classUnitLocation- Parameters:
locatable- TheLocatableto test the presence of.- Returns:
- True if the locatable is present at this location.
-
getGoodsContainer
public final GoodsContainer getGoodsContainer()
Gets theGoodsContainerthisLocationuse for storing it's goods.- Specified by:
getGoodsContainerin interfaceLocation- Overrides:
getGoodsContainerin classUnitLocation- Returns:
- The
GoodsContainerornullif theLocationcannot store any goods.
-
getNoAddReason
public UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
Gets the reason why a givenLocatablecan 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:
getNoAddReasonin classUnitLocation- Parameters:
locatable- TheLocatableto 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 ofGoodsthis 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- TheGoodsTypeto 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:
getDisposablesin classUnitLocation- Returns:
- A stream of
FreeColGameObjects to dispose of.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classUnitLocation- Type Parameters:
T- TheFreeColObjectsubclass 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:
writeChildrenin classUnitLocation- Parameters:
xw- TheFreeColXMLWriterto 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:
readChildrenin classUnitLocation- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildin classUnitLocation- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
-