Class Menu
java.lang.Object
csce331.group13.project2.backend.Menu
Singleton class that manages the in-memory menu cache.
Provides methods to access, update, and manage menu items and their inventory relationships.
- Author:
- Austin Glander, Varish Kongara, William Clymire
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMenu()Private constructor that initializes the menu by loading all menu items and their inventory relationships from the database. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMenuItemWithInventory(MenuItem menuItem, List<InventoryItem> inventoryItems, List<BigDecimal> quantities) Adds a new menu item along with its inventory relationships.Organizes all menu items into a map by category.static MenuReturns the singleton instance of the Menu class.getInventoryItemsForMenuItem(UUID menuItemId) Retrieves all inventory items associated with a specific menu item.getItemsByCategoryName(String category) Retrieves all active menu item names for a specific category.getMenuItemByName(String name) Retrieves a menu item by its name (case-insensitive).getQuantitiesForMenuItem(UUID menuItemId) Retrieves the quantities of each inventory item required for a specific menu item.booleanupdateMenuItem(MenuItem menuItem) Updates a menu item in the database.voidupdateMenuItemWithInventory(MenuItem menuItem, List<InventoryItem> inventoryItems, List<BigDecimal> quantities) Updates a menu item and its inventory relationships.
-
Field Details
-
items
-
-
Constructor Details
-
Menu
public Menu()Private constructor that initializes the menu by loading all menu items and their inventory relationships from the database.
-
-
Method Details
-
getInstance
Returns the singleton instance of the Menu class.- Returns:
- The single Menu instance.
-
updateMenuItem
Updates a menu item in the database.- Parameters:
menuItem- The MenuItem with updated values.- Returns:
- true if the update was successful; false otherwise.
-
categorizeMenuItems
-
getMenuItemByName
Retrieves a menu item by its name (case-insensitive). First searches the in-memory cache, then falls back to the database if not found.- Parameters:
name- The name of the menu item to find.- Returns:
- The MenuItem with the given name, or null if not found.
-
getItemsByCategoryName
-
addMenuItemWithInventory
public void addMenuItemWithInventory(MenuItem menuItem, List<InventoryItem> inventoryItems, List<BigDecimal> quantities) Adds a new menu item along with its inventory relationships. This operation is transactional - either all changes succeed or all are rolled back.- Parameters:
menuItem- The MenuItem to add.inventoryItems- List of InventoryItem objects required for this menu item.quantities- List of quantities corresponding to each inventory item.
-
updateMenuItemWithInventory
public void updateMenuItemWithInventory(MenuItem menuItem, List<InventoryItem> inventoryItems, List<BigDecimal> quantities) Updates a menu item and its inventory relationships. Deletes existing relationships and creates new ones. This operation is transactional - either all changes succeed or all are rolled back.- Parameters:
menuItem- The MenuItem with updated values.inventoryItems- List of InventoryItem objects required for this menu item.quantities- List of quantities corresponding to each inventory item.
-
getInventoryItemsForMenuItem
Retrieves all inventory items associated with a specific menu item.- Parameters:
menuItemId- The UUID of the menu item.- Returns:
- A list of InventoryItem objects used by this menu item.
-
getQuantitiesForMenuItem
Retrieves the quantities of each inventory item required for a specific menu item.- Parameters:
menuItemId- The UUID of the menu item.- Returns:
- A list of BigDecimal quantities corresponding to the inventory items.
-