public static void printInput(Product[] objectArray) throws IOException { System.out.println("The input data from the file is: \n"); for (Product item : objectArray) { System.out.println(item.getName() + " " + item.getPrice()); } } // (optional) - displays what was read from the input file
// add product to database using a product object public boolean addProductEntry(Product product, String server_name) { boolean success = true; this.product_list.add(product); // add product to database addStoredLocation(product.getName(), server_name); // update stored locations of product return success; }
// retrieve stored list of products from products file public Product[] getStoredProducts() { Product[] products = (Product[]) readFile(getProductFileName()); // print names of products being returned for (Product product : products) { System.out.println("getStoredProducts: Returned " + product.getName()); } return products; }
// retrieve product from database public Product getProductEntry(String name) { Product product = null; for (Product entry : getProducts()) { if (entry != null && entry.getName().equals(name)) { product = entry; break; } } return product; }
// remove product from database public boolean deleteProduct(String name) { boolean success = true; Iterator<Product> products = this.product_list.iterator(); while (products.hasNext()) { Product entry = products.next(); if (entry.getName().equals(name)) { success = this.product_list.remove(entry); removeStoredLocation(name); // remove product entry break; } } return success; }