Interface StockHolderWrapper

All Superinterfaces:
StockHolder
All Known Subinterfaces:
PersonalStockHolder
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface StockHolderWrapper extends StockHolder
An interface that wraps StockHolder.
  • Method Details

    • delegate

      @NotNull @NotNull StockHolder delegate()
      Gets the delegating StockHolder.
      Returns:
      the delegating StockHolder
    • getName

      @NotNull default @NotNull String getName()
      Description copied from interface: StockHolder
      Gets the name of this holder.
      Specified by:
      getName in interface StockHolder
      Returns:
      the name of this holder
    • getUUID

      @NotNull default @NotNull UUID getUUID()
      Description copied from interface: StockHolder
      Gets the uuid of this holder.
      Specified by:
      getUUID in interface StockHolder
      Returns:
      the uuid of this holder
    • getAmount

      default int getAmount(int itemId)
      Description copied from interface: StockHolder
      Gets the stock quantity of the specified item.
      Specified by:
      getAmount in interface StockHolder
      Parameters:
      itemId - the id of the BoxItem to get the stock
      Returns:
      the current stock quantity
    • setAmount

      default void setAmount(@NotNull @NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int amount, @NotNull StockEvent.Cause cause)
      Description copied from interface: StockHolder
      Sets the stock quantity of the specified item.
      Specified by:
      setAmount in interface StockHolder
      Parameters:
      item - the item to set the stock quantity
      amount - the amount
      cause - the cause that indicates why this method called
    • increase

      default int increase(@NotNull @NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int increment, @NotNull StockEvent.Cause cause)
      Description copied from interface: StockHolder
      Increases the stock of the specified item.

      If increment is zero, this method returns StockHolder.getAmount(BoxItem).

      The behavior when the stock has overflowed depends on the implementation.

      Specified by:
      increase in interface StockHolder
      Parameters:
      item - the item to increase the stock
      increment - the amount to increase the stock
      cause - the cause that indicates why this method called
      Returns:
      the stock quantity after increasing
    • decrease

      default int decrease(@NotNull @NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int decrement, @NotNull StockEvent.Cause cause)
      Description copied from interface: StockHolder
      Decreases the stock of the specified item.

      If decrement is zero, this method returns StockHolder.getAmount(BoxItem).

      If the current stock is less than decrement, this method sets the stock to zero. In other words, this method does not guarantee that the stock is always decreased by decrement.

      If you want to decrease the stock when it is sufficient, use StockHolder.decreaseIfPossible(BoxItem, int, StockEvent.Cause).

      Specified by:
      decrease in interface StockHolder
      Parameters:
      item - the item to decrease the stock
      decrement - the amount to decrease the stock
      cause - the cause that indicates why this method called
      Returns:
      the stock quantity after decreasing
    • decreaseToZero

      default int decreaseToZero(@NotNull @NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int limit, @NotNull StockEvent.Cause cause)
      Description copied from interface: StockHolder
      Decreases the stock of the specified item.

      This method has the following specification:

      • If the stock is less than limit, this method sets the stock to zero and returns the stock before set to zero
      • Otherwise, this method decreases the stock by limit and returns limit

      This method is useful when you want to decrease the stock as much as possible, with limit as the maximum decrement.

      Specified by:
      decreaseToZero in interface StockHolder
      Parameters:
      item - the item to decrease the stock
      limit - the maximum decrement
      cause - the cause that indicates why this method called
      Returns:
      the amount of decrement
    • decreaseIfPossible

      default int decreaseIfPossible(@NotNull @NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int decrement, @NotNull StockEvent.Cause cause)
      Description copied from interface: StockHolder
      Decreases the stock of the specified item.

      If the stock is less than the decrement, this method does not actually decrease it, and returns -1.

      Specified by:
      decreaseIfPossible in interface StockHolder
      Parameters:
      item - the item to decrease the stock
      decrement - the amount to decrease the stock
      cause - the cause that indicates why this method called
      Returns:
      the stock quantity after decreasing or -1 when the stock is less than the decrement
    • decreaseIfPossible

      default boolean decreaseIfPossible(@NotNull @NotNull it.unimi.dsi.fastutil.objects.Object2IntMap<BoxItem> decrementMap, @NotNull StockEvent.Cause cause)
      Description copied from interface: StockHolder
      Decreases the stock of the specified items.

      This method is implemented as follows:

      • If all items in the decrementMap are greater than the decrement (the value keyed by BoxItem), this method will actually decrease them and return true.
      • If even one item is lacking, it returns false without any stock modification.
      • If decrementMap is empty, this method returns true.
      • When the negative value is contained in decrementMap, this method throws IllegalArgumentException
      • When the decrement value is zero, this method ignores it.
      Specified by:
      decreaseIfPossible in interface StockHolder
      Parameters:
      decrementMap - the map (key: BoxItem, value: decrement)
      cause - the cause that indicates why this method called
      Returns:
      true if stock of all specified items is decreased, otherwise false
    • getStockedItems

      @NotNull default @NotNull @Unmodifiable Collection<BoxItem> getStockedItems()
      Description copied from interface: StockHolder
      Gets a stocked item collection.
      Specified by:
      getStockedItems in interface StockHolder
      Returns:
      a stocked item collection.
    • toStockDataCollection

      @NotNull default @NotNull @Unmodifiable Collection<StockData> toStockDataCollection()
      Description copied from interface: StockHolder
      Gets the current stock as a StockData collection.
      Specified by:
      toStockDataCollection in interface StockHolder
      Returns:
      the collection of StockData
    • reset

      @NotNull default @NotNull @Unmodifiable Collection<StockData> reset()
      Description copied from interface: StockHolder
      Resets all stock.
      Specified by:
      reset in interface StockHolder
      Returns:
      the collection of StockData before reset