Class Controller
- java.lang.Object
-
- Controller
-
public class Controller extends java.lang.ObjectController class is responsible for managing instances of clients, vendors, orders and products. Also represents a collection of instances of various entities used in the system, including clients, vendors, orders, and products.
-
-
Constructor Summary
Constructors Constructor Description Controller()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddClientToInstances(java.lang.String name, boolean active)Creates a new client with the specified name and active status, and adds it to the list of client instances.voidaddDefaultObjects()This method initializes default instances for vendors, products, clients and orders.voidaddOrderToInstances(Client client, java.util.ArrayList<ProductOnOrder> products)Adds the specified order to the list of order instances.voidaddProductToInstances(java.lang.String name, float price, char nutri, Vendor vendor)Creates a new product with the specified name, price, nutrition grade, and vendor, and adds it to the list of product instances.java.lang.StringaddProductToOrder(Product product, java.util.ArrayList<ProductOnOrder> products, int qty)Adds a specified quantity of a Product object to an ArrayList of ProductOnOrder objects.voidaddVendorToInstances(java.lang.String name, boolean active)Creates a new vendor with the specified name and active status, and adds it to the list of vendor instances.voiddropClientFromInstances(int clientID)This method removes the client instance with the given client ID from the clientInstances ArrayList.voiddropDefaultObjects()This method drops the default objects related to clients, products, orders, and vendors from their respective lists of default objects.voiddropOrderFromInstances(int orderID)This method removes the order instance with the given order ID from the orderInstances ArrayList.voiddropProductFromInstances(int productID)This method removes the product instance with the given product ID from the productInstances ArrayList.java.lang.StringdropProductFromOrder(int id, java.util.ArrayList<ProductOnOrder> products, int qty)Drops a specified quantity of a ProductOnOrder object from an ArrayList of ProductOnOrder objects.voiddropVendorFromInstances(int vendorID)This method removes the vendor instance with the given vendor ID from the vendorInstances ArrayList.OrderfindOrderById(int id)Searches for an Order object in the system by its ID.java.util.ArrayList<Client>getClientInstances()Returns the ArrayList containing all client instances.java.util.ArrayList<java.lang.Integer>getDefaultObjectsClient()Returns the ArrayList of default objects related to clients.java.util.ArrayList<java.lang.Integer>getDefaultObjectsOrder()Returns the ArrayList of default objects related to orders.java.util.ArrayList<java.lang.Integer>getDefaultObjectsProduct()Returns the ArrayList of default objects related to products.java.util.ArrayList<java.lang.Integer>getDefaultObjectsProductOnOrder()Returns a list of integers representing the default objects for the ProductOnOrder class.java.util.ArrayList<java.lang.Integer>getDefaultObjectsVendor()java.util.ArrayList<Order>getOrderInstances()Returns the ArrayList containing all order instances.ProductgetProductById(int id)Returns the Product object with the specified ID.java.util.ArrayList<Product>getProductInstances()Returns the ArrayList containing all product instances.static java.util.ArrayList<ProductOnOrder>getProductOnOrderInstances()java.lang.StringgetShoppingList(java.util.ArrayList<ProductOnOrder> products)Returns a formatted String representation of an ArrayList of ProductOnOrder objects, representing a shopping list.floatgetTotalPrice(java.util.ArrayList<ProductOnOrder> products)Calculates and returns the total price of an ArrayList of ProductOnOrder objects.java.util.ArrayList<Vendor>getVendorInstances()Returns the ArrayList containing all vendor instances.booleanisProductInOrder(Product product, java.util.ArrayList<ProductOnOrder> products)Returns whether a Product object is in an ArrayList of ProductOnOrder objects.
-
-
-
Method Detail
-
getClientInstances
public java.util.ArrayList<Client> getClientInstances()
Returns the ArrayList containing all client instances.- Returns:
- ArrayList containing all client instances.
-
getVendorInstances
public java.util.ArrayList<Vendor> getVendorInstances()
Returns the ArrayList containing all vendor instances.- Returns:
- ArrayList containing all vendor instances.
-
getOrderInstances
public java.util.ArrayList<Order> getOrderInstances()
Returns the ArrayList containing all order instances.- Returns:
- ArrayList containing all order instances.
-
getProductInstances
public java.util.ArrayList<Product> getProductInstances()
Returns the ArrayList containing all product instances.- Returns:
- ArrayList containing all product instances.
-
getProductOnOrderInstances
public static java.util.ArrayList<ProductOnOrder> getProductOnOrderInstances()
-
getDefaultObjectsVendor
public java.util.ArrayList<java.lang.Integer> getDefaultObjectsVendor()
-
getDefaultObjectsClient
public java.util.ArrayList<java.lang.Integer> getDefaultObjectsClient()
Returns the ArrayList of default objects related to clients.- Returns:
- the ArrayList of default objects related to clients.
-
getDefaultObjectsProduct
public java.util.ArrayList<java.lang.Integer> getDefaultObjectsProduct()
Returns the ArrayList of default objects related to products.- Returns:
- the ArrayList of default objects related to products.
-
getDefaultObjectsOrder
public java.util.ArrayList<java.lang.Integer> getDefaultObjectsOrder()
Returns the ArrayList of default objects related to orders.- Returns:
- the ArrayList of default objects related to orders.
-
getDefaultObjectsProductOnOrder
public java.util.ArrayList<java.lang.Integer> getDefaultObjectsProductOnOrder()
Returns a list of integers representing the default objects for the ProductOnOrder class.- Returns:
- an ArrayList of integers representing the default objects for the ProductOnOrder class.
-
getProductById
public Product getProductById(int id)
Returns the Product object with the specified ID.- Parameters:
id- the ID of the Product to retrieve- Returns:
- the Product object with the specified ID, or null if no Product with the specified ID is found
-
isProductInOrder
public boolean isProductInOrder(Product product, java.util.ArrayList<ProductOnOrder> products)
Returns whether a Product object is in an ArrayList of ProductOnOrder objects.- Parameters:
product- the Product object to search forproducts- the ArrayList of ProductOnOrder objects to search in- Returns:
- true if the Product object is found in the ArrayList, false otherwise
-
addProductToOrder
public java.lang.String addProductToOrder(Product product, java.util.ArrayList<ProductOnOrder> products, int qty)
Adds a specified quantity of a Product object to an ArrayList of ProductOnOrder objects.- Parameters:
product- the Product object to addproducts- the ArrayList of ProductOnOrder objects to add toqty- the quantity of the Product object to add- Returns:
- a String message indicating whether the Product object was successfully added to the ArrayList or not
-
dropProductFromOrder
public java.lang.String dropProductFromOrder(int id, java.util.ArrayList<ProductOnOrder> products, int qty)Drops a specified quantity of a ProductOnOrder object from an ArrayList of ProductOnOrder objects.- Parameters:
id- the ID of the ProductOnOrder object to dropproducts- the ArrayList of ProductOnOrder objects to drop fromqty- the quantity of the ProductOnOrder object to drop- Returns:
- a String message indicating whether the ProductOnOrder object was successfully dropped from the ArrayList or not
-
getShoppingList
public java.lang.String getShoppingList(java.util.ArrayList<ProductOnOrder> products)
Returns a formatted String representation of an ArrayList of ProductOnOrder objects, representing a shopping list.- Parameters:
products- the ArrayList of ProductOnOrder objects to represent as a shopping list- Returns:
- a formatted String representation of the shopping list
-
getTotalPrice
public float getTotalPrice(java.util.ArrayList<ProductOnOrder> products)
Calculates and returns the total price of an ArrayList of ProductOnOrder objects.- Parameters:
products- the ArrayList of ProductOnOrder objects to calculate the total price of- Returns:
- the total price of the ProductOnOrder objects in the ArrayList
-
findOrderById
public Order findOrderById(int id)
Searches for an Order object in the system by its ID. If the ID is associated with a default object, an error message is printed and null is returned. If the ID is not found in the system, an error message is printed and null is returned.- Parameters:
id- the ID of the Order object to search for- Returns:
- the Order object with the given ID if found, null otherwise
-
addProductToInstances
public void addProductToInstances(java.lang.String name, float price, char nutri, Vendor vendor)Creates a new product with the specified name, price, nutrition grade, and vendor, and adds it to the list of product instances.- Parameters:
name- the name of the productprice- the price of the productnutri- the nutrition grade of the productvendor- the vendor of the product
-
addClientToInstances
public void addClientToInstances(java.lang.String name, boolean active)Creates a new client with the specified name and active status, and adds it to the list of client instances.- Parameters:
name- the name of the clientactive- the active status of the client
-
addVendorToInstances
public void addVendorToInstances(java.lang.String name, boolean active)Creates a new vendor with the specified name and active status, and adds it to the list of vendor instances.- Parameters:
name- the name of the vendoractive- the active status of the vendor
-
addOrderToInstances
public void addOrderToInstances(Client client, java.util.ArrayList<ProductOnOrder> products)
Adds the specified order to the list of order instances.
-
dropClientFromInstances
public void dropClientFromInstances(int clientID)
This method removes the client instance with the given client ID from the clientInstances ArrayList.- Parameters:
clientID- the ID of the client to be removed
-
dropVendorFromInstances
public void dropVendorFromInstances(int vendorID)
This method removes the vendor instance with the given vendor ID from the vendorInstances ArrayList.- Parameters:
vendorID- the ID of the vendor to be removed
-
dropProductFromInstances
public void dropProductFromInstances(int productID)
This method removes the product instance with the given product ID from the productInstances ArrayList.- Parameters:
productID- the ID of the product to be removed
-
dropOrderFromInstances
public void dropOrderFromInstances(int orderID)
This method removes the order instance with the given order ID from the orderInstances ArrayList.- Parameters:
orderID- the ID of the order to be removed
-
addDefaultObjects
public void addDefaultObjects()
This method initializes default instances for vendors, products, clients and orders. The vendors, products and clients are added to their respective instance lists. The orders are created using the default products and clients and added to the order instance list.
-
dropDefaultObjects
public void dropDefaultObjects()
This method drops the default objects related to clients, products, orders, and vendors from their respective lists of default objects. It calls the methods to drop each client, vendor, product, and order from their instances and removes them from their respective lists of default objects. Note that the defaultObjectsClient, defaultObjectsProduct, defaultObjectsOrder, and defaultObjectsVendor lists must be initialized and populated prior to calling this method.
-
-