buyitem.java

来自「巴巴运动网源码 传智博客出品 不全 一部分代码 可以参考」· Java 代码 · 共 67 行

JAVA
67
字号
package com.itcast.bean;

import com.itcast.bean.product.ProductInfo;
import com.itcast.bean.product.ProductStyle;

public class BuyItem {
	/** 所购买的商品 **/
	private ProductInfo product;
	/** 购买数量 **/
	private int amount;
	
	public BuyItem(ProductInfo product) {
		this.product = product;
	}
	public BuyItem(ProductInfo product, int amount) {
		this.product = product;
		this.amount = amount;
	}
	public ProductInfo getProduct() {
		return product;
	}
	public void setProduct(ProductInfo product) {
		this.product = product;
	}
	public int getAmount() {
		return amount;
	}
	public void setAmount(int amount) {
		this.amount = amount;
	}
	
	@Override
	public int hashCode() {
		String buyitemid = product.hashCode()+ "-";
		if(product.getStyles().size()>0){
			buyitemid += product.getStyles().iterator().next().getId();
		}
		return buyitemid.hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final BuyItem other = (BuyItem) obj;
		if (product == null) {
			if (other.product != null)
				return false;
		} else if (!product.equals(other.product))
			return false;		
		if(product.getStyles().size()!=other.product.getStyles().size()){
			return false;
		}
		if(product.getStyles().size()>0){
			ProductStyle style = product.getStyles().iterator().next();
			ProductStyle otherstyle = other.product.getStyles().iterator().next();
			if(!style.equals(otherstyle)) return false;		
		}		
		return true;
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?