diff --git a/src/main/java/tech/iBeans/POSware/Lite/inventory.java b/src/main/java/tech/iBeans/POSware/Lite/inventory.java index 3932550..aa8bd83 100644 --- a/src/main/java/tech/iBeans/POSware/Lite/inventory.java +++ b/src/main/java/tech/iBeans/POSware/Lite/inventory.java @@ -14,6 +14,7 @@ import java.util.*; public class inventory { public static Dictionary items = new Hashtable<>(); + public static ArrayList item_names = collate(); public static boolean refresh() { /* Refresh the inventory. @@ -22,6 +23,7 @@ public class inventory { */ // Pull the sample items. items = data_test.fake_items; + item_names = collate(); return (true); }; @@ -75,10 +77,10 @@ public class inventory { ArrayList items_SKU = new ArrayList<>(); Enumeration items_SKU_raw = items.keys(); - do { + while (items_SKU_raw.hasMoreElements()) { String item_SKU = items_SKU_raw.nextElement(); items_SKU.add(item_SKU); - } while (items_SKU_raw.hasMoreElements()); + }; return(items_SKU); }; @@ -115,10 +117,58 @@ public class inventory { }; return(items_names_display); + }; + + public static Dictionary find(String NAME) { + /* Find an item by its name, and get its information. - } + Parameters: + (String) NAME: the name or SKU of an item + Returns: (Dictionary) its information + */ + + Dictionary SKU_DETAILS = null; + + refresh(); + Boolean isNAME = item_names.contains(NAME); + Boolean isSKU = list().contains(NAME); + + if (isNAME) { + int item_index = item_names.indexOf(NAME); + SKU_DETAILS = items.get(list().get(item_index)); + } else if (isSKU) { + SKU_DETAILS = items.get(NAME); + }; + return (SKU_DETAILS); + }; + + public static Dictionary find(int INDEX) { + /* Find an item by its index in the collated data, and get its information. + + Parameters: + (String) NAME: the name or SKU of an item + Returns: (Dictionary) its information + */ + + Dictionary SKU_DETAILS = null; + + refresh(); + int NAME_LENGTH = item_names.size(); + + if (INDEX > NAME_LENGTH) { + // Stop being out of bounds. + return (null); + }; + + // Get the details of the data. + SKU_DETAILS = items.get(list().get(INDEX)); + + // It's time to return the data. + return (SKU_DETAILS); + }; static { refresh(); + collate(); } };