Package net.sf.freecol.common.model
Class FreeColGameObject
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
- Direct Known Subclasses:
AbstractMission
,DiplomaticTrade
,Game
,GoodsContainer
,Map
,Market
,MarketData
,Monarch
,NativeTrade
,Player
,Region
,TileItem
,TileItemContainer
,TradeItem
,TradeRoute
,TradeRouteStop
,UnitLocation
public abstract class FreeColGameObject extends FreeColObject
The superclass of all game objects in FreeCol. All FreeColGameObjects need to be able to refer to the game they belong to. Therefore, the game attribute must not be null, except in the special case where a Game is being initially created. Most FreeColGameObjects are intended to be accessible by identifier (@see Game#getFreeColObject) but some are not, and should override isInternable to return false.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
disposed
Has this object been disposed?private static int
FREECOL_GAME_OBJECT_CLASS_INDEX
Default class index for FreeColGameObjects.private Game
game
The game this object belongs to.protected boolean
initialized
Has this object been initialized?private static java.util.logging.Logger
logger
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FreeColGameObject()
Special constructor solely for initializing a Game.FreeColGameObject(Game game)
Create and initialize a newFreeColGameObject
.FreeColGameObject(Game game, java.lang.String id)
Creates a newFreeColGameObject
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Constants.IntegrityType
checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.void
dispose()
Destroy this object and all its parts, releasing resources and removing references.void
disposeResources()
Dispose of the resources of this object, and finally remove it from the game.boolean
equals(java.lang.Object o)
void
fundamentalDispose()
Low level base dispose, removing the object from the game.int
getClassIndex()
Accessor for the class index.java.util.stream.Stream<FreeColGameObject>
getDisposables()
Collect this object and all its subparts that should be disposed of when this object goes away.Game
getGame()
Gets the game this object belongs to.FreeColGameObject
getLinkTarget(Player player)
Get a suitable game object to use as a clickable link in messages to a player.Specification
getSpecification()
Get the specification.int
hashCode()
void
intern()
Intern this object.void
internId(java.lang.String newId)
Sets the unique identifier of this object and registers it in itsGame
with that identifier, i.e.boolean
isDisposed()
Has this object been disposed?boolean
isInitialized()
Has this object been initialized?boolean
isInternable()
Should this object be interned into its Game? Usually true, but there are some special containers that have to be FCGOs but are unsuitable to be interned.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
readFromXML(FreeColXMLReader xr)
Initializes this object from an XML-representation of this object, unless the PARTIAL_ATTRIBUTE tag is present which indicates a partial update of an existing object.void
setGame(Game game)
Sets the game object this object belongs to.void
setSpecification(Specification specification)
Sets the specification for this object.-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, getXMLTagName, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readChild, readChildren, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toString, toXML, toXML, toXMLPartial, toXMLPartial, writeAttributes, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
FREECOL_GAME_OBJECT_CLASS_INDEX
private static final int FREECOL_GAME_OBJECT_CLASS_INDEX
Default class index for FreeColGameObjects.- See Also:
- Constant Field Values
-
game
private Game game
The game this object belongs to.
-
disposed
private boolean disposed
Has this object been disposed?
-
initialized
protected boolean initialized
Has this object been initialized?
-
-
Constructor Detail
-
FreeColGameObject
protected FreeColGameObject()
Special constructor solely for initializing a Game. Do *not* call internId as the Game is not ready to register objects.
-
FreeColGameObject
public FreeColGameObject(Game game)
Create and initialize a newFreeColGameObject
.- Parameters:
game
- The enclosingGame
.
-
FreeColGameObject
public FreeColGameObject(Game game, java.lang.String id)
Creates a newFreeColGameObject
. If an identifier is supplied, use that, otherwise leave it undefined. This routine should be used when we know that the object will need further initialization.- Parameters:
game
- The enclosingGame
.id
- The object identifier.
-
-
Method Detail
-
internId
public final void internId(java.lang.String newId)
Sets the unique identifier of this object and registers it in itsGame
with that identifier, i.e. "intern" this object.- Parameters:
newId
- The unique identifier of this object.
-
intern
public void intern()
Intern this object.
-
isInitialized
public final boolean isInitialized()
Has this object been initialized?- Returns:
- True if this object is initialized.
-
isDisposed
public final boolean isDisposed()
Has this object been disposed?- Returns:
- True if this object has been disposed.
- See Also:
dispose()
-
dispose
public final void dispose()
Destroy this object and all its parts, releasing resources and removing references.
-
fundamentalDispose
public final void fundamentalDispose()
Low level base dispose, removing the object from the game.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColObject
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
isInternable
public boolean isInternable()
Should this object be interned into its Game? Usually true, but there are some special containers that have to be FCGOs but are unsuitable to be interned. These classes will override this routine.- Returns:
- True if this object should be interned.
-
getDisposables
public java.util.stream.Stream<FreeColGameObject> getDisposables()
Collect this object and all its subparts that should be disposed of when this object goes away. Overriding routines should call upwards towards this routine, arranging that the object itself is last.- Returns:
- A stream of
FreeColGameObject
s to dispose of.
-
disposeResources
public void disposeResources()
Dispose of the resources of this object, and finally remove it from the game. To be extended by subclasses, but they must tail call up towards this.
-
getLinkTarget
public FreeColGameObject getLinkTarget(Player player)
Get a suitable game object to use as a clickable link in messages to a player. Objects do not have links by default, hence the null return here. However, for example, a player's colony should return itself as a link target.- Parameters:
player
- ThePlayer
to make a link for.- Returns:
- A suitable link target if available, although usually null.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.- Parameters:
fix
- If true, fix problems if possible.lb
- ALogBuilder
to log to.- Returns:
- A suitable
IntegrityType
.
-
getSpecification
public Specification getSpecification()
Get the specification.- Overrides:
getSpecification
in classFreeColObject
- Returns:
- The
Specification
used by this object.
-
setSpecification
public void setSpecification(Specification specification)
Sets the specification for this object.- Overrides:
setSpecification
in classFreeColObject
- Parameters:
specification
- TheSpecification
to use.
-
getGame
public final Game getGame()
Gets the game this object belongs to.- Overrides:
getGame
in classFreeColObject
- Returns:
- The
Game
this object belongs to.
-
setGame
public final void setGame(Game game)
Sets the game object this object belongs to.- Overrides:
setGame
in classFreeColObject
- Parameters:
game
- TheGame
to set.
-
getClassIndex
public int getClassIndex()
Accessor for the class index.- Overrides:
getClassIndex
in classFreeColObject
- Returns:
- The class index used by
ClientOptions
.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readFromXML
public void readFromXML(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Initializes this object from an XML-representation of this object, unless the PARTIAL_ATTRIBUTE tag is present which indicates a partial update of an existing object.- Overrides:
readFromXML
in classFreeColObject
- Parameters:
xr
- The input stream with the XML.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems reading the stream.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classFreeColObject
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classFreeColObject
-
-