Class Inventory
java.lang.Object
csce331.group13.project2.backend.Inventory
Singleton class that manages the in-memory inventory cache.
Provides methods to add, update, and reduce inventory items.
- Author:
- Varish Kongara, Austin Glander
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPrivate constructor that initializes the inventory by loading all items from the database. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddInventoryItem(InventoryItem inventoryItem) Adds a new inventory item to both the database and the in-memory cache.static InventoryReturns the singleton instance of the Inventory class.voidreduceInventory(UUID menuItemId, int quantity) Reduces the stock of inventory items associated with a menu item.booleanupdateInventoryItem(InventoryItem inventoryItem) Updates an existing inventory item in the database.
-
Field Details
-
items
-
-
Constructor Details
-
Inventory
public Inventory()Private constructor that initializes the inventory by loading all items from the database.
-
-
Method Details
-
getInstance
Returns the singleton instance of the Inventory class.- Returns:
- The single Inventory instance.
-
addInventoryItem
Adds a new inventory item to both the database and the in-memory cache.- Parameters:
inventoryItem- The InventoryItem to add.- Returns:
- true if the item was successfully added; false otherwise.
-
updateInventoryItem
Updates an existing inventory item in the database.- Parameters:
inventoryItem- The InventoryItem with updated values.- Returns:
- true if the update was successful; false otherwise.
-
reduceInventory
Reduces the stock of inventory items associated with a menu item.- Parameters:
menuItemId- menu item to reduce stock forquantity- quantity to remove- Throws:
SQLException
-