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, Named, Ownable

public class Goods
extends AbstractGoods
implements Locatable, Ownable, Named

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
private  Game game
           
private  Location location
           
private static java.util.logging.Logger logger
           
 
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
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.
 void changeLocation(Location location)
          DO NOT USE, this is going away (into the server) soon.
 boolean equals(java.lang.Object obj)
           
 Game getGame()
          Gets the game object this Goods belongs to.
 StringTemplate getLabel(boolean sellable)
          Returns the name of this type of goods.
 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.
 int hashCode()
           
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 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.
 
Methods inherited from class net.sf.freecol.common.model.AbstractGoods
equals, getAmount, getNameKey, getType, setAmount, setType, writeAttributes
 
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, getSpecification, hasAbility, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, 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.Named
getNameKey
 

Field Detail

logger

private static java.util.logging.Logger logger

game

private Game game

location

private Location location
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

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)

getLabel

public StringTemplate getLabel(boolean sellable)
Returns the name of this type of goods.

Parameters:
sellable - Whether this type of goods is sellable;
Returns:
The name of this type of goods.

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.

getLocation

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

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

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.

changeLocation

public void changeLocation(Location location)
DO NOT USE, this is going away (into the server) soon.


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.


getGame

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

Returns:
The Game.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

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.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class AbstractGoods
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

getXMLElementTagName

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

Returns:
"goods".