01: package com.ibatis.jpetstore.domain;
02:
03: import java.io.Serializable;
04: import java.math.BigDecimal;
05:
06: public class CartItem implements Serializable {
07:
08: /* Private Fields */
09:
10: private Item item;
11:
12: private int quantity;
13:
14: private boolean inStock;
15:
16: private BigDecimal total;
17:
18: /* JavaBeans Properties */
19:
20: public boolean isInStock() {
21: return inStock;
22: }
23:
24: public void setInStock(boolean inStock) {
25: this .inStock = inStock;
26: }
27:
28: public BigDecimal getTotal() {
29: return total;
30: }
31:
32: public Item getItem() {
33: return item;
34: }
35:
36: public void setItem(Item item) {
37: this .item = item;
38: calculateTotal();
39: }
40:
41: public int getQuantity() {
42: return quantity;
43: }
44:
45: public void setQuantity(int quantity) {
46: this .quantity = quantity;
47: calculateTotal();
48: }
49:
50: /* Public methods */
51:
52: public void incrementQuantity() {
53: quantity++;
54: calculateTotal();
55: }
56:
57: /* Private methods */
58:
59: private void calculateTotal() {
60: if (item != null && item.getListPrice() != null) {
61: total = item.getListPrice().multiply(
62: new BigDecimal(quantity));
63: } else {
64: total = null;
65: }
66: }
67:
68: }
|