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

求助:一堆的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;
}
慕森卡
浏览 1053回答 2
2回答

BIG阳

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){...}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript