此代码(损坏的)被 PMD 标记为嵌套太深。我个人总是用我编写过的任何语言以这种方式编写代码——尤其是大型数据库驱动的 for 循环。
这种编码风格真的不受欢迎吗?我发现它是最可维护和最干净的。
for (MyList MyRegistry : listJSP) {
if (meta.containsKey(MyRegistry.getFieldName()) && MyRegistry.getOrderType().equals(orderType)) {
String CustomerInput = meta.get(MyRegistry.getFieldName())[0];
String jspFieldName = MyRegistry.getFieldName();
if (MyRegistry.getErrorsCheck()) {
mapErrors = valUtil.adTextContainsErrors(CustomerInput, cms.getRegex("VALIDATION"));
if (mapErrors.containsKey(Boolean.TRUE)) {
mapValidationErrors.put(jspFieldName, mapErrors.get(Boolean.parseBoolean("true")));
log.info("Errors " + "{}: ", CustomerInput);
}
}
List<JSPFieldValidation> jSPFieldValidation = cms.getJSPFieldValidations(orderType, MyRegistry.getFieldName());
for (JSPFieldValidation jspf : jSPFieldValidation) {
String valRule = jspf.getValidationRule();
if (valRule.equals("REQUIRED")) {
if (isEmpty(CustomerInput)) {
mapValidationErrors.put(orderType, orderType);
log.info(CustomerInput + "{}: ", valRule);
}
}
else {
Pattern p = cms.getRegex(valRule);
if (p != null) {
if (!isValid(CustomerInput, p)) {
mapValidationErrors.put(orderType, orderType);
log.info(CustomerInput + "{}", valRule);
}
}
}
}
}
}