我有一个在条件字符串中的方法,如果逻辑运算符前后没有空格,则会引发错误。我有一个问题,例如它找到像“更多”这样的词,或者它找到“或”它给出错误。这是一个示例,下面是我的代码。
健康)状况: (da_cargue_hechos_mora_abonados) and s(da_cliente_diario_scl) and s(da_e_abonado_diario_pos) and s(da_e_abonado_diario_pre) and s(da_dim_situacion_scl) and s(da_dim_oficina_scl)
Code:
private static Job checkSpacesInCondition(Job job) {
String condition = null;
condition = job.getCondition();
// If null, no check needed
if (condition != null) {
condition = condition.toLowerCase();
condition = condition.replaceAll("&&", "and");
condition = condition.replaceAll("&", "and");
for (String word : CONDITION_OPERATORS) {
Pattern logicalPattern = Pattern.compile("\\S" + word + "|"
+ word + "\\S");
Matcher logicalMatcher = logicalPattern.matcher(condition);
boolean foundNoSpace = logicalMatcher.find();
if (foundNoSpace) {
job.addWarning(JobWarning.SPACES_AFTER_LOGICAL_OPERATOR);
}
}
}
return job;
}