Package net.sf.freecol.common.model
Class FreeColSpecObjectType
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.FreeColSpecObjectType
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Named
,ObjectWithId
- Direct Known Subclasses:
BuildableType
,Disaster
,Effect
,Event
,FoundingFather
,GoodsType
,Limit
,Nation
,NationType
,PlunderType
,ResourceType
,SettlementType
,Specification.Source
,TileImprovementType
,TileType
,TileTypeChange
,UnitChangeType
,UnitTypeChange
public abstract class FreeColSpecObjectType extends FreeColSpecObject implements Named
The base class for all types defined by the specification. It can be instantiated in order to provide a source for modifiers and abilities that are provided by the code rather than defined in the specification, such as the "artillery in the open" penalty. A FreeColSpecObjectType does not always need a reference to the specification. However, if it has attributes or children that are themselves FreeColSpecObjectTypes, then the specification must be set before the type is de-serialized, otherwise the identifiers therein can not be resolved. FreeColSpecObjectTypes can be abstract. Abstract types can be used to derive other types, but can not be instantiated. They will be removed from the Specification after it has loaded completely. Many FreeColSpecObjectTypes have ids, but some leaf types do not need them and there they may be omitted.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ABSTRACT_TAG
private boolean
abstractType
Whether the type is abstract, or can be instantiated.protected static java.lang.String
DELETE_TAG
static java.lang.String
EXTENDS_TAG
private FeatureContainer
featureContainer
The features of this game object type.private int
index
The index imposes a total ordering consistent with equals on each class extending FreeColSpecObjectType, but this ordering is nothing but the order in which the objects of the respective class were defined.static java.lang.String
PRESERVE_TAG
private ScopeContainer
scopeContainer
Scopes that might limit the action of this object to certain types of objects.-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FreeColSpecObjectType()
Deliberately empty constructor.FreeColSpecObjectType(java.lang.String id)
Create a simple FreeColSpecObjectType without a specification.FreeColSpecObjectType(java.lang.String id, Specification specification)
Create a FreeColSpecObjectType with a given identifier and specification.FreeColSpecObjectType(Specification specification)
Create a FreeColSpecObjectType with a given specification but no object identifier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addScope(Scope scope)
boolean
appliesTo(FreeColObject fco)
<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.void
copyScopes(java.util.Collection<Scope> scopes)
java.lang.String
getDescriptionKey()
Gets a string suitable for looking up the description of this object inMessages
.FeatureContainer
getFeatureContainer()
Gets the feature container for this object, if any.int
getIndex()
Gets the index of this FreeColSpecObjectType.java.lang.String
getNameKey()
Gets the name of this named object.java.util.List<Scope>
getScopeList()
java.util.stream.Stream<Scope>
getScopes()
boolean
isAbstractType()
Is this an abstract type?protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.void
removeScope(Scope scope)
protected void
setIndex(int index)
Sets the index of this FreeColSpecObjectType.java.lang.String
toString()
protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObject
getSpecification, setSpecification
-
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, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, getXMLTagName, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, toXML, toXML, toXMLPartial, toXMLPartial, writeAttributes
-
-
-
-
Field Detail
-
abstractType
private boolean abstractType
Whether the type is abstract, or can be instantiated.
-
featureContainer
private FeatureContainer featureContainer
The features of this game object type. Feature containers are created on demand.
-
scopeContainer
private ScopeContainer scopeContainer
Scopes that might limit the action of this object to certain types of objects.
-
index
private int index
The index imposes a total ordering consistent with equals on each class extending FreeColSpecObjectType, but this ordering is nothing but the order in which the objects of the respective class were defined. It is guaranteed to remain stable only for a particular revision of a particular specification.
-
ABSTRACT_TAG
private static final java.lang.String ABSTRACT_TAG
- See Also:
- Constant Field Values
-
DELETE_TAG
protected static final java.lang.String DELETE_TAG
- See Also:
- Constant Field Values
-
EXTENDS_TAG
public static final java.lang.String EXTENDS_TAG
- See Also:
- Constant Field Values
-
PRESERVE_TAG
public static final java.lang.String PRESERVE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FreeColSpecObjectType
protected FreeColSpecObjectType()
Deliberately empty constructor.
-
FreeColSpecObjectType
public FreeColSpecObjectType(java.lang.String id)
Create a simple FreeColSpecObjectType without a specification.- Parameters:
id
- The object identifier.
-
FreeColSpecObjectType
public FreeColSpecObjectType(Specification specification)
Create a FreeColSpecObjectType with a given specification but no object identifier.- Parameters:
specification
- TheSpecification
to refer to.
-
FreeColSpecObjectType
public FreeColSpecObjectType(java.lang.String id, Specification specification)
Create a FreeColSpecObjectType with a given identifier and specification.- Parameters:
id
- The object identifier.specification
- TheSpecification
to refer to.
-
-
Method Detail
-
getIndex
public int getIndex()
Gets the index of this FreeColSpecObjectType. The index imposes a total ordering consistent with equals on each class extending FreeColSpecObjectType, but this ordering is nothing but the order in which the objects of the respective class were defined. It is guaranteed to remain stable only for a particular revision of a particular specification.- Returns:
- The game object index.
-
setIndex
protected final void setIndex(int index)
Sets the index of this FreeColSpecObjectType.- Parameters:
index
- The new index value.
-
getDescriptionKey
public final java.lang.String getDescriptionKey()
Gets a string suitable for looking up the description of this object inMessages
.- Returns:
- A description key.
-
isAbstractType
public final boolean isAbstractType()
Is this an abstract type?- Returns:
- True if this is an abstract game object type.
-
getScopeList
public final java.util.List<Scope> getScopeList()
-
getScopes
public final java.util.stream.Stream<Scope> getScopes()
-
copyScopes
public final void copyScopes(java.util.Collection<Scope> scopes)
-
addScope
public final void addScope(Scope scope)
-
removeScope
public final void removeScope(Scope scope)
-
appliesTo
public boolean appliesTo(FreeColObject fco)
-
getNameKey
public final java.lang.String getNameKey()
Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.- Specified by:
getNameKey
in interfaceNamed
- Returns:
- The name of the
Named
.
-
getFeatureContainer
public final FeatureContainer getFeatureContainer()
Gets the feature container for this object, if any.- Overrides:
getFeatureContainer
in classFreeColObject
- Returns:
- The
FeatureContainer
for this object.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColSpecObject
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildren
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
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.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChild
protected void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChild
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-