Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rbvs;
- import ict.basic.IDeepCopy;
- import rbvs.product.IProduct;
- import rbvs.record.Record;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Objects;
- //Eldira Sesto, 11815163
- public class Order extends Record implements IDeepCopy {
- private OrderState currentState;
- private List<IProduct> products;
- private Table table;
- Order(long identifier, Table table, List<IProduct> products) {
- super(identifier);
- currentState = OrderState.OPEN;
- this.products = products;
- this.table = table;
- }
- @Override
- public Order deepCopy() {
- Table newTable = new Table(table.getTableIdentifier(), table.getSeatCount());
- List<IProduct> newProducts = new ArrayList<>();
- for(IProduct p : products){
- newProducts.add((IProduct) p.deepCopy());
- }
- return new Order(super.getIdentifier(), newTable, newProducts);
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Order order = (Order) o;
- return currentState == order.currentState &&
- Objects.equals(products, order.products) &&
- Objects.equals(table, order.table);
- }
- public OrderState getState() {
- return currentState;
- }
- public List<IProduct> getProducts() {
- return products;
- }
- public Table getTable() {
- return table;
- }
- public boolean isCanceled(){
- return currentState.equals(OrderState.CANCELLED);
- }
- public boolean isPaid(){
- return currentState.equals(OrderState.PAID);
- }
- public boolean setState(OrderState newState){
- if(!isCanceled() && !isPaid()) {
- currentState = newState;
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement