Class GoodsLocation

    • Field Detail

      • logger

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

        private GoodsContainer goodsContainer
        The container for the goods.
    • Constructor Detail

      • GoodsLocation

        public GoodsLocation​(Game game)
        Creates a new GoodsLocation instance.
        Parameters:
        game - The enclosing Game.
      • GoodsLocation

        public GoodsLocation​(Game game,
                             java.lang.String id)
        Creates a new GoodsLocation instance.
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
    • Method Detail

      • setGoodsContainer

        public final void setGoodsContainer​(GoodsContainer goodsContainer)
      • addGoods

        public final boolean addGoods​(AbstractGoods goods)
        Adds some goods to this location.
        Parameters:
        goods - The AbstractGoods to add.
        Returns:
        True if the goods were added.
      • addGoods

        public final boolean addGoods​(java.util.List<AbstractGoods> goods)
        Adds a list of goods to this location.
        Parameters:
        goods - The list of AbstractGoods to add.
        Returns:
        True if the goods were all added.
      • removeGoods

        public final Goods removeGoods​(AbstractGoods goods)
        Removes the some goods from this location.
        Parameters:
        goods - The AbstractGoods to remove.
        Returns:
        The goods that was removed, which may be less than that requested, or null if none.
      • removeGoods

        public final Goods removeGoods​(GoodsType type)
        Removes all Goods of the given type from this location.
        Parameters:
        type - The GoodsType to remove.
        Returns:
        The goods that was removed, or null if none.
      • getGoodsCount

        public final int getGoodsCount​(GoodsType type)
        Gets the amount of one type of goods at this location.
        Parameters:
        type - The GoodsType to look for.
        Returns:
        The amount of goods.
      • containsGoods

        public final boolean containsGoods​(java.util.List<AbstractGoods> goods)
        Does this location contain enough goods to satisfy a list of requirements?
        Parameters:
        goods - A list of AbstractGoods to check.
        Returns:
        True if the goods are all present.
      • removeAll

        public final void removeAll()
        Remove all the goods.
      • getGoodsList

        public java.util.List<Goods> getGoodsList()
        Gets a list of all the goods in this location. Each list member is limited to a maximum amount of CARGO_SIZE, thus there may be multiple entries with the same goods type.
        Returns:
        A list of goods.
      • getCompactGoodsList

        public java.util.List<Goods> getCompactGoodsList()
        Gets an list of all the goods in this location. There is only one Goods for each GoodsType, thus the amount of goods may exceed CARGO_SIZE.
        Returns:
        A list of goods.
      • moveGoods

        public static void moveGoods​(GoodsLocation src,
                                     GoodsType goodsType,
                                     int amount,
                                     GoodsLocation dst)
        Move goods from one location to another.
        Parameters:
        src - The source GoodsLocation.
        goodsType - The GoodsType to move.
        amount - The amount of goods to move.
        dst - The new GoodsLocation.
      • add

        public boolean add​(Locatable locatable)
        Adds a Locatable to this Location.
        Specified by:
        add in interface Location
        Overrides:
        add in class UnitLocation
        Parameters:
        locatable - The Locatable to add to this Location.
        Returns:
        True if the locatable was added.
      • remove

        public boolean remove​(Locatable locatable)
        Removes a Locatable from this Location.
        Specified by:
        remove in interface Location
        Overrides:
        remove in class UnitLocation
        Parameters:
        locatable - The Locatable to remove from this Location.
        Returns:
        True if the locatable was removed.
      • contains

        public boolean contains​(Locatable locatable)
        Checks if this Location contains the specified Locatable.
        Specified by:
        contains in interface Location
        Overrides:
        contains in class UnitLocation
        Parameters:
        locatable - The Locatable to test the presence of.
        Returns:
        True if the locatable is present at this location.
      • getNoAddReason

        public UnitLocation.NoAddReason getNoAddReason​(Locatable locatable)
        Gets the reason why a given Locatable can not be added to this Location. Be careful to test for unit presence last before success (NoAddReason.NONE) except perhaps for the capacity test, so that we can treat ALREADY_PRESENT as success in some cases (e.g. if the unit changes type --- does it still have a required skill?) FIXME: consider moving this up to Location?
        Overrides:
        getNoAddReason in class UnitLocation
        Parameters:
        locatable - The Locatable to test.
        Returns:
        The reason why adding would fail.
      • invalidateCache

        public abstract void invalidateCache()
        Invalidate any cache dependent on the goods levels.
      • getGoodsCapacity

        public abstract int getGoodsCapacity()
        Gets the maximum number of Goods this Location can hold.
        Returns:
        The capacity for goods
      • addGoods

        public boolean addGoods​(GoodsType type,
                                int amount)
        Adds a specified amount of a type of goods to this location.
        Parameters:
        type - The GoodsType to add.
        amount - The amount of goods to add.
        Returns:
        True if the goods were added.
      • removeGoods

        public Goods removeGoods​(GoodsType type,
                                 int amount)
        Removes a specified amount of a type of Goods from this location.
        Parameters:
        type - The type of goods to remove.
        amount - The amount of goods to remove.
        Returns:
        The goods that was removed, which may be less than that requested, or null if none.
      • getDisposables

        public java.util.stream.Stream<FreeColGameObject> getDisposables()
        Collect this object and all its subparts that should be disposed of when this object goes away. Overriding routines should call upwards towards this routine, arranging that the object itself is last.
        Overrides:
        getDisposables in class UnitLocation
        Returns:
        A stream of FreeColGameObjects to dispose of.
      • copyIn

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