這個代碼(mangled)被PMD標記爲太深嵌套。我個人總是用我編寫的任何語言編寫代碼 - 尤其是大型數據庫驅動的for-loops。深嵌套如果...然後
這種編碼風格真的令人f目結舌嗎?我發現它是最可維護和最乾淨的。
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);
}
}
}
}
}
}
可能更適合http://codereview.stackexchange.com/。 –
有無數書籍和文章在線描述爲什麼這不是一個很好的寫代碼的方式。我很好奇......你爲什麼認爲它是「最可維護和最乾淨的」? –