net.sf.freecol.common.model
Class GoodsLocation

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObject
          extended by net.sf.freecol.common.model.UnitLocation
              extended by net.sf.freecol.common.model.GoodsLocation
All Implemented Interfaces:
Location
Direct Known Subclasses:
Settlement

public abstract class GoodsLocation
extends UnitLocation

The GoodsLocation is a place where Units and Goods can be put. The GoodsLocation can not store any other Locatables, such as TileItems.

See Also:
Locatable

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
 
Field Summary
private  GoodsContainer goodsContainer
          Describe goodsContainer here.
private static java.util.logging.Logger logger
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
UNITS_TAG_NAME
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
protected GoodsLocation()
           
  GoodsLocation(Game game)
          Creates a new GoodsLocation instance.
  GoodsLocation(Game game, java.lang.String id)
          Creates a new GoodsLocation instance.
  GoodsLocation(Game game, javax.xml.stream.XMLStreamReader in)
          Creates a new GoodsLocation instance.
 
Method Summary
 boolean add(Locatable locatable)
          Adds a Locatable to this Location.
 boolean addGoods(AbstractGoods goods)
          Describe addGoods method here.
 boolean addGoods(GoodsType type, int amount)
          Describe addGoods method here.
 boolean contains(Locatable locatable)
          Checks if this Location contains the specified Locatable.
 void dispose()
          Dispose of this GoodsLocation.
 java.util.List<FreeColGameObject> disposeList()
          Removes all references to this object.
 java.util.List<Goods> getCompactGoods()
          Gets an List with every Goods in this Colony.
abstract  int getGoodsCapacity()
          Gets the maximum number of Goods this Location can hold.
 GoodsContainer getGoodsContainer()
          Gets the GoodsContainer this Location use for storing it's goods, or null if the Location cannot store any goods.
 int getGoodsCount(GoodsType type)
          Gets the amount of one type of Goods at this Settlement.
 java.util.Iterator<Goods> getGoodsIterator()
          Gets an Iterator of every Goods in this GoodsContainer.
 UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
          Gets the reason why a given Locatable can not be added to this Location.
 int getWarehouseCapacity()
          Gets the storage capacity of this settlement.
protected  void readChild(javax.xml.stream.XMLStreamReader in)
          Reads a single child object.
 boolean remove(Locatable locatable)
          Removes a Locatable from this Location.
 Goods removeGoods(AbstractGoods goods)
          Removes the given Goods from the Settlement.
 Goods removeGoods(GoodsType type)
          Removes all Goods of the given type from the Settlement.
 Goods removeGoods(GoodsType type, int amount)
          Removes a specified amount of a type of Goods from this Settlement.
 void setGoodsContainer(GoodsContainer newGoodsContainer)
          Set the GoodsContainer value.
