1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.domain.jpetstore;
17
18 import java.io.Serializable;
19 import java.math.BigDecimal;
20
21 public class CartItem implements Serializable {
22
23 private static final long serialVersionUID = 1L;
24
25 private Item item;
26 private int quantity;
27 private boolean inStock;
28 private BigDecimal total;
29
30 public boolean isInStock() {
31 return inStock;
32 }
33
34 public void setInStock(boolean inStock) {
35 this.inStock = inStock;
36 }
37
38 public BigDecimal getTotal() {
39 return total;
40 }
41
42 public Item getItem() {
43 return item;
44 }
45
46 public void setItem(Item item) {
47 this.item = item;
48 calculateTotal();
49 }
50
51 public int getQuantity() {
52 return quantity;
53 }
54
55 public void setQuantity(int quantity) {
56 this.quantity = quantity;
57 calculateTotal();
58 }
59
60 public void incrementQuantity() {
61 quantity++;
62 calculateTotal();
63 }
64
65 private void calculateTotal() {
66 if (item != null && item.getListPrice() != null) {
67 total = item.getListPrice().multiply(new BigDecimal(quantity));
68 } else {
69 total = null;
70 }
71 }
72
73 }