net.sf.freecol.common.model
Class UnitLocation

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
All Implemented Interfaces:
Location
Direct Known Subclasses:
Europe, GoodsLocation, HighSeas, Tile, WorkLocation

public abstract class UnitLocation
extends FreeColGameObject
implements Location

The UnitLocation is a place where a Unit can be put. The UnitLocation can not store any other Locatables, such as Goods, or TileItems.

See Also:
Locatable

Nested Class Summary
static class UnitLocation.NoAddReason
           
 
Field Summary
private static java.util.logging.Logger logger
           
private  java.util.List<Unit> units
          The Units present in this Location.
 
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 UnitLocation()
           
  UnitLocation(Game game)
          Creates a new UnitLocation instance.
  UnitLocation(Game game, java.lang.String id)
          Creates a new UnitLocation instance.
  UnitLocation(Game game, javax.xml.stream.XMLStreamReader in)
          Creates a new UnitLocation instance.
 
Method Summary
 boolean add(Locatable locatable)
          Adds a Locatable to this Location.
 boolean canAdd(Locatable locatable)
          Checks whether or not the specified locatable may be added to this Location.
 boolean contains(Locatable locatable)
          Checks if this Location contains the specified Locatable.
 void dispose()
          Dispose of this UnitLocation.
 java.util.List<FreeColGameObject> disposeList()
          Removes all references to this object.
 Colony getColony()
          Returns the Colony this Location is located in, or null if it is not located in a colony.
 GoodsContainer getGoodsContainer()
          Gets the GoodsContainer this Location use for storing it's goods, or null if the Location cannot store any goods.
 StringTemplate getLocationName()
          Returns the name of this location.
 StringTemplate getLocationNameFor(Player player)
          Returns the name of this location for a particular player.
 UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
          Gets the reason why a given Locatable can not be added to this Location.
 Settlement getSettlement()
          Returns the Settlement this Location is located in, or null if it is not located in any settlement.
 int getSpaceTaken()
          Gets the current space taken by the units in this location.
 Tile getTile()
          Returns the Tile where this Location is located, or null if it is not located on a Tile.
 int getUnitCapacity()
          Gets the maximum number of Units this Location can hold.
 int getUnitCount()
          Returns the number of Units at this Location.
 java.util.Iterator<Unit> getUnitIterator()
          Gets a Iterator of every Unit directly located on this Location.
 java.util.List<Unit> getUnitList()
          Gets the Units present at this Location.
 boolean isEmpty()
          Returns true if there are no Units present in this Location.
 boolean isFull()
          Is this unit location full?
protected  void readChild(javax.xml.stream.XMLStreamReader in)
          Reads a single child object.
protected  void readChildren(javax.xml.stream.XMLStreamReader in)
          Reads the children of this object from an XML stream.
 boolean remove(Locatable locatable)
          Removes a Locatable from this Location.
protected  void writeAttributes(javax.xml.stream.XMLStreamWriter out)
          Write the attributes of this object to a stream.
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.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

units

private final java.util.List<Unit> units
The Units present in this Location.

Constructor Detail

UnitLocation

protected UnitLocation()

UnitLocation

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

Parameters:
game - a Game value

UnitLocation

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

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

UnitLocation

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

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

getUnitCapacity

public int getUnitCapacity()
Gets the maximum number of Units this Location can hold. To be overridden by subclasses.

Returns:
Integer.MAX_VALUE, denoting no effective limit.

getSpaceTaken

public int getSpaceTaken()
Gets the current space taken by the units in this location.

Returns:
The sum of the space taken by the units in this location.

getLocationName

public StringTemplate getLocationName()
Returns the name of this location.

Specified by:
getLocationName in interface Location
Returns:
The name of this location.

getLocationNameFor

public StringTemplate getLocationNameFor(Player player)
Returns the name of this location for a particular player.

Specified by:
getLocationNameFor in interface Location
Parameters:
player - The Player to return the name for.
Returns:
The name of this location.

canAdd

public boolean canAdd(Locatable locatable)
Checks whether or not the specified locatable may be added to this Location.

Specified by:
canAdd in interface Location
Parameters:
locatable - The Locatable to add.
Returns:
The result.

getNoAddReason

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

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
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
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
Parameters:
locatable - The Locatable to test the presence of.
Returns:
  • true if the specified Locatable is on this Location and
  • false otherwise.

getUnitCount

public int getUnitCount()
Returns the number of Units at this Location.

Specified by:
getUnitCount in interface Location
Returns:
The number of Units at this Location.

isEmpty

public boolean isEmpty()
Returns true if there are no Units present in this Location.

Returns:
a boolean value

isFull

public boolean isFull()
Is this unit location full?

Returns:
True if this location is full.

getUnitList

public java.util.List<Unit> getUnitList()
Gets the Units present at this Location.

Specified by:
getUnitList in interface Location
Returns:
A copy of the list containing the Units present at this location.

getUnitIterator

public java.util.Iterator<Unit> getUnitIterator()
Gets a Iterator of every Unit directly located on this Location.

Specified by:
getUnitIterator in interface Location
Returns:
The Iterator.

getTile

public Tile getTile()
Returns the Tile where this Location is located, or null if it is not located on a Tile.

Specified by:
getTile in interface Location
Returns:
a Tile value

getColony

public Colony getColony()
Returns the Colony this Location is located in, or null if it is not located in a colony.

Specified by:
getColony in interface Location
Returns:
A Colony

getSettlement

public Settlement getSettlement()
Returns the Settlement this Location is located in, or null if it is not located in any settlement.

Specified by:
getSettlement in interface Location
Returns:
a Settlement value

getGoodsContainer

public 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
Returns:
A GoodsContainer value

disposeList

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

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

dispose

public void dispose()
Dispose of this UnitLocation.

Overrides:
dispose in class FreeColGameObject

writeAttributes

protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                        throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden by any object that uses the toXML(XMLStreamWriter, String) call.

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

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.

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

readChildren

protected void readChildren(javax.xml.stream.XMLStreamReader in)
                     throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.

Overrides:
readChildren in class FreeColObject
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

readChild

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

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