KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > cid > Order


1 //$Id: Order.java,v 1.2 2004/11/25 14:37:00 steveebersole Exp $
2
package org.hibernate.test.cid;
3
4 import java.io.Serializable JavaDoc;
5 import java.math.BigDecimal JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Calendar JavaDoc;
8 import java.util.Collection JavaDoc;
9
10 /**
11  * @author Gavin King
12  */

13 public class Order {
14     public static class Id implements Serializable JavaDoc {
15         private String JavaDoc customerId;
16         private int orderNumber;
17
18         public Id(String JavaDoc customerId, int orderNumber) {
19             this.customerId = customerId;
20             this.orderNumber = orderNumber;
21         }
22         public Id() {}
23
24         /**
25          * @return Returns the customerId.
26          */

27         public String JavaDoc getCustomerId() {
28             return customerId;
29         }
30         /**
31          * @param customerId The customerId to set.
32          */

33         public void setCustomerId(String JavaDoc customerId) {
34             this.customerId = customerId;
35         }
36         /**
37          * @return Returns the orderNumber.
38          */

39         public int getOrderNumber() {
40             return orderNumber;
41         }
42         /**
43          * @param orderNumber The orderNumber to set.
44          */

45         public void setOrderNumber(int orderNumber) {
46             this.orderNumber = orderNumber;
47         }
48         public int hashCode() {
49             return customerId.hashCode() + orderNumber;
50         }
51         public boolean equals(Object JavaDoc other) {
52             if (other instanceof Id) {
53                 Id that = (Id) other;
54                 return that.customerId.equals(this.customerId) &&
55                     that.orderNumber == this.orderNumber;
56             }
57             else {
58                 return false;
59             }
60         }
61     }
62
63     private Id id = new Id();
64     private Calendar JavaDoc orderDate;
65     private Customer customer;
66     private Collection JavaDoc lineItems = new ArrayList JavaDoc();
67     private BigDecimal JavaDoc total;
68
69     public Order(Customer customer) {
70         this.customer = customer;
71         this.id.customerId = customer.getCustomerId();
72         this.id.orderNumber = customer.getOrders().size();
73         customer.getOrders().add(this);
74     }
75
76     public Order() {}
77
78     /**
79      * @return Returns the customer.
80      */

81     public Customer getCustomer() {
82         return customer;
83     }
84     /**
85      * @param customer The customer to set.
86      */

87     public void setCustomer(Customer customer) {
88         this.customer = customer;
89     }
90     /**
91      * @return Returns the lineItems.
92      */

93     public Collection JavaDoc getLineItems() {
94         return lineItems;
95     }
96     /**
97      * @param lineItems The lineItems to set.
98      */

99     public void setLineItems(Collection JavaDoc lineItems) {
100         this.lineItems = lineItems;
101     }
102     /**
103      * @return Returns the orderDate.
104      */

105     public Calendar JavaDoc getOrderDate() {
106         return orderDate;
107     }
108     /**
109      * @param orderDate The orderDate to set.
110      */

111     public void setOrderDate(Calendar JavaDoc orderDate) {
112         this.orderDate = orderDate;
113     }
114     /**
115      * @return Returns the total.
116      */

117     public BigDecimal JavaDoc getTotal() {
118         return total;
119     }
120     /**
121      * @param total The total to set.
122      */

123     public void setTotal(BigDecimal JavaDoc total) {
124         this.total = total;
125     }
126     /**
127      * @return Returns the id.
128      */

129     public Id getId() {
130         return id;
131     }
132     /**
133      * @param id The id to set.
134      */

135     public void setId(Id id) {
136         this.id = id;
137     }
138
139     public LineItem generateLineItem( Product product, int quantity ) {
140         LineItem li = new LineItem( this, product );
141         li.setQuantity( quantity );
142         lineItems.add( li );
143         return li;
144     }
145 }
146
Popular Tags