KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > jpetstore > domain > LineItem


1 package com.ibatis.jpetstore.domain;
2
3 import java.io.Serializable JavaDoc;
4 import java.math.BigDecimal JavaDoc;
5
6
7 public class LineItem implements Serializable JavaDoc {
8
9   /* Private Fields */
10
11   private int orderId;
12   private int lineNumber;
13   private int quantity;
14   private String JavaDoc itemId;
15   private BigDecimal JavaDoc unitPrice;
16   private Item item;
17   private BigDecimal JavaDoc total;
18
19   /* Constructors */
20
21   public LineItem() {
22   }
23
24   public LineItem(int lineNumber, CartItem cartItem) {
25     this.lineNumber = lineNumber;
26     this.quantity = cartItem.getQuantity();
27     this.itemId = cartItem.getItem().getItemId();
28     this.unitPrice = cartItem.getItem().getListPrice();
29     this.item = cartItem.getItem();
30   }
31
32   /* JavaBeans Properties */
33
34   public int getOrderId() {
35     return orderId;
36   }
37
38   public void setOrderId(int orderId) {
39     this.orderId = orderId;
40   }
41
42   public int getLineNumber() {
43     return lineNumber;
44   }
45
46   public void setLineNumber(int lineNumber) {
47     this.lineNumber = lineNumber;
48   }
49
50   public String JavaDoc getItemId() {
51     return itemId;
52   }
53
54   public void setItemId(String JavaDoc itemId) {
55     this.itemId = itemId;
56   }
57
58   public BigDecimal JavaDoc getUnitPrice() {
59     return unitPrice;
60   }
61
62   public void setUnitPrice(BigDecimal JavaDoc unitprice) {
63     this.unitPrice = unitprice;
64   }
65
66   public BigDecimal JavaDoc getTotal() {
67     return total;
68   }
69
70   public Item getItem() {
71     return item;
72   }
73
74   public void setItem(Item item) {
75     this.item = item;
76     calculateTotal();
77   }
78
79   public int getQuantity() {
80     return quantity;
81   }
82
83   public void setQuantity(int quantity) {
84     this.quantity = quantity;
85     calculateTotal();
86   }
87
88   /* Private methods */
89
90   private void calculateTotal() {
91     if (item != null && item.getListPrice() != null) {
92       total = item.getListPrice().multiply(new BigDecimal JavaDoc(quantity));
93     } else {
94       total = null;
95     }
96   }
97
98
99 }
100
Popular Tags