add inventory find functions
This commit is contained in:
		
							parent
							
								
									1423eba2a9
								
							
						
					
					
						commit
						4eae82c7e1
					
				
					 1 changed files with 53 additions and 3 deletions
				
			
		|  | @ -14,6 +14,7 @@ import java.util.*; | |||
| public class inventory { | ||||
|      | ||||
|     public static Dictionary<String, Dictionary> items = new Hashtable<>(); | ||||
|     public static ArrayList<String> 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<String> items_SKU = new ArrayList<>(); | ||||
|         Enumeration<String> 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(); | ||||
|     } | ||||
| }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue