我的问题是-
我有两个字符串变量site_inclusion和site_exclusion. 如果site_inclusion有一个值,那么我不在乎值site_exclusion包含什么。也就是说,site_inclusion覆盖site_exclusion. 但是,如果 site_inclusionisnull并且site_exclusion具有值,那么我想检查site_exclusion.
更准确地说:
- 如果
site_inclusion和site_exclusion都null设置useTheSynthesizer为true; - 如果
site_inclusion不是null,它与设置为的regexPatternthen匹配。而且我不在乎.useTheSynthesizertruesite_exclusion - if
site_inclusionisnullandsite_exclusionis notnull和site_exclusion不匹配regexPatternthen 设置useTheSynthesizer为 true。
我写了下面的代码,但不知何故,我在 if/else 循环中重复了一些东西。任何满足我条件的代码改进都将不胜感激。
String site_inclusion = metadata.getSiteInclusion();
String site_exclusion = metadata.getSiteExclusion();
// fix for redundant data per site issue
if(site_inclusion != null && site_inclusion.matches(regexPattern)) {
useTheSynthesizer = true;
} else if(site_exclusion != null && !(site_exclusion.matches(regexPattern))) {
useTheSynthesizer = true;
} else if(site_inclusion == null && site_exclusion == null ) {
useTheSynthesizer = true;
}