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 booleandisposedHas this object been disposed?private static intFREECOL_GAME_OBJECT_CLASS_INDEXDefault class index for FreeColGameObjects.private GamegameThe game this object belongs to.protected booleaninitializedHas this object been initialized?private static java.util.logging.Loggerlogger-
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 protectedFreeColGameObject()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.IntegrityTypecheckIntegrity(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.voiddispose()Destroy this object and all its parts, releasing resources and removing references.voiddisposeResources()Dispose of the resources of this object, and finally remove it from the game.booleanequals(java.lang.Object o)voidfundamentalDispose()Low level base dispose, removing the object from the game.intgetClassIndex()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.GamegetGame()Gets the game this object belongs to.FreeColGameObjectgetLinkTarget(Player player)Get a suitable game object to use as a clickable link in messages to a player.SpecificationgetSpecification()Get the specification.inthashCode()voidintern()Intern this object.voidinternId(java.lang.String newId)Sets the unique identifier of this object and registers it in itsGamewith that identifier, i.e.booleanisDisposed()Has this object been disposed?booleanisInitialized()Has this object been initialized?booleanisInternable()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 voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidreadFromXML(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.voidsetGame(Game game)Sets the game object this object belongs to.voidsetSpecification(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 itsGamewith 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:
copyInin classFreeColObject- Type Parameters:
T- TheFreeColObjectsubclass 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
FreeColGameObjects 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- ThePlayerto 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- ALogBuilderto log to.- Returns:
- A suitable
IntegrityType.
-
getSpecification
public Specification getSpecification()
Get the specification.- Overrides:
getSpecificationin classFreeColObject- Returns:
- The
Specificationused by this object.
-
setSpecification
public void setSpecification(Specification specification)
Sets the specification for this object.- Overrides:
setSpecificationin classFreeColObject- Parameters:
specification- TheSpecificationto use.
-
getGame
public final Game getGame()
Gets the game this object belongs to.- Overrides:
getGamein classFreeColObject- Returns:
- The
Gamethis object belongs to.
-
setGame
public final void setGame(Game game)
Sets the game object this object belongs to.- Overrides:
setGamein classFreeColObject- Parameters:
game- TheGameto set.
-
getClassIndex
public int getClassIndex()
Accessor for the class index.- Overrides:
getClassIndexin 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:
readAttributesin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readFromXMLin 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:
equalsin classFreeColObject
-
hashCode
public int hashCode()
- Overrides:
hashCodein classFreeColObject
-
-