入力パラメータは、列挙クラスに含まれるかどうかを判断します.

1400 ワード

列挙クラス:
public enum  UserRewardTaskType {

    UPDATE_NAME_REWARD_MONEY("1000"," 1"),
    UPDATE_HEAD_REWARD_MONEY("1001"," 2"),
    FILL_ADDRESS_REWARD_MONEY("1002"," 3"),
    ;
    //code 1000,1001,1002
    private String code;
    //desc 1,2,3
    private String desc;

    private UserRewardTaskType(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}

判断:
 @Override
 public void before (int task_id) {
                boolean has_task=false;
                // 
                for(UserRewardTaskType u:UserRewardTaskType.values()){
                    if(u.getCode().equals(String.valueOf(task_id))){
                        has_task=true;
                        break;
                    }
                }
                // 
                if (!has_task){
                    logger.error(MessageFormat.format("addCompleteTask,  task_id:{0}",task_id));
                    throw new ShopException(new ShopError(ShopResultCode.USER_REWARD_TASK));
                }
            }