001: package net.ar.webonswing.petstore.model;
002:
003: import java.io.*;
004: import java.util.*;
005:
006: public class Order implements Serializable {
007: public static final String CANCELLED = "cancelled";
008: public static final String DELIVERED = "delivered";
009: public static final String PENDING = "pending";
010:
011: protected Address address;
012: protected CreditCard creditCard;
013: protected Customer customer;
014: protected Date date;
015: protected Integer id;
016: protected Set orderItems = new HashSet();
017: protected String status = PENDING;
018:
019: public Order() {
020: }
021:
022: public Order(Customer aCustomer) {
023: customer = aCustomer;
024: creditCard = customer.getCreditCard();
025: address = customer.getAddress();
026: date = new Date();
027: }
028:
029: public void add(Item item, int quantity) {
030: orderItems.add(new OrderItem(item, quantity));
031: }
032:
033: public Address getAddress() {
034: return address;
035: }
036:
037: public CreditCard getCreditCard() {
038: return creditCard;
039: }
040:
041: public Customer getCustomer() {
042: return customer;
043: }
044:
045: public Date getDate() {
046: return date;
047: }
048:
049: public Integer getId() {
050: return id;
051: }
052:
053: public Set getOrderItems() {
054: return orderItems;
055: }
056:
057: public String getStatus() {
058: return status;
059: }
060:
061: public double getTotal() {
062: double total = 0;
063: Iterator it = orderItems.iterator();
064:
065: while (it.hasNext()) {
066: total += ((OrderItem) it.next()).getSubTotal();
067: }
068:
069: return total;
070: }
071:
072: public void setAddress(Address address) {
073: this .address = address;
074: }
075:
076: public void setCreditCard(CreditCard creditCard) {
077: this .creditCard = creditCard;
078: }
079:
080: public void setCustomer(Customer customer) {
081: this .customer = customer;
082: }
083:
084: public void setDate(Date date) {
085: this .date = date;
086: }
087:
088: public void setId(Integer id) {
089: this .id = id;
090: }
091:
092: public void setOrderItems(Set orderItems) {
093: this .orderItems = orderItems;
094: }
095:
096: public void setStatus(String status) {
097: this.status = status;
098: }
099:
100: }
|