2 回答

TA貢獻1830條經驗 獲得超3個贊
替換您的 2 種方法validarObligatorios并validarNumericas通過以下單個功能回答您的問題嗎?
private void validarObligatoriosYNumericos(final JobParameters parameters) throws JobParametersInvalidException {
for (String nombre : PARAMETROS_OBLIGATORIOS) {
if (StringUtils.isBlank(parameters.getString(nombre))) {
String error ="El parametro " + nombre + " es obligatorio";
LOGGER.error(error);
throw new JobParametersInvalidException(error);
}
}
for (String nombre : PARAMETROS_NUMERICOS) {
if (!StringUtils.isNumeric(parameters.getString(nombre))) {
String error = "El parametro " + nombre + " debe ser numerico";
LOGGER.error(error);
throw new JobParametersInvalidException(error);
}
}
}
!

TA貢獻1831條經驗 獲得超4個贊
將數值列數組復制到列表中并用于contains查看是否應檢查值。此解決方案假定數字列數組是強制列數組的子集,但看起來這是一個安全的假設。
private void validarObligatorios(final JobParameters parameters) throws JobParametersInvalidException {
List<String> numericColumns = Arrays.asList(PARAMETROS_NUMERICOS );
String error = null;
for (String nombre : PARAMETROS_OBLIGATORIOS) {
if (StringUtils.isBlank(parameters.getString(nombre))) {
error ="El parametro " + nombre + " es obligatorio";
} else if (numericColumns.contains(nombre) {
if (!StringUtils.isNumeric(parameters.getString(nombre))) {
error = "El parametro " + nombre + " debe ser numerico";
}
}
if (error != null) {
LOGGER.error(error);
throw new JobParametersInvalidException(error);
}
}
}
添加回答
舉報