使用枚举实现树结构

1.父枚举NoticeTypeEnum

package com.messageService.enums;

import java.util.Arrays;
import java.util.List;

public enum NoticeTypeEnum {

	SYSTEM(1,"系统通知") {
		@Override
		public List getMessageTypes() {
			return Arrays.asList(MessageTypeEnum.ORDER,MessageTypeEnum.REFUND,MessageTypeEnum.AFTERSALE,MessageTypeEnum.COUPON);
		}
	},
	INTERACTION(2,"互动通知") {
		@Override
		public List getMessageTypes() {
			return Arrays.asList(MessageTypeEnum.COMMENT,MessageTypeEnum.LIKE,MessageTypeEnum.REPLY);
		}
	},
	DELIVER(3, "物流通知") {
		@Override
		public List getMessageTypes() {
			return Arrays.asList(MessageTypeEnum.SHIPMENTS,MessageTypeEnum.SIGNFOR);
		}
	},
	ACTIVITY(4, "活动通知") {
		@Override
		public List getMessageTypes() {
			return Arrays.asList(MessageTypeEnum.ACTIVITY);
		}
	};
	
	private NoticeTypeEnum(Integer code, String remark) {
		this.code = code;
		this.remark = remark;
	}
	
	
	private Integer code;
	private String remark;
	public Integer getCode() {
		return code;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	public abstract List getMessageTypes();
}
2.子枚举MessageTypeEnum

package com.messageService.enums;

public enum MessageTypeEnum {

	ORDER(1, "订单提醒"),
	REFUND(2, "退款提醒"),
	AFTERSALE(4, "售后提醒"), 
	COUPON(5, "优惠券提醒"), 
	ACTIVITY(6, "活动通知"),
	COMMENT(7, "评论通知"),
	REPLY(8, "回复通知"),
	LIKE(9, "点赞通知"),
	SHIPMENTS(10, "发货通知"),
	SIGNFOR(11, "签收通知");
	
	private Integer code;
	private String remark;
	
	private MessageTypeEnum(Integer code, String remark) {
		this.code = code;
		this.remark = remark;
	}
	public Integer getCode() {
		return code;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
}



你可能感兴趣的:(java,enum)