protected  void writeChildren(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          Serialize the children of this UnitLocation, i.e.
 
Methods inherited from class net.sf.freecol.common.model.UnitLocation
canAdd, getColony, getLocationName, getLocationNameFor, getSettlement, getSpaceTaken, getTile, getUnitCapacity, getUnitCount, getUnitIterator, getUnitList, isEmpty, isFull, readChildren, writeAttributes
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, getXMLElementTagName, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toString, toXML, toXMLImpl, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeChildren
 
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
 

Field Detail

logger

private static final java.util.logging.Logger logger

goodsContainer

private GoodsContainer goodsContainer
Describe goodsContainer here.

Constructor Detail

GoodsLocation

protected GoodsLocation()

GoodsLocation

public GoodsLocation(Game game)
Creates a new GoodsLocation instance.

Parameters:
game - a Game value

GoodsLocation

public GoodsLocation(Game game,
                     javax.xml.stream.XMLStreamReader in)
              throws javax.xml.stream.XMLStreamException
Creates a new GoodsLocation instance.

Parameters:
game - a Game value
in - a XMLStreamReader value
Throws:
javax.xml.stream.XMLStreamException - if an error occurs

GoodsLocation

public GoodsLocation(Game game,
                     java.lang.String id)
Creates a new GoodsLocation instance.

Parameters:
game - a Game value
id - a String value
Method Detail

getGoodsCapacity

public abstract int getGoodsCapacity()
Gets the maximum number of Goods this Location can hold.

Returns:
the capacity for goods

getGoodsIterator

public java.util.Iterator<Goods> getGoodsIterator()
Gets an Iterator of every Goods in this GoodsContainer. Each Goods have a maximum amount of GoodsContainer.CARGO_SIZE.

Returns:
The Iterator.

getCompactGoods

public java.util.List<Goods> getCompactGoods()
Gets an List with every Goods in this Colony. There is only one Goods for each type of goods.

Returns:
The Iterator.

getNoAddReason

public UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
Gets the reason why a given Locatable can not be added to this Location.

Overrides:
getNoAddReason in class UnitLocation
Parameters:
locatable - The Locatable to test.
Returns:
The reason why adding would fail.

add

public boolean add(Locatable locatable)
Adds a Locatable to this Location.

Specified by:
add in interface Location
Overrides:
add in class UnitLocation
Parameters:
locatable - The Locatable to add to this Location.

remove

public boolean remove(Locatable locatable)
Removes a Locatable from this Location.

Specified by:
remove in interface Location
Overrides:
remove in class UnitLocation
Parameters:
locatable - The Locatable to remove from this Location.

contains

public boolean contains(Locatable locatable)
Checks if this Location contains the specified Locatable.

Specified by:
contains in interface Location
Overrides:
contains in class UnitLocation
Parameters:
locatable - The Locatable to test the presence of.
Returns:
  • true if the specified Locatable is on this Location and
  • false otherwise.

getGoodsContainer

public final GoodsContainer getGoodsContainer()
Gets the GoodsContainer this Location use for storing it's goods, or null if the Location cannot store any goods.

Specified by:
getGoodsContainer in interface Location
Overrides:
getGoodsContainer in class UnitLocation
Returns:
A GoodsContainer value

setGoodsContainer

public final void setGoodsContainer(GoodsContainer newGoodsContainer)
Set the GoodsContainer value.

Parameters:
newGoodsContainer - The new GoodsContainer value.

getWarehouseCapacity

public int getWarehouseCapacity()
Gets the storage capacity of this settlement.

Returns:
The storage capacity of this settlement.
See Also:
getGoodsCapacity()

removeGoods

public Goods removeGoods(GoodsType type,
                         int amount)
Removes a specified amount of a type of Goods from this Settlement.

Parameters:
type - The type of Goods to remove from this settlement.
amount - The amount of Goods to remove from this settlement.

removeGoods

public Goods removeGoods(AbstractGoods goods)
Removes the given Goods from the Settlement.

Parameters:
goods - a Goods value

removeGoods

public Goods removeGoods(GoodsType type)
Removes all Goods of the given type from the Settlement.

Parameters:
type - a GoodsType value

addGoods

public boolean addGoods(GoodsType type,
                        int amount)
Describe addGoods method here.

Parameters:
type - a GoodsType value
amount - an int value

addGoods

public boolean addGoods(AbstractGoods goods)
Describe addGoods method here.

Parameters:
goods - an AbstractGoods value

getGoodsCount

public int getGoodsCount(GoodsType type)
Gets the amount of one type of Goods at this Settlement.

Parameters:
type - The type of goods to look for.
Returns:
The amount of this type of Goods at this Location.

disposeList

public java.util.List<FreeColGameObject> disposeList()
Removes all references to this object.

Overrides:
disposeList in class UnitLocation
Returns:
A list of disposed objects.

dispose

public void dispose()
Dispose of this GoodsLocation.

Overrides:
dispose in class UnitLocation

writeChildren

protected void writeChildren(javax.xml.stream.XMLStreamWriter out,
                             Player player,
                             boolean showAll,
                             boolean toSavedGame)
                      throws javax.xml.stream.XMLStreamException
Serialize the children of this UnitLocation, i.e. the Units themselves.

Overrides:
writeChildren in class UnitLocation
Parameters:
out - a XMLStreamWriter value
player - a Player value
showAll - a boolean value
toSavedGame - a boolean value
Throws:
javax.xml.stream.XMLStreamException - if an error occurs

readChild

protected void readChild(javax.xml.stream.XMLStreamReader in)
                  throws javax.xml.stream.XMLStreamException
Reads a single child object. This method does calls readChild with a null specification parameter.

Overrides:
readChild in class UnitLocation
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if an error occurs