130 lines
3 KiB
Java
130 lines
3 KiB
Java
package model;
|
|
|
|
import model.exceptions.OrderException;
|
|
|
|
import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* This class represent a typical order in our shop.
|
|
*/
|
|
public class Order {
|
|
|
|
private String customer;
|
|
private List<Pizza> pizzas;
|
|
private Date date;
|
|
private OrderState state;
|
|
|
|
public Order(String customer, List<Pizza> pizzas, Date date) {
|
|
this.customer = customer;
|
|
this.pizzas = pizzas;
|
|
this.date = date;
|
|
state = OrderState.IN_PROGRESS;
|
|
}
|
|
|
|
public String getCustomer() {
|
|
return customer;
|
|
}
|
|
|
|
/**
|
|
* Set the customer. This is not possible if the order is already deliverd
|
|
*
|
|
* @param customer
|
|
*/
|
|
public void setCustomer(String customer) {
|
|
if(this.state == OrderState.IN_PROGRESS)
|
|
this.customer = customer;
|
|
}
|
|
|
|
public List<Pizza> getPizzas() {
|
|
return pizzas;
|
|
}
|
|
|
|
/**
|
|
* Set the pizzas.
|
|
*
|
|
* @param pizzas
|
|
* @throws OrderException if {@see state} is not in {@link OrderState#IN_PROGRESS}.
|
|
*/
|
|
public void setPizzas(List<Pizza> pizzas) throws OrderException {
|
|
if(this.state == OrderState.IN_PROGRESS)
|
|
this.pizzas = pizzas;
|
|
else throw new OrderException();
|
|
}
|
|
|
|
/**
|
|
* Add pizza p to the order
|
|
*
|
|
* @param p
|
|
* @throws OrderException if {@see state} is not in {@link OrderState#IN_PROGRESS}.
|
|
*/
|
|
public void addPizza(Pizza p) throws OrderException {
|
|
if(this.state == OrderState.IN_PROGRESS)
|
|
this.pizzas.add(p);
|
|
else throw new OrderException();
|
|
}
|
|
|
|
/**
|
|
* @param state the state to be set.
|
|
*/
|
|
public void setOrderState(OrderState state) {
|
|
this.state = state;
|
|
}
|
|
|
|
public OrderState getOrderState() {return this.state;}
|
|
|
|
public Date getDate() {
|
|
return date;
|
|
}
|
|
|
|
/**
|
|
* Set the Time of the Order
|
|
*
|
|
* @param date
|
|
* @throws IllegalArgumentException if the Order is in the future.
|
|
*/
|
|
public void setDate(Date date) throws IllegalArgumentException {
|
|
Date today = new Date();
|
|
Calendar c = Calendar.getInstance();
|
|
c.setTime(today);
|
|
c.add(Calendar.DAY_OF_MONTH, 20);
|
|
Date currentDatePlus20d = c.getTime();
|
|
|
|
if(date.before(currentDatePlus20d))
|
|
this.date = date;
|
|
else throw new IllegalArgumentException();
|
|
}
|
|
|
|
/**
|
|
* State of the order.
|
|
*/
|
|
public enum OrderState {
|
|
/**
|
|
* Customer enter all items
|
|
*/
|
|
IN_PROGRESS,
|
|
/**
|
|
* Customer finish order, waiting to be prepared
|
|
*/
|
|
WAIT,
|
|
/**
|
|
* Order is in preperatopion
|
|
*/
|
|
IN_PREPERATION,
|
|
/**
|
|
* Order is cooked
|
|
*/
|
|
ORDER_COMPLET,
|
|
/**
|
|
* Order is in delivery by the waiter or deliveryman
|
|
*/
|
|
IN_DELIVERY,
|
|
/**
|
|
* Order is finished completely.
|
|
*/
|
|
DELIVERD
|
|
}
|
|
}
|