位运算实现状态控制

/**
 * <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));
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值