/**
* <ul>
* <li> 1 售后退货 001
* <li> 2 售后退款 010
* <li> 3 售后退货&售后退款 011
* <li> 4 售后补发 100
* <li> 5 售后退货&售后补发 101
* <li> 6 售后退款&售后补发 110
* <li> 7 售后退货&售后退款&售后补发 111
* </ul>
* @ClassName: ShdetyEnum
* @Description: 售后业务类型
* @author Sombra
* @date 2018年4月20日 下午5:42:10
* @version V3.0
*/
public enum ShdetyEnum {
/** 售后退货 */
SHTH(1)
/** 售后退款 */
,SHTK(2)
/** 售后补发 */
,SHBF(4)
;
private Integer code;
private ShdetyEnum(Integer code) {
this.code = code;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
/** 业务类型判断是否存在类型 按位与 */
public static boolean existShdety(Integer shdety, ShdetyEnum isDety) {
if (shdety == null) {
shdety = 0;
}
return isDety.getCode().equals(shdety & isDety.getCode());
}
/** 业务类型加入类型 按位或 */
public static Integer addShdety(Integer shdety, ShdetyEnum addDety) {
if (shdety == null) {
shdety = 0;
}
return shdety | addDety.getCode();
}
/** 业务类型去除类型 按位异或 */
public static Integer removeShdety(Integer shdety, ShdetyEnum removeDety) {
if (shdety == null) {
shdety = 0;
}
return shdety ^ removeDety.getCode();
}
public static void main(String[] args) {
Integer shth_shtk = null;
System.out.println("---------------------shth_shtk----------------------");
System.out.println(existShdety(shth_shtk, SHTH));
System.out.println(existShdety(shth_shtk, SHTK));
System.out.println(existShdety(shth_shtk, SHBF));
Integer shth_shtk_shbf = addShdety(shth_shtk, SHBF);
System.out.println("---------------------shth_shtk_shbf----------------------");
System.out.println(existShdety(shth_shtk_shbf, SHTH));
System.out.println(existShdety(shth_shtk_shbf, SHTK));
System.out.println(existShdety(shth_shtk_shbf, SHBF));
Integer shth_shbf = removeShdety(shth_shtk_shbf, ShdetyEnum.SHTK);
System.out.println("---------------------shth_shbf----------------------");
System.out.println(existShdety(shth_shbf, SHTH));
System.out.println(existShdety(shth_shbf, SHTK));
System.out.println(existShdety(shth_shbf, SHBF));
}
}
位运算实现状态控制
最新推荐文章于 2024-07-17 14:59:45 发布