Interface StockHolder
- All Known Subinterfaces:
PersonalStockHolder,StockHolderWrapper
The implementation of this interface must be thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionintdecrease(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int decrement, StockEvent.Cause cause) Decreases the stock of the specified item.booleandecreaseIfPossible(@NotNull it.unimi.dsi.fastutil.objects.Object2IntMap<BoxItem> decrementMap, StockEvent.Cause cause) Decreases the stock of the specified items.default booleandecreaseIfPossible(@NotNull Map<BoxItem, Integer> decrementMap, StockEvent.Cause cause) Decreases the stock of the specified items.intdecreaseIfPossible(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int decrement, StockEvent.Cause cause) Decreases the stock of the specified item.intdecreaseToZero(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int limit, StockEvent.Cause cause) Decreases the stock of the specified item.intgetAmount(int itemId) Gets the stock quantity of the specified item.default intGets the stock quantity of the specified item.@NotNull StringgetName()Gets the name of this holder.@NotNull @Unmodifiable Collection<BoxItem> Gets a stocked item collection.@NotNull UUIDgetUUID()Gets the uuid of this holder.intincrease(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int increment, StockEvent.Cause cause) Increases the stock of the specified item.@NotNull @Unmodifiable Collection<StockData> reset()Resets all stock.voidsetAmount(@NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int amount, StockEvent.Cause cause) Sets the stock quantity of the specified item.@NotNull @Unmodifiable Collection<StockData> Gets the current stock as aStockDatacollection.
-
Method Details
-
getName
Gets the name of this holder.- Returns:
- the name of this holder
-
getUUID
Gets the uuid of this holder.- Returns:
- the uuid of this holder
-
getAmount
Gets the stock quantity of the specified item.- Parameters:
item- the item to get the stock- Returns:
- the current stock quantity
- Throws:
NullPointerException- ifitemisnull
-
getAmount
int getAmount(int itemId) Gets the stock quantity of the specified item.- Parameters:
itemId- the id of theBoxItemto get the stock- Returns:
- the current stock quantity
- Throws:
NullPointerException- ifitemisnull
-
setAmount
void setAmount(@NotNull @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.- Parameters:
item- the item to set the stock quantityamount- the amountcause- the cause that indicates why this method called- Throws:
IllegalArgumentException- ifamountis negativeNullPointerException- ifitemorcauseisnull
-
increase
int increase(@NotNull @NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int increment, @NotNull StockEvent.Cause cause) Increases the stock of the specified item.If
incrementis zero, this method returnsgetAmount(BoxItem).The behavior when the stock has overflowed depends on the implementation.
- 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
- Throws:
IllegalArgumentException- ifincrementis negativeNullPointerException- ifitemorcauseisnull
-
decrease
int decrease(@NotNull @NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int decrement, @NotNull StockEvent.Cause cause) Decreases the stock of the specified item.If
decrementis zero, this method returnsgetAmount(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
decreaseIfPossible(BoxItem, int, StockEvent.Cause).- 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
- Throws:
IllegalArgumentException- ifdecrementis negativeNullPointerException- ifitemorcauseisnull
-
decreaseToZero
int decreaseToZero(@NotNull @NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int limit, @NotNull StockEvent.Cause cause) 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
limitand returnslimit
This method is useful when you want to decrease the stock as much as possible, with
limitas the maximum decrement.- Parameters:
item- the item to decrease the stocklimit- the maximum decrementcause- the cause that indicates why this method called- Returns:
- the amount of decrement
- Throws:
IllegalArgumentException- iflimitis negativeNullPointerException- ifitemorcauseisnull
- If the stock is less than
-
decreaseIfPossible
int decreaseIfPossible(@NotNull @NotNull BoxItem item, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int decrement, @NotNull StockEvent.Cause cause) 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.- 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 - Throws:
IllegalArgumentException- ifdecrementis negativeNullPointerException- ifitemorcauseisnull
-
decreaseIfPossible
@NonExtendable default boolean decreaseIfPossible(@NotNull @NotNull Map<BoxItem, Integer> decrementMap, @NotNull StockEvent.Cause cause) Decreases the stock of the specified items.- 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- Throws:
IllegalArgumentException- if the negative value is contained indecrementMapNullPointerException- ifdecrementMaporcauseisnull- See Also:
-
decreaseIfPossible
boolean decreaseIfPossible(@NotNull @NotNull it.unimi.dsi.fastutil.objects.Object2IntMap<BoxItem> decrementMap, @NotNull StockEvent.Cause cause) Decreases 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.
- 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- Throws:
IllegalArgumentException- if the negative value is contained indecrementMapNullPointerException- ifdecrementMaporcauseisnull
- If all items in the
-
getStockedItems
Gets a stocked item collection.- Returns:
- a stocked item collection.
-
toStockDataCollection
Gets the current stock as aStockDatacollection.- Returns:
- the collection of
StockData
-
reset
Resets all stock.- Returns:
- the collection of
StockDatabefore reset
-