java如何消除繁琐的if else 语句?-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

java如何消除繁琐的if else 语句?

蛮大人123 2016-03-04 16:48:03 3691

求助:一堆的if else 嵌套

private Map versionCheck(Map mapParam) {
    Map msg = new HashMap();
    if(!"".equals(PMSUtil.isNull(mapParam.get("IS_INTERNET")))){
      String checkVersion =SystemGlobals.getProperty("IS_CHECK");
      if("1".equals(checkVersion)){
          String versions =SystemGlobals.getProperty("VERSION");
          String version =PMSUtil.isNull(mapParam.get("VERSION"));
          String taxRegisterNo=PMSUtil.isNull(mapParam.get(""));
          String whiteList =SystemGlobals.getProperty("NO_CHECK_TAX_REGISTER_NO");
          if((","+whiteList+",").indexOf((","+taxRegisterNo+","))==-1){
              if((","+versions+",").indexOf(","+version+",")==-1){//找不到
                  msg.put("RESULT", "0001");
                  msg.put("MSG", "FAILD");
              }else{
                 msg.put("RESULT", ""0000"");
              }
          }else{
            msg.put("RESULT", ""0000"");
          }
      }else{
          msg.put("RESULT", ""0000"");
      }
    }else{
        msg.put("RESULT", ""0000"");
    }
    return msg;
}
Java
分享到
取消 提交回答
全部回答(2)
  • 小勿悔
    2019-07-17 18:52:32
    使用tmf框架,通过拓展点的方式来杜绝if else这种方式
    0 0
  • 蛮大人123
    2019-07-17 18:52:32

    不要用 PMSUtil 了,直接上 org.apache.commons.lang.StringUtils

     private Map versionCheck(Map mapParam) {
            Map msg = new HashMap();
            msg.put("RESULT", "0000");
    
            String isInternet = (String) mapParam.get("IS_INTERNET");
            if (StringUtils.isBlank(isInternet)) {
                return msg;
            }
    
            String isCheck = SystemGlobals.getProperty("IS_CHECK");
            if (!StringUtils.equals(isCheck, "1")) {
                return msg;
            }
    
            String globalVersions = SystemGlobals.getProperty("VERSION");
            String currentVersion = (String) mapParam.get("VERSION");
            if (!StringUtils.contains("," + globalVersions + ",", "," + currentVersion + ",")) {
                return msg;
            }
    
            String whiteList = SystemGlobals.getProperty("NO_CHECK_TAX_REGISTER_NO");
            String taxRegisterNo = (String) mapParam.get("");
            if (!StringUtils.contains("," + whiteList + ",", "," + taxRegisterNo + ",")) {
                msg.put("RESULT", "0001");
                msg.put("MSG", "FAILD");
                return msg;
            }
    
            return Collections.emptyMap();
        }
    0 0
添加回答
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

推荐文章
相似问题
推荐课程