Class AbstractUnit

    • Field Detail

      • roleId

        private java.lang.String roleId
        The role identifier of this AbstractUnit.
      • number

        private int number
        The number of units.
    • Constructor Detail

      • AbstractUnit

        public AbstractUnit()
        Deliberately empty constructor, for Game.newInstance.
      • AbstractUnit

        public AbstractUnit​(java.lang.String id,
                            java.lang.String roleId,
                            int number)
        Create a new AbstractUnit.
        Parameters:
        id - The object identifier.
        roleId - The unit role identifier.
        number - A number of units.
      • AbstractUnit

        public AbstractUnit​(UnitType unitType,
                            java.lang.String roleId,
                            int number)
        Create a new AbstractUnit.
        Parameters:
        unitType - The type of unit to create.
        roleId - The unit role identifier.
        number - The number of units.
      • AbstractUnit

        public AbstractUnit​(FreeColXMLReader xr)
                     throws javax.xml.stream.XMLStreamException
        Creates a new AbstractUnit instance.
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if an error occurs
    • Method Detail

      • getRoleId

        public final java.lang.String getRoleId()
        Get the role identifier.
        Returns:
        The role identifier.
      • setRoleId

        public final void setRoleId​(java.lang.String roleId)
        Set the role identifier.
        Parameters:
        roleId - The new role identifier.
      • getNumber

        public final int getNumber()
        Get the number of units.
        Returns:
        The number of units.
      • setNumber

        public final void setNumber​(int newNumber)
        Set the number of units.
        Parameters:
        newNumber - The new number of units.
      • addToNumber

        public final void addToNumber​(int diff)
        Add to the number.
        Parameters:
        diff - The amount to add.
      • getSingleLabel

        public StringTemplate getSingleLabel()
        Gets a template describing this abstract unit with a fixed count of 1.
        Returns:
        A StringTemplate describing the abstract unit.
      • getLabel

        public StringTemplate getLabel()
        Gets a template describing this abstract unit.
        Returns:
        A StringTemplate describing the abstract unit.
      • getLabelInternal

        private static StringTemplate getLabelInternal​(java.lang.String typeId,
                                                       java.lang.String roleId,
                                                       int number)
        Gets a template describing an arbitrary abstract unit.
        Parameters:
        typeId - The unit type identifier.
        roleId - The role identifier.
        number - The number of units.
        Returns:
        A StringTemplate describing the abstract unit.
      • getDescription

        public java.lang.String getDescription()
        Get a description of this abstract unit.
        Returns:
        A String describing this abstract unit.
      • getType

        public UnitType getType​(Specification spec)
        Convenience accessor for the unit type.
        Parameters:
        spec - A Specification to look up the type in.
        Returns:
        The UnitType of this abstract unit.
      • getRole

        public Role getRole​(Specification spec)
        Convenience accessor for the role.
        Parameters:
        spec - A Specification to look up the role in.
        Returns:
        The Role of this abstract unit.
      • getOffence

        public double getOffence​(Specification spec)
        Get the approximate offence power that an instantiated unit corresponding to this abstract form would have.
        Parameters:
        spec - A Specification to look up.
        Returns:
        The approximate offence power.
      • calculateStrength

        public static double calculateStrength​(Specification spec,
                                               java.util.List<AbstractUnit> units)
        Calculate the approximate offence power of a list of units.
        Parameters:
        spec - A Specification to look up the type in.
        units - A list of AbstractUnits.
        Returns:
        The approximate offence power.
      • deepCopy

        public static java.util.List<AbstractUnit> deepCopy​(java.util.List<AbstractUnit> units)
        Get a deep copy of a list of abstract units.
        Parameters:
        units - The list of AbstractUnits to copy.
        Returns:
        A list of AbstractUnits.
      • getListLabel

        public static StringTemplate getListLabel​(java.lang.String base,
                                                  java.util.List<AbstractUnit> units)
        Get a template for a list of abstract units.
        Parameters:
        base - The label template base.
        units - The list of AbstractUnits to use.
        Returns:
        A suitable StringTemplate.
      • matchAll

        public boolean matchAll​(AbstractUnit other)
        Does another AbstractUnit match in all fields.
        Parameters:
        other - The other AbstractUnit to test.
        Returns:
        True if all fields match.
      • matcher

        public static java.util.function.Predicate<AbstractUnit> matcher​(UnitType ut,
                                                                         java.lang.String roleId)
        Create a predicate to match the type+role of an abstract unit.
        Parameters:
        ut - The UnitType to match.
        roleId - The role identifier to match.
        Returns:
        A suitable Predicate.
      • matcher

        public static java.util.function.Predicate<AbstractUnit> matcher​(AbstractUnit au)
        Create a predicate to match the type+role of an abstract unit.
        Parameters:
        au - The AbstractUnit to match.
        Returns:
        A suitable Predicate.
      • matcher

        public static java.util.function.Predicate<AbstractUnit> matcher​(Unit unit)
        Create a predicate to match the type+role of a unit.
        Parameters:
        unit - The Unit to match.
        Returns:
        A suitable Predicate.
      • matchUnits

        public static boolean matchUnits​(java.util.List<AbstractUnit> l1,
                                         java.util.List<AbstractUnit> l2)
        Do two lists of abstract units match completely.
        Parameters:
        l1 - The first AbstractUnit.
        l2 - The first AbstractUnit.
        Returns:
        True if the lists match.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class FreeColObject
        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.
      • writeAttributes

        protected void writeAttributes​(FreeColXMLWriter xw)
                                throws javax.xml.stream.XMLStreamException
        Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.
        Overrides:
        writeAttributes 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 final 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.
      • getXMLTagName

        public java.lang.String getXMLTagName()
        Get the serialization tag for this object.
        Specified by:
        getXMLTagName in class FreeColObject
        Returns:
        The tag.