为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕森卡 2019-04-09 20:25:14
求助:一堆的ifelse嵌套privateMapversionCheck(MapmapParam){Mapmsg=newHashMap();if(!"".equals(PMSUtil.isNull(mapParam.get("IS_INTERNET")))){StringcheckVersion=SystemGlobals.getProperty("IS_CHECK");if("1".equals(checkVersion)){Stringversions=SystemGlobals.getProperty("VERSION");Stringversion=PMSUtil.isNull(mapParam.get("VERSION"));StringtaxRegisterNo=PMSUtil.isNull(mapParam.get(""));StringwhiteList=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"");}returnmsg;}
查看完整描述

2 回答

?
BIG阳

TA贡献1859条经验 获得超6个赞

1.整体可简化为:
if(){
if(){
if(){
if(){
msg.put("RESULT","0001");
msg.put("MSG","FAILD");
returnmsg;
}
}
}
}
msg.put("RESULT","0000");
returnmsg;
2.str.indexOf(s)==-1可简化为!str.contains(s)
3.使用2之后,最里层的两个if语句:
if(c1){
if(c2){
...
}
}
可以写成:
if(c1&&c2){
...
}
                            
查看完整回答
反对 回复 2019-04-09
  • 2 回答
  • 0 关注
  • 1052 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信