summaryrefslogtreecommitdiff
path: root/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/item
diff options
context:
space:
mode:
Diffstat (limited to 'oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/item')
-rw-r--r--oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/item/InMemoryItemManager.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/item/InMemoryItemManager.java b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/item/InMemoryItemManager.java
new file mode 100644
index 0000000..00bc835
--- /dev/null
+++ b/oop/10-point-of-sale/src/lk/ac/pdn/ceit/pos/item/InMemoryItemManager.java
@@ -0,0 +1,43 @@
+package lk.ac.pdn.ceit.pos.item;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import lk.ac.pdn.ceit.pos.entities.Item;
+
+public class InMemoryItemManager implements ItemManager {
+
+ // Assume this is the item storage
+ private Map<String, Item> items = new HashMap<>();
+
+ // Initial set of data for demo purposes
+ public InMemoryItemManager() {
+ this.create("Dhal", "F001", 300.00);
+ this.create("Bread", "F002", 180.00);
+ this.create("Sunlight Soap", "S001", 150.00);
+ }
+
+ @Override
+ public Item findById(String id) {
+ return items.get(id);
+ }
+
+ @Override
+ public List<Item> searchByName(String word) {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("Unimplemented method 'searchByName'");
+ }
+
+ @Override
+ public Item create(String name, String id, double unitPrice) {
+ // Create a new Item
+ Item item = new Item(name, id, unitPrice);
+
+ // Add to storage
+ items.put(id, item);
+
+ return item;
+ }
+
+}