Class WorkerWish

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, ObjectWithId

    public final class WorkerWish
    extends Wish
    Represents the need for a worker within a Colony.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • unitType

        private UnitType unitType
        The type of unit required.
      • expertNeeded

        private boolean expertNeeded
        Whether the exact type is needed.
      • EXPERT_NEEDED_TAG

        private static final java.lang.String EXPERT_NEEDED_TAG
        See Also:
        Constant Field Values
      • TRANSPORTABLE_TAG

        private static final java.lang.String TRANSPORTABLE_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • WorkerWish

        public WorkerWish​(AIMain aiMain,
                          java.lang.String id)
        Creates a new uninitialized WorkerWish from the given XML-representation.
        Parameters:
        aiMain - The main AI-object.
        id - The object identifier.
      • WorkerWish

        public WorkerWish​(AIMain aiMain,
                          Location destination,
                          int value,
                          UnitType unitType,
                          boolean expertNeeded)
        Creates a new WorkerWish.
        Parameters:
        aiMain - The main AI-object.
        destination - The Location in which the transportable assigned to this WorkerWish will have to reach.
        value - The value identifying the importance of this Wish.
        unitType - The type of unit needed for releasing this wish completely.
        expertNeeded - Determines wether the unitType is required or not.
      • WorkerWish

        public WorkerWish​(AIMain aiMain,
                          FreeColXMLReader xr)
                   throws javax.xml.stream.XMLStreamException
        Creates a new WorkerWish from the given XML-representation.
        Parameters:
        aiMain - The main AI-object.
        xr - The input stream containing the XML.
        Throws:
        javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
    • Method Detail

      • setInitialized

        public void setInitialized()
        Set the initialized flag in this object. To be implemented by leaf classes, and called in their constructors plus the special case in readChild below where we resolve forward references.
        Specified by:
        setInitialized in class AIObject
      • update

        public void update​(UnitType unitType,
                           boolean expertNeeded,
                           int value)
        Updates this WorkerWish with the given attributes.
        Parameters:
        unitType - The UnitType to wish for.
        expertNeeded - Is an expert unit required?
        value - The urgency of the wish.
      • getUnitType

        public UnitType getUnitType()
        Gets the type of unit needed for releasing this wish.
        Returns:
        The type of unit.
      • satisfiedBy

        public boolean satisfiedBy​(Unit unit)
        Does a specified unit satisfy this wish?
        Specified by:
        satisfiedBy in class Wish
        Parameters:
        unit - The Unit to test.
        Returns:
        True if the unit either matches exactly if expertRequired, or at least matches in a land/naval sense if not.
      • satisfiedBy

        public <T extends AbstractGoods> boolean satisfiedBy​(T goods)
        Does some specified goods satisfy this wish?
        Specified by:
        satisfiedBy in class Wish
        Type Parameters:
        T - The base type of the goods.
        Parameters:
        goods - The goods to test.
        Returns:
        True if the goods type matches and amount is not less than that requested.
      • checkIntegrity

        public Constants.IntegrityType checkIntegrity​(boolean fix,
                                                      LogBuilder lb)
        AIObjects need integrity checking too.
        Overrides:
        checkIntegrity in class Wish
        Parameters:
        fix - If true, fix problems if possible.
        lb - A LogBuilder to log to.
        Returns:
        -1 if there are problems remaining, zero if problems were fixed, +1 if no problems found at all.
      • 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 Wish
        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 Wish
        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.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class Wish
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Wish