Class WareHolding

  • Direct Known Subclasses:
    City, TradingOffice

    public abstract class WareHolding
    extends java.lang.Object
    This class represents an entity that can hold wares which can be moved
    Author:
    Andi Hotz, (c) Sahits GmbH, 2011 Created on Dec 17, 2011
    • Field Detail

      • occupiedSpace

        private final javafx.beans.property.IntegerProperty occupiedSpace
        Space occupied by some tenant
      • storedAmountBinding

        private LateIntegerBinding storedAmountBinding
        Binding representing the current load.
    • Constructor Detail

      • WareHolding

        public WareHolding()
    • Method Detail

      • addNewWare

        protected void addNewWare​(IWare ware,
                                  int amount)
        Add a new ware to the wares list
        Parameters:
        ware - to be added
        amount - of ware to be added.
      • bindStoredAmount

        protected void bindStoredAmount​(javafx.beans.property.ReadOnlyIntegerProperty amountProperty)
        Bind the amountProperty.
        Parameters:
        amountProperty - to be bound.
      • unbindAllAmounts

        protected void unbindAllAmounts()
        Unbind all bound amounts.
      • getWare

        public AmountablePrice<IWare> getWare​(IWare ware)
        Retrieve the AmountablePrice of the ware as it is stored in the holding
        Parameters:
        ware - to be retrieved
        Returns:
        AmountablePrice object
      • move

        public int move​(IWare ware,
                        int amount,
                        ICitizen player)
        Move ware into this holding. The player may be null and is not used in this base implementation, but subclasses may be interested for statistical reasons. This method is thread save.
        Parameters:
        ware - to be moved
        amount - of the ware that is moved
        player - that initiates the moving, may be null, e.g. if the moving is initiated by a city
        Returns:
        the effective amount that was moved. The amount may be positive if something was added, negative if the ware was removed from the holding or zero if nothing was moved.
      • containsWare

        protected final boolean containsWare​(IWare ware)
        Check if there is an amountable object for this ware
        Parameters:
        ware - to be checked for containemnt
        Returns:
        true if the ware is present in the WareHolding.
      • computeAVGPrice

        protected int computeAVGPrice​(IWare ware,
                                      int amount)
        Compute the average price for ware that is to be purchased in the specified amount. The additional variable of the available amount is supplied by getWare(IWare). Subclasses may override this method.
        Parameters:
        ware - for which the average price is to be computed
        amount - amount that is bought
        Returns:
        average price for the amount of ware.
      • internalStoredAmountCalculation

        private int internalStoredAmountCalculation()
        Calculate the stored amount.
        Returns:
        total amount of stored wares.
      • occupiedSpaceProperty

        public javafx.beans.property.IntegerProperty occupiedSpaceProperty()
      • getOccupiedSpace

        public int getOccupiedSpace()
      • setOccupiedSpace

        public void setOccupiedSpace​(int occupiedSpace)