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.
StockHolder.-
Method Summary
Modifier and TypeMethodDescriptiondefault intdecrease(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int decrement, @NotNull StockEvent.Cause cause) Decreases the stock of the specified item.default booleandecreaseIfPossible(@NotNull it.unimi.dsi.fastutil.objects.Object2IntMap<BoxItem> decrementMap, @NotNull StockEvent.Cause cause) Decreases the stock of the specified items.default intdecreaseIfPossible(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int decrement, @NotNull StockEvent.Cause cause) Decreases the stock of the specified item.default intdecreaseToZero(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int limit, @NotNull StockEvent.Cause cause) Decreases the stock of the specified item.@NotNull StockHolderdelegate()Gets the delegatingStockHolder.default intgetAmount(int itemId) Gets the stock quantity of the specified item.default @NotNull StringgetName()Gets the name of this holder.default @NotNull @Unmodifiable Collection<BoxItem> Gets a stocked item collection.default @NotNull UUIDgetUUID()Gets the uuid of this holder.default intincrease(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int increment, @NotNull StockEvent.Cause cause) Increases the stock of the specified item.default @NotNull @Unmodifiable Collection<StockData> reset()Resets all stock.default voidsetAmount(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int amount, @NotNull StockEvent.Cause cause) Sets the stock quantity of the specified item.default @NotNull @Unmodifiable Collection<StockData> Gets the current stock as aStockDatacollection.Methods inherited from interface net.okocraft.box.api.model.stock.StockHolder
decreaseIfPossible, getAmount
-
Method Details
-
delegate
Gets the delegatingStockHolder.- Returns:
- the delegating
StockHolder
-
getName
Description copied from interface:StockHolderGets the name of this holder.- Specified by:
getNamein interfaceStockHolder- Returns:
- the name of this holder
-
getUUID
Description copied from interface:StockHolderGets the uuid of this holder.- Specified by:
getUUIDin interfaceStockHolder- Returns:
- the uuid of this holder
-
getAmount
default int getAmount(int itemId) Description copied from interface:StockHolderGets the stock quantity of the specified item.- Specified by:
getAmountin interfaceStockHolder- Parameters:
itemId- the id of theBoxItemto 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:StockHolderSets the stock quantity of the specified item.- Specified by:
setAmountin interfaceStockHolder- Parameters:
item- the item to set the stock quantityamount- the amountcause- 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:StockHolderIncreases the stock of the specified item.If
incrementis zero, this method returnsStockHolder.getAmount(BoxItem).The behavior when the stock has overflowed depends on the implementation.
- Specified by:
increasein interfaceStockHolder- Parameters:
item- the item to increase the stockincrement- the amount to increase the stockcause- 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:StockHolderDecreases the stock of the specified item.If
decrementis zero, this method returnsStockHolder.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 bydecrement.If you want to decrease the stock when it is sufficient, use
StockHolder.decreaseIfPossible(BoxItem, int, StockEvent.Cause).- Specified by:
decreasein interfaceStockHolder- Parameters:
item- the item to decrease the stockdecrement- the amount to decrease the stockcause- 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:StockHolderDecreases 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
limitand returnslimit
This method is useful when you want to decrease the stock as much as possible, with
limitas the maximum decrement.- Specified by:
decreaseToZeroin interfaceStockHolder- Parameters:
item- the item to decrease the stocklimit- the maximum decrementcause- the cause that indicates why this method called- Returns:
- the amount of decrement
- If the stock is less than
-
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:StockHolderDecreases 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:
decreaseIfPossiblein interfaceStockHolder- Parameters:
item- the item to decrease the stockdecrement- the amount to decrease the stockcause- the cause that indicates why this method called- Returns:
- the stock quantity after decreasing or
-1when the stock is less than thedecrement
-
decreaseIfPossible
default boolean decreaseIfPossible(@NotNull @NotNull it.unimi.dsi.fastutil.objects.Object2IntMap<BoxItem> decrementMap, @NotNull StockEvent.Cause cause) Description copied from interface:StockHolderDecreases the stock of the specified items.This method is implemented as follows:
- If all items in the
decrementMapare greater than the decrement (the value keyed byBoxItem), this method will actually decrease them and returntrue. - If even one item is lacking, it returns
falsewithout any stock modification. - If
decrementMapis empty, this method returnstrue. - When the negative value is contained in
decrementMap, this method throwsIllegalArgumentException - When the decrement value is zero, this method ignores it.
- Specified by:
decreaseIfPossiblein interfaceStockHolder- Parameters:
decrementMap- the map (key:BoxItem, value: decrement)cause- the cause that indicates why this method called- Returns:
trueif stock of all specified items is decreased, otherwisefalse
- If all items in the
-
getStockedItems
Description copied from interface:StockHolderGets a stocked item collection.- Specified by:
getStockedItemsin interfaceStockHolder- Returns:
- a stocked item collection.
-
toStockDataCollection
Description copied from interface:StockHolderGets the current stock as aStockDatacollection.- Specified by:
toStockDataCollectionin interfaceStockHolder- Returns:
- the collection of
StockData
-
reset
Description copied from interface:StockHolderResets all stock.- Specified by:
resetin interfaceStockHolder- Returns:
- the collection of
StockDatabefore reset
-