Package org.progettoedids.util
Class Inventory
java.lang.Object
org.progettoedids.util.Inventory
The Inventory class is essentially a container of Item(s) with a maximum capacity.
Some methods are provided to add, get or remove Item(s) from the Inventory. It's not allowed to add an Item whose weight will cause the Inventory's held weight of all the Item(s) to exceed the maximum capacity.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified Item to the Inventory, if its addition doesn't exceed maximum capacity.booleanChecks whether it's possible to add an Item based on the current weight held in the Inventory and the weight of the Item specified.Returns the Item matching the specified UUIDgetItemByName(String itemName) Item[]getItems()Returns an array of Item(s) held in the Inventory<T> Item[]intintReturns the sum of the weight of all the Item(s) held in the InventorybooleanCheck whether the Item with the specified UUID is present in the InventorybooleanisEmpty()void<T> voidprintInventory(Class<T> itemClass) removeItem(UUID itemUUID) Removes an Item from the Inventory
-
Constructor Details
-
Inventory
public Inventory(int maxWeight) Initializes an Inventory.- Parameters:
maxWeight- an integer representing the maximum allowed weight. Must be positive or zero- Throws:
IllegalArgumentException- if the maximum weight is negative
-
-
Method Details
-
getItem
-
getItemByName
-
getItems
Returns an array of Item(s) held in the Inventory- Returns:
- an array of Item, can be empty
-
getItems
-
canAdd
Checks whether it's possible to add an Item based on the current weight held in the Inventory and the weight of the Item specified.If the weight of the Item plus the current held weight exceeds the maximum capacity false will be returned.
- Parameters:
item- an Item. Must not be null- Returns:
- true if the Item can fit in the Inventory, false otherwise
-
addItem
Adds the specified Item to the Inventory, if its addition doesn't exceed maximum capacity.- Parameters:
item- an Item. Must not be null
-
removeItem
-
hasItem
Check whether the Item with the specified UUID is present in the Inventory- Parameters:
itemUUID- the UUID of an Item. Must not be null- Returns:
- true if the UUID was found in the Inventory, false otherwise
-
getWeightOfAllItems
public int getWeightOfAllItems()Returns the sum of the weight of all the Item(s) held in the Inventory- Returns:
- an integer representing the weight of all the Item(s) held
-
getMaxWeight
public int getMaxWeight() -
exchange
-
isEmpty
public boolean isEmpty() -
printInventory
public void printInventory() -
printInventory
-