请优化下面代码减少重复代码:---n-----temp-=-jsgetStringuutFileName;n--------if-StringUtilsisEmptytempn------------msg-=-uutFileName-is-empty;n------------LOGGERerrormsg;n------------this_printTestLogmsg;n------------return-false;n--------n--------temp-=-jsgetStrin
可以使用一个方法来处理重复代码:
private boolean checkStringEmpty(JSONObject js, String key, String errorMsg) {
String temp = js.getString(key);
if (StringUtils.isEmpty(temp)){
LOGGER.error(errorMsg);
this._printTestLog(errorMsg);
return false;
}
return true;
}
然后在原来的代码中调用这个方法:
if(!checkStringEmpty(js, "uutFileName", "uutFileName is empty")){
return false;
}
if(!checkStringEmpty(js, "NodeName", "NodeName is empty")){
return false;
}
if(!checkStringEmpty(js, "HardPlatUsed", "HardPlatUsed is empty")){
return false;
}
原文地址: https://www.cveoy.top/t/topic/p18 著作权归作者所有。请勿转载和采集!