Class 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 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.
    • 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 - The Specification 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 - The Specification 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 in Messages.
        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)
      • 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 interface Named
        Returns:
        The name of the Named.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class FreeColSpecObject
        Type Parameters:
        T - The FreeColObject 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 class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.