Package Model
Class Inventory
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
Integer[]>
A custom HashMap to store the inventory of the clinic
Maps a medicine name to an array of two integers: the first integer is the quantity of the medicine in stock, the second integer is the low stock alert threshold
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addMedicine
(String medicine, int quantity) Adds a medicine to inventory If the medicine already exists in inventory, the quantity is updated If the medicine does not exist in inventory, it is added to inventory with default low stock threshold of 0void
addMedicine
(String medicine, int quantity, int lowStockThreshold) Adds a medicine to inventoryString[]
int
getLowStockThreshold
(String medicine) int
getMedicineCount
(String medicine) boolean
isLowStock
(String medicine) Checks if a medicine is low in stock If the medicine does not exist in inventory, it is considered low stockboolean
removeMedicine
(String medicine, int quantity) Removes a quantity of a medicine from inventoryvoid
setLowStockThreshold
(String medicine, int lowStockThreshold) void
setMedicineCount
(String medicine, int quantity) toString()
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode
-
Constructor Details
-
Inventory
public Inventory()
-
-
Method Details
-
addMedicine
Adds a medicine to inventory- Parameters:
medicine
- the name of the medicinequantity
- the quantity of the medicine to addlowStockThreshold
- the low stock threshold for the medicine
-
addMedicine
Adds a medicine to inventory If the medicine already exists in inventory, the quantity is updated If the medicine does not exist in inventory, it is added to inventory with default low stock threshold of 0- Parameters:
medicine
- the name of the medicinequantity
- the quantity of the medicine to add
-
setLowStockThreshold
-
getLowStockThreshold
-
isLowStock
Checks if a medicine is low in stock If the medicine does not exist in inventory, it is considered low stock- Parameters:
medicine
- the name of the medicine- Returns:
- true if the quantity of the medicine is less than or equal to the low stock threshold
-
getLowStockItems
-
removeMedicine
Removes a quantity of a medicine from inventory- Parameters:
medicine
- the name of the medicinequantity
- the quantity of the medicine to remove- Returns:
- true if the medicine was successfully removed, false if the quantity to remove is greater than the current quantity
-
getMedicineCount
-
setMedicineCount
-
toString
- Overrides:
toString
in classAbstractMap<String,
Integer[]>
-