📄 cartitem.java
字号:
package test.models;
import java.io.*;
import java.math.*;
/**
*代表了购物车中各个item的信息
*/
public class CartItem implements Serializable {
/* Private Fields */
private Item item=new Item();
private int quantity;
private boolean inStock;
private BigDecimal total;
/* JavaBeans Properties */
public boolean isInStock() { return inStock; }
public void setInStock(boolean inStock) { this.inStock = inStock; }
public BigDecimal getTotal() { return total; }
public Item getItem() { return item; }
public void setItem(Item item) {
this.item = item;
calculateTotal();
}
public void setItemId(Item item)
{
this.item.setItemId(item.getItemId());
}
public String getItemId()
{
return this.item.getItemId();
}
// public void setQuantity(Item item)
// {
// this.item.setQuantity(item.getQuantity());
// }
//
// public int getQuantity()
// {
// return this.item.getQuantity();
// }
public int getQuantity() { return quantity; }
public void setQuantity(int quantity) {
this.quantity = quantity;
calculateTotal();
}
/* Public methods */
public void incrementQuantity() {
++quantity;
calculateTotal();
}
/**
* 计算item的金额
*/
private void calculateTotal() {
if (item != null && item.getListPrice() != null) {
total = item.getListPrice().multiply(new BigDecimal(quantity));
} else {
total = null;
}
}
public boolean equals(Object obj)
{
if(obj instanceof CartItem)
{
CartItem objTemp=(CartItem)obj;
if(item.getItemId().equals(objTemp.getItem().getItemId()))
return true;
else
return false;
}
else
return false;
}
public int hashCode()
{
return item.getItemId().hashCode();
}
public String toString()
{
return item.getItemId();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -