net.sf.freecol.common.model
Class GoodsContainer

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.GoodsContainer

public class GoodsContainer
extends FreeColGameObject

Contains goods and can be used by a Location to make certain tasks easier.


Field Summary
static int CARGO_SIZE
           
static java.lang.String OLD_STORED_GOODS_TAG
           
static java.lang.String STORED_GOODS_TAG
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
GoodsContainer(Game game, Location parent)
          Creates an empty GoodsContainer.
GoodsContainer(Game game, Location parent, org.w3c.dom.Element e)
          Initiates a new GoodsContainer from an Element.
GoodsContainer(Game game, Location parent, javax.xml.stream.XMLStreamReader in)
          Initiates a new GoodsContainer from an Element.
 
Method Summary
 void addGoods(AbstractGoods g)
          Adds a Goods to this containter.
 void addGoods(GoodsType type, int amount)
          Adds the given amount of the given type of goods.
 void cleanAndReport()
          Removes goods exceeding limit and reports on goods exceeding levels.
 boolean contains(Goods g)
          Checks if the specified Goods is in this container.
 java.util.List<Goods> getCompactGoods()
          Gets an Iterator of every Goods in this GoodsContainer.
 java.util.List<Goods> getFullGoods()
          Gets an Iterator of every Goods in this GoodsContainer.
 java.util.List<Goods> getGoods()
          Returns an ArrayList containing all Goods in this GoodsContainer.
 Goods getGoods(GoodsType goodsType)
           
 int getGoodsCount()
          Gets the number of goods-packages.
 int getGoodsCount(GoodsType type)
          Returns the amount of one type of Goods in this container.
 java.util.Iterator<Goods> getGoodsIterator()
          Gets an Iterator of every Goods in this GoodsContainer.
 int getOldGoodsCount(GoodsType type)
          Returns the amount of one type of Goods at the beginning of the turn.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean hasReachedCapacity(int amount)
          Checks if any storable type of goods has reached the given amount.
 void removeAbove(int newAmount)
          Removes all goods above given amount, provided that the goods are storable and do not ignore warehouse limits.
 void removeAll()
          Removes all goods.
 Goods removeGoods(AbstractGoods g)
          Removes Goods from this containter.
 Goods removeGoods(GoodsType type)
           
 Goods removeGoods(GoodsType type, int amount)
          Removes the given amount of the given type of goods.
 void saveState()
          Prepares this GoodsContainer for a new turn.
 java.lang.String toString()
          Creates a String representation of this GoodsContainer.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
addToRemoveElement, dispose, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, setGame, setId, toSavedXML, toXML, updateFreeColGameObject, updateID
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CARGO_SIZE

public static final int CARGO_SIZE
See Also:
Constant Field Values

STORED_GOODS_TAG

public static final java.lang.String STORED_GOODS_TAG
See Also:
Constant Field Values

OLD_STORED_GOODS_TAG

public static final java.lang.String OLD_STORED_GOODS_TAG
See Also:
Constant Field Values
Constructor Detail

GoodsContainer

public GoodsContainer(Game game,
                      Location parent)
Creates an empty GoodsContainer.

Parameters:
game - The Game in which this GoodsContainer belong.
parent - The Location this GoodsContainer will be containg goods for.

GoodsContainer

public GoodsContainer(Game game,
                      Location parent,
                      javax.xml.stream.XMLStreamReader in)
               throws javax.xml.stream.XMLStreamException
Initiates a new GoodsContainer from an Element.

Parameters:
game - The Game in which this GoodsContainer belong.
parent - The object using this GoodsContainer for storing it's goods.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

GoodsContainer

public GoodsContainer(Game game,
                      Location parent,
                      org.w3c.dom.Element e)
Initiates a new GoodsContainer from an Element.

Parameters:
game - The Game in which this GoodsContainer belong.
parent - The object using this GoodsContainer for storing it's goods.
e - An XML-element that will be used to initialize this object.
Method Detail

addGoods

public void addGoods(AbstractGoods g)
Adds a Goods to this containter.

Parameters:
g - The Goods to add to this container.

addGoods

public void addGoods(GoodsType type,
                     int amount)
Adds the given amount of the given type of goods.

Parameters:
type - The type of goods to add.
amount - The type of amount to add.

removeGoods

public Goods removeGoods(AbstractGoods g)
Removes Goods from this containter.

Parameters:
g - The Goods to remove from this container.

removeGoods

public Goods removeGoods(GoodsType type)

removeGoods

public Goods removeGoods(GoodsType type,
                         int amount)
Removes the given amount of the given type of goods.

Parameters:
type - The type of goods to remove.
amount - The type of amount to remove.
Returns:
A Goods with the requested or available amount that has been removed

removeAbove

public void removeAbove(int newAmount)
Removes all goods above given amount, provided that the goods are storable and do not ignore warehouse limits.

Parameters:
newAmount - The treshold.

removeAll

public void removeAll()
Removes all goods.


hasReachedCapacity

public boolean hasReachedCapacity(int amount)
Checks if any storable type of goods has reached the given amount.

Parameters:
amount - The amount.
Returns:
true if any type of goods, except for Goods.FOOD, has reached the given amount.

contains

public boolean contains(Goods g)
Checks if the specified Goods is in this container.

Parameters:
g - The Goods to test the presence of.
Returns:
The result.

getGoodsCount

public int getGoodsCount(GoodsType type)
Returns the amount of one type of Goods in this container.

Parameters:
type - The type of Goods being looked for in this container.
Returns:
The amount of this type of Goods in this container.

getOldGoodsCount

public int getOldGoodsCount(GoodsType type)
Returns the amount of one type of Goods at the beginning of the turn.

Parameters:
type - The type of Goods being looked for in this container.
Returns:
The amount of this type of Goods in this container. at the beginning of the turn

getGoods

public Goods getGoods(GoodsType goodsType)

getGoodsCount

public int getGoodsCount()
Gets the number of goods-packages. A goods package contain between 1-CARGO_SIZE.

Returns:
The number of goods packages.

getGoodsIterator

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

Returns:
The Iterator.
See Also:
getCompactGoods()

getGoods

public java.util.List<Goods> getGoods()
Returns an ArrayList containing all Goods in this GoodsContainer. Each Goods has a maximum amount of CARGO_SIZE.

Returns:
The ArrayList.
See Also:
getGoodsIterator()

getCompactGoods

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

Returns:
The Iterator.
See Also:
getGoodsIterator()

getFullGoods

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

Returns:
The Iterator.
See Also:
getGoodsIterator()

saveState

public void saveState()
Prepares this GoodsContainer for a new turn.


cleanAndReport

public void cleanAndReport()
Removes goods exceeding limit and reports on goods exceeding levels.


getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Returns:
"goodsContainer".

toString

public java.lang.String toString()
Creates a String representation of this GoodsContainer.

Overrides:
toString in class FreeColGameObject
Returns:
The String