net.sf.freecol.common.model
Class Goods

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.AbstractGoods
          extended by net.sf.freecol.common.model.Goods
All Implemented Interfaces:
Locatable, Ownable, Typed<GoodsType>

public class Goods
extends AbstractGoods
implements Locatable, Ownable, Typed<GoodsType>

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
static GoodsType BELLS
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType CIGARS
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType CLOTH
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType COATS
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType COTTON
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType CROSSES
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType FISH
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType FOOD
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType FURS
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType HAMMERS
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType HORSES
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType LUMBER
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType MUSKETS
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType ORE
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType RUM
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType SILVER
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType SUGAR
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType TOBACCO
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType TOOLS
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
static GoodsType TRADEGOODS
          Need to change various classes to use the specification in order to remove reliance on these static quick links.
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
Goods(Game game, org.w3c.dom.Element e)
          Creates a new Goods instance.
Goods(Game game, Location location, GoodsType type, int amount)
          Creates a standard Goods-instance given the place where the goods is.
Goods(Game game, javax.xml.stream.XMLStreamReader in)
          Creates a new Goods instance.
 
Method Summary
 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.
 Game getGame()
          Gets the game object this Goods belongs to.
 Location getLocation()
          Gets the location of this goods.
 Player getOwner()
          Gets the owner of this Ownable.
 int getSpaceTaken()
          Gets the amount of space this Goods take.
 Tile getTile()
          Returns the Tile where this Goods is located, or null if it's location is Europe.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
static void initialize(java.util.List<GoodsType> goodsList, int numberOfTypes)
          Initializes the important Types for quick reference - performed by Specification.java Should be softcoded as much as possible, and this should be amended later
 void loadOnto(Unit carrier)
          Loads the cargo onto a carrier that is on the same tile.
 void setLocation(Location location)
          Sets the location of the goods.
 void setOwner(Player p)
          Sets the owner of this Ownable.
 java.lang.String toString()
          Returns a textual representation of this object.
static java.lang.String toString(Goods goods)
           
static java.lang.String toString(GoodsType goodsType, int amount)
           
 void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
 void unload()
          Unload this Goods from a carrier into a colony.
 
Methods inherited from class net.sf.freecol.common.model.AbstractGoods
getAmount, getType, setAmount, setType
 
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, readFromXML, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.model.Typed
getType
 

Field Detail

FOOD

public static GoodsType FOOD
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


LUMBER

public static GoodsType LUMBER
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


ORE

public static GoodsType ORE
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


SILVER

public static GoodsType SILVER
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


HORSES

public static GoodsType HORSES
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


RUM

public static GoodsType RUM
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


CIGARS

public static GoodsType CIGARS
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


CLOTH

public static GoodsType CLOTH
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


COATS

public static GoodsType COATS
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


TRADEGOODS

public static GoodsType TRADEGOODS
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


TOOLS

public static GoodsType TOOLS
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


MUSKETS

public static GoodsType MUSKETS
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


FISH

public static GoodsType FISH
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


BELLS

public static GoodsType BELLS
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


CROSSES

public static GoodsType CROSSES
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


HAMMERS

public static GoodsType HAMMERS
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


SUGAR

public static GoodsType SUGAR
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


TOBACCO

public static GoodsType TOBACCO
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


FURS

public static GoodsType FURS
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.


COTTON

public static GoodsType COTTON
Need to change various classes to use the specification in order to remove reliance on these static quick links. Only the essential should have a quick link.

Constructor Detail

Goods

public Goods(Game game,
             Location location,
             GoodsType type,
             int amount)
Creates a standard Goods-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 Game in which this object belongs
location - The location of the goods (may be null)
type - The type of the goods.
amount - The amount of the goods.
Throws:
java.lang.IllegalArgumentException - if the location cannot store any goods.

Goods

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

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

Goods

public Goods(Game game,
             org.w3c.dom.Element e)
Creates a new Goods instance.

Parameters:
game - a Game value
e - an Element value
Method Detail

initialize

public static void initialize(java.util.List<GoodsType> goodsList,
                              int numberOfTypes)
Initializes the important Types for quick reference - performed by Specification.java Should be softcoded as much as possible, and this should be amended later

Parameters:
numberOfTypes - Initializer for NUMBER_OF_TYPES

getOwner

public Player getOwner()
Gets the owner of this Ownable.

Specified by:
getOwner in interface Ownable
Returns:
The Player controlling this Ownable.

setOwner

public void setOwner(Player p)
Sets the owner of this Ownable.

Specified by:
setOwner in interface Ownable
Parameters:
p - The Player that should take ownership of this Ownable.
Throws:
java.lang.UnsupportedOperationException - is always thrown by this method.

toString

public java.lang.String toString()
Returns a textual representation of this object.

Overrides:
toString in class AbstractGoods
Returns:
A String with the format:
AMOUNT GOODSTYPE

Example:
15 Cotton

toString

public static java.lang.String toString(Goods goods)

toString

public static java.lang.String toString(GoodsType goodsType,
                                        int amount)

getTile

public Tile getTile()
Returns the Tile where this Goods is located, or null if it's location is Europe.

Specified by:
getTile in interface Locatable
Returns:
The Tile where this Unit is located. Or null if its location is Europe.

setLocation

public void setLocation(Location location)
Sets the location of the goods.

Specified by:
setLocation in interface Locatable
Parameters:
location - The new location of the goods,

getLocation

public Location getLocation()
Gets the location of this goods.

Specified by:
getLocation in interface Locatable
Returns:
The location.

getSpaceTaken

public int getSpaceTaken()
Gets the amount of space this Goods take.

Specified by:
getSpaceTaken in interface Locatable
Returns:
The amount.

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.


loadOnto

public void loadOnto(Unit carrier)
Loads the cargo onto a carrier that is on the same tile. This method has the same effect as setLocation but ensures that: 1.) The given unit is at the same tile as the goods (including a check if transfering the goods in Europe makes sense) and 2.) that the source location of the goods is not null. checks that

Parameters:
carrier - The carrier onto which to the load the goods.
Throws:
java.lang.IllegalStateException - If the carrier is on another tile than this unit, the location of the goods is null or both carriers are not in port in Europe.

unload

public void unload()
Unload this Goods from a carrier into a colony. This method has the same effect as setLocation but performs checks whether the goods are on a carrier and whether the carrier is in a colony.

Throws:
java.lang.IllegalStateException - If the goods are not on a unit or the unit not in a colony.

getGame

public Game getGame()
Gets the game object this Goods belongs to.

Returns:
The Game.

toXMLImpl

public void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
               throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Overrides:
toXMLImpl in class AbstractGoods
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

getXMLElementTagName

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

Returns:
"goods".