View Javadoc
1   /*
2    *    Copyright 2009-2022 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.apache.ibatis.domain.jpetstore;
17  
18  import java.io.Serializable;
19  import java.math.BigDecimal;
20  
21  public class LineItem implements Serializable {
22  
23    private static final long serialVersionUID = 1L;
24  
25    private int orderId;
26    private int lineNumber;
27    private int quantity;
28    private String itemId;
29    private BigDecimal unitPrice;
30    private Item item;
31    private BigDecimal total;
32  
33    public LineItem() {
34    }
35  
36    public LineItem(int lineNumber, CartItem cartItem) {
37      this.lineNumber = lineNumber;
38      this.quantity = cartItem.getQuantity();
39      this.itemId = cartItem.getItem().getItemId();
40      this.unitPrice = cartItem.getItem().getListPrice();
41      this.item = cartItem.getItem();
42    }
43  
44    public int getOrderId() {
45      return orderId;
46    }
47  
48    public void setOrderId(int orderId) {
49      this.orderId = orderId;
50    }
51  
52    public int getLineNumber() {
53      return lineNumber;
54    }
55  
56    public void setLineNumber(int lineNumber) {
57      this.lineNumber = lineNumber;
58    }
59  
60    public String getItemId() {
61      return itemId;
62    }
63  
64    public void setItemId(String itemId) {
65      this.itemId = itemId;
66    }
67  
68    public BigDecimal getUnitPrice() {
69      return unitPrice;
70    }
71  
72    public void setUnitPrice(BigDecimal unitprice) {
73      this.unitPrice = unitprice;
74    }
75  
76    public BigDecimal getTotal() {
77      return total;
78    }
79  
80    public Item getItem() {
81      return item;
82    }
83  
84    public void setItem(Item item) {
85      this.item = item;
86      calculateTotal();
87    }
88  
89    public int getQuantity() {
90      return quantity;
91    }
92  
93    public void setQuantity(int quantity) {
94      this.quantity = quantity;
95      calculateTotal();
96    }
97  
98    private void calculateTotal() {
99      if (item != null && item.getListPrice() != null) {
100       total = item.getListPrice().multiply(new BigDecimal(quantity));
101     } else {
102       total = null;
103     }
104   }
105 
106 }