📄 categoryitem.java
字号:
package com.bluesky.elecall.domain;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
public class CategoryItem {
private Long id;
private String name;
private int level = -1;// 0 root, 1,2,3,4:end,5 series
private Long imageFileId;
private int displayIndex=0;
private CategoryItem parent;
private Set<CategoryItem> children = new HashSet<CategoryItem>();
private Set<ProductAttributeType> attributeTypes =new HashSet<ProductAttributeType>();
private Set<Product> products = new HashSet<Product>();
public static int ROOT_LEVEL=0;
public Set<ProductAttributeType> getAttributeTypes() {
return attributeTypes;
}
public void setAttributeTypes(Set<ProductAttributeType> attributeTypes) {
this.attributeTypes = attributeTypes;
}
public Set<Product> getProducts() {
return products;
}
public void setProducts(Set<Product> products) {
this.products = products;
}
public boolean isRoot()
{
return level==ROOT_LEVEL;
}
public CategoryItem addChild(CategoryItem childItem) {
getChildren().add(childItem);
childItem.setParent(this);
childItem.setLevel(this.getLevel()+1);
return childItem;
}
public CategoryItem removeChild(CategoryItem childItem) {
children.remove(childItem);
childItem.setParent(null);
return childItem;
}
public CategoryItem() {
}
public CategoryItem(String name) {
this.name = name;
}
public CategoryItem(String name, int displayIndex) {
this.name = name;
this.displayIndex = displayIndex;
}
public CategoryItem(int level) {
this.level = level;
}
public String toString() {
long partentId = -1;
if (getParent() != null)
partentId = getParent().getId();
return String.format("id:%s,name:%s,level:%d,imageId:%s,parent:%s", id,
name, level, imageFileId, partentId);
}
public void setParent(CategoryItem parent) {
this.parent = parent;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public Long getImageFileId() {
return imageFileId;
}
public void setImageFileId(Long imageFileId) {
this.imageFileId = imageFileId;
}
public Set<CategoryItem> getChildren() {
return this.children;
}
public CategoryItem getParent() {
return this.parent;
}
public int getDisplayIndex() {
return displayIndex;
}
public void setDisplayIndex(int displayIndex) {
this.displayIndex = displayIndex;
}
public void setChildren(Set<CategoryItem> children) {
this.children = children;
}
public static CategoryItem getSample(CategoryItem parent){
String[] names = new String[]{"无线电","继电器","电表","信息技术","五金配件","控制设备","机壳与风扇","电气安装","线缆","继电器、开关与指示器","过程控制","高压与安全","半导体与光电子","变压器","无源组件","电池","电源","硬件及 ESD 保护","连接器"};
String[] familyNames = new String[]{"时尚","经典","黑白","工用","军用","A","B","C","极品","奢华"};
Random random = new Random();
CategoryItem ci = new CategoryItem();
String name="";
if(parent.getLevel()==4)
name = familyNames[random.nextInt(familyNames.length)];
else
name = names[random.nextInt(names.length)];
ci.setName(name);
ci.setParent(parent);
parent.addChild(ci);
return ci;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -