Class UnitID

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable<java.lang.Object>, ID

    public class UnitID
    extends EntityID
    A class for identifying unit objects through an integer. This class makes equivalent assumptions about the representation of the integer as the EntityID class. It also provides additional convenience methods and knowledge about TEMP unit ids (which are represented as negative integers).

    FIXME (stm-2010) It would be better if UnitID wasn't a sub-type of EntityID. This can result in unit IDs being compared to building IDs and found equal...

    • Field Summary

      • Fields inherited from class magellan.library.IntegerID

        id
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected UnitID​(int i, int radix)
      Constructs a new UnitID object based on an Integer object created from the specified int.
    • Constructor Detail

      • UnitID

        protected UnitID​(int i,
                         int radix)
        Constructs a new UnitID object based on an Integer object created from the specified int.
        Parameters:
        i - id as integer form
        radix - the base
    • Method Detail

      • createUnitID

        public static UnitID createUnitID​(int o,
                                          int radix)
        Constructs a new UnitID object based on the specified Integer and specified radix.
        Parameters:
        o - unit id as int
        radix - base for the UnitID
        Returns:
        UnitID of the given int
      • createUnitID

        public static UnitID createUnitID​(java.lang.String s,
                                          int radix)
        Constructs a new UnitID object by parsing the specified string. Effectively the same as calling createUnitID(s, radix, radix).
        Throws:
        java.lang.NumberFormatException - if unit id is not parseable
        java.lang.NullPointerException - if unit id is null
      • createUnitID

        public static UnitID createUnitID​(java.lang.String s,
                                          int inputRadix,
                                          int outputRadix)
        Constructs a new UnitID object by parsing the specified string.
        Parameters:
        s - unit id as String
        inputRadix - base for transforming string to int
        outputRadix - base for the return value
        Returns:
        UnitID of the given string
        Throws:
        java.lang.NumberFormatException - if unit id is not parseable
        java.lang.NullPointerException - if unit id is null
      • createTempID

        public static UnitID createTempID​(GameData data,
                                          java.util.Properties settings,
                                          Unit parentUnit)
        Creates a temp id.
        Parameters:
        data - The current GameData object
        settings - The active settings
        parentUnit - The parent unit of the temp unit (maybe null)
        Returns:
        the new temp id. This is always negative as Magellan expects temp unit ids to be negative.
      • getNextDecimalID

        protected static int getNextDecimalID​(int current,
                                              int base,
                                              boolean ascending)
        Returns the next int, that is bigger than the given one but consists only out of decimal digits (interpreted in the current base).
        Parameters:
        current - the last ID, that is to be increased (or decreased)
        base - the base where the digits come from
        ascending - if true, the current id is increased, otherwise decreased
        Returns:
        the next int, that is bigger than the given one (or smaller if ascending==false) but consists only of decimal digits (interpreted in the given base). The result is also > 0 and <= IDBaseConverter.getMaxId(int)
      • toString

        public java.lang.String toString()
        Returns a String representation of this UnitID. The radix of the output depends on the default set in the IDBaseConverter class. This method is not TEMP id aware, i.e. negative ids are returned as the string representation of the absolute value but without a 'TEMP' prefix.
        Specified by:
        toString in interface ID
        Overrides:
        toString in class EntityID
        Returns:
        String representation of this UnitID