import and modify inventory handling
This commit is contained in:
		
							parent
							
								
									7af901fcc9
								
							
						
					
					
						commit
						12e4576463
					
				
					 1 changed files with 124 additions and 0 deletions
				
			
		
							
								
								
									
										124
									
								
								src/main/java/tech/iBeans/POSware/Lite/inventory.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								src/main/java/tech/iBeans/POSware/Lite/inventory.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,124 @@ | |||
| /* | ||||
|  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||||
|  * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||||
|  */ | ||||
| package tech.iBeans.POSware.Lite; | ||||
| import tech.iBeans.POSware.Lite.data_test.*; | ||||
| 
 | ||||
| import java.util.*; | ||||
| 
 | ||||
| /** | ||||
|  * | ||||
|  * @author eleven | ||||
|  */ | ||||
| public class inventory { | ||||
|      | ||||
|     public static Dictionary<String, Dictionary> items = new Hashtable<>(); | ||||
|      | ||||
|     public static boolean refresh() { | ||||
|         /* Refresh the inventory.  | ||||
|          | ||||
|         Returns: (bool) the refresh state | ||||
|         */ | ||||
|         // Pull the sample items.  | ||||
|         items = data_test.fake_items; | ||||
|         return (true); | ||||
|     }; | ||||
|      | ||||
|      | ||||
|     public static Object get(String SKU, String PROPERTY) { | ||||
|         /* Get the information of a particular SKU.  | ||||
|          | ||||
|         Parameters:  | ||||
|             (String) SKU: the SKU of the product to look for | ||||
|             (String) PROPERTY: the property in search | ||||
|         Returns: (Object) the corresponding value | ||||
|         */ | ||||
|          | ||||
|         Dictionary<String, Boolean> PROPERTY_EXISTS = new Hashtable<>(); | ||||
|          | ||||
|         // Find the SKU. This isn't the most efficient method but will do for the purposes of lab.  | ||||
|         Enumeration<String> items_SKU = items.keys(); | ||||
|         PROPERTY_EXISTS.put("SKU", false); | ||||
|         do { | ||||
|             String item_SKU = items_SKU.nextElement(); | ||||
|             PROPERTY_EXISTS.put("SKU", item_SKU.equals(SKU)); | ||||
|         } while (items_SKU.hasMoreElements() && (!(PROPERTY_EXISTS.get("SKU")))); | ||||
|          | ||||
|         // Stop when the SKU is not found.  | ||||
|         if (!PROPERTY_EXISTS.get("SKU")) { | ||||
|             return (null); | ||||
|         }; | ||||
|          | ||||
|         // Find the property within the element.  | ||||
|         Enumeration<String> item_properties = items.get(SKU).keys(); | ||||
|         do { | ||||
|             String item_property = item_properties.nextElement();  | ||||
|             PROPERTY_EXISTS.put("Property", item_property.equals(PROPERTY)); | ||||
|             if (PROPERTY_EXISTS.get("Property")) { | ||||
|                 break; | ||||
|             }; | ||||
|         } while (item_properties.hasMoreElements()); | ||||
|          | ||||
|         if (PROPERTY_EXISTS.get("Property")) { | ||||
|             return (items.get(SKU)).get(PROPERTY); | ||||
|         }; | ||||
|          | ||||
|         return (null); | ||||
|     }; | ||||
|      | ||||
|     public static ArrayList<String> list() { | ||||
|         /* List all inventory items. | ||||
|          | ||||
|         Returns: (ArrayList<String>) The array list | ||||
|         */ | ||||
|          | ||||
|         ArrayList<String> items_SKU = new ArrayList<>(); | ||||
|         Enumeration<String> items_SKU_raw = items.keys(); | ||||
|         do { | ||||
|             String item_SKU = items_SKU_raw.nextElement(); | ||||
|             items_SKU.add(item_SKU); | ||||
|         } while (items_SKU_raw.hasMoreElements()); | ||||
|          | ||||
|         return(items_SKU); | ||||
|     }; | ||||
|      | ||||
|     public static ArrayList list(String PROPERTY) { | ||||
|         ArrayList<Object> items_data = new ArrayList<>(); | ||||
|         ArrayList<String> items_SKU = list(); | ||||
|          | ||||
|         for (String item_SKU : items_SKU) { | ||||
|             Object item_data = ""; | ||||
|             try { | ||||
|                 item_data = items.get(item_SKU).get(PROPERTY); | ||||
|             } catch (Exception e) {System.out.println("Exception occurred: " + e.getMessage());}; | ||||
|              | ||||
|             if (item_data == null) {item_data = "";}; | ||||
|             items_data.add(item_data); | ||||
|         }; | ||||
|          | ||||
|         return(items_data); | ||||
|     }; | ||||
|      | ||||
|     public static ArrayList<String> collate() { | ||||
|         /* Collate the names, replacing unknown names with their SKU.  | ||||
|          | ||||
|         Returns: (ArrayList<String>) the array list of names | ||||
|         */ | ||||
|          | ||||
|         ArrayList<String> items_names_display = list("Name"); | ||||
|         ArrayList<String> items_SKU = list(); | ||||
|         for (int item_rank = 0; item_rank < items_names_display.size(); item_rank++) { | ||||
|             if (items_names_display.get(item_rank).isBlank()) { | ||||
|                 items_names_display.set(item_rank, items_SKU.get(item_rank)); | ||||
|             }; | ||||
|         }; | ||||
|          | ||||
|         return(items_names_display); | ||||
|          | ||||
|     } | ||||
|      | ||||
|     static { | ||||
|         refresh(); | ||||
|     } | ||||
| }; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue