hey guyz how do you change all of these methods when you are replacing the arraylist with a hash map
Java Code:
public Order() {
this.orderNumber = orderNumberCounter;
orderNumberCounter++;
orderLines = new ArrayList<OrderLine>();
orderTime = Calendar.getInstance();
}
/**
* Constructs a new Order object with the value of the passed in parameters
*
* @param orderLines - the initial value of each order line that is in this order
*/
public Order(ArrayList<OrderLine> orderLines) {
this.orderNumber = orderNumberCounter;
orderNumberCounter++;
for (OrderLine orderLine : orderLines) {
this.orderLines.add(orderLine);
}
this.orderTime = Calendar.getInstance();
}
/**
* Return the food numbers of foods that are in this order
*
* @return a copy of attribute foodNumbers
*/
public ArrayList<OrderLine> getOrderLines() {
return (ArrayList<OrderLine>)orderLines.clone();
}
/**
* Add a food to the order along with the correponding quantity
*
* @param food - the food to add
* @param quantity - the quantity of the food
* @return true if the food item is added successfully, false otherwise
*/
public boolean addItem(Food food, int quantity) {
if (!orderLines.contains(searchOrderLine(food))) {
return this.orderLines.add(new OrderLine(food, quantity));
}
return false;
}
/**
* Add an order line to the order
*
* @param orderLine - the new order line to add in
* @return true if the orderLine is added successfully, false otherwise
*/
public boolean addItem(OrderLine orderLine) {
if (!orderLines.contains(searchOrderLine(orderLine.getFood()))) {
return this.orderLines.add(orderLine);
}
return false;
}
/**
* Remove a food from the order
*
* @param food - the food to remove
* @return true if the food item is removed successfully, false otherwise
*/
public boolean removeItem(Food food) {
return this.orderLines.remove(searchOrderLine(food));
}
/**
* Search whether a food already existed in the order
*
* @param food - the food to search
* @return the order line containing the food
*/
private OrderLine searchOrderLine(Food food) {
for (OrderLine orderLine : orderLines) {
if (orderLine.getFood().getFoodNumber() == food.getFoodNumber()) {
return orderLine;
}
}
return new OrderLine();
}
tahnx in advance