KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: LineItem.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
6 /**
7  * @author Gavin King
8  */

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

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

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

37         public String JavaDoc getProductId() {
38             return productId;
39         }
40         /**
41          * @param productId The productId to set.
42          */

43         public void setProductId(String JavaDoc productId) {
44             this.productId = productId;
45         }
46         /**
47          * @return Returns the orderNumber.
48          */

49         public int getOrderNumber() {
50             return orderNumber;
51         }
52         /**
53          * @param orderNumber The orderNumber to set.
54          */

55         public void setOrderNumber(int orderNumber) {
56             this.orderNumber = orderNumber;
57         }
58         public int hashCode() {
59             return customerId.hashCode() + orderNumber + productId.hashCode();
60         }
61         public boolean equals(Object JavaDoc other) {
62             if (other instanceof Id) {
63                 Id that = (Id) other;
64                 return that.customerId.equals(this.customerId) &&
65                     that.productId.equals(this.productId) &&
66                     that.orderNumber == this.orderNumber;
67             }
68             else {
69                 return false;
70             }
71         }
72     }
73
74     private Id id = new Id();
75     private int quantity;
76     private Order order;
77     private Product product;
78
79     public LineItem(Order o, Product p) {
80         this.order = o;
81         this.id.orderNumber = o.getId().getOrderNumber();
82         this.id.customerId = o.getId().getCustomerId();
83         this.id.productId = p.getProductId();
84         o.getLineItems().add(this);
85     }
86
87     public LineItem() {}
88
89     /**
90      * @return Returns the order.
91      */

92     public Order getOrder() {
93         return order;
94     }
95     /**
96      * @param order The order to set.
97      */

98     public void setOrder(Order order) {
99         this.order = order;
100     }
101     /**
102      * @return Returns the product.
103      */

104     public Product getProduct() {
105         return product;
106     }
107     /**
108      * @param product The product to set.
109      */

110     public void setProduct(Product product) {
111         this.product = product;
112     }
113     /**
114      * @return Returns the quantity.
115      */

116     public int getQuantity() {
117         return quantity;
118     }
119     /**
120      * @param quantity The quantity to set.
121      */

122     public void setQuantity(int quantity) {
123         this.quantity = quantity;
124     }
125     /**
126      * @return Returns the id.
127      */

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

134     public void setId(Id id) {
135         this.id = id;
136     }
137 }
138
Popular Tags