Finalize coherent feature

This commit is contained in:
2023-03-07 22:55:03 +01:00
parent 8317e97639
commit 6372cc560c
8 changed files with 50 additions and 48 deletions

View File

@@ -37,6 +37,7 @@ public class Config {
private boolean safeMode;
private Integer coherent;
private boolean forceCoherent;
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs", "songs"));
private Set<String> commentaryKeywords = new HashSet<>(Arrays.asList("commentary", "director"));

View File

@@ -29,7 +29,8 @@ public class ConfigLoader {
new SetValidator(COMMENTARY_KEYWORDS, false, true),
new SetValidator(EXCLUDED_DIRECTORY, false, true),
new AttributeConfigValidator(),
new CoherentConfigValidator(COHERENT, false)
new CoherentConfigValidator(COHERENT, false),
new BooleanValidator(FORCE_COHERENT, false)
);
public static void initConfig(String[] args) {

View File

@@ -121,27 +121,27 @@ public abstract class ConfigValidator<FieldType> {
* @return false if method invocation failed
*/
protected boolean setValue(FieldType result) {
List<Method> methods = Arrays.stream(Config.getInstance().getClass().getDeclaredMethods())
.filter(containsSetterOf(property))
.collect(Collectors.toList());
if (methods.size() != 1) {
return false;
}
try {
methods.get(0).invoke(Config.getInstance(), result);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
return true;
for (Method method: Config.getInstance().getClass().getDeclaredMethods()) {
if(containsSetterOf(property).test(method)) {
try {
method.invoke(Config.getInstance(), result);
return true;
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}
return false;
}
protected Predicate<Method> containsSetterOf(ConfigProperty property) {
return method -> StringUtils.containsIgnoreCase(method.getName(), "set")
&& StringUtils.containsIgnoreCase(method.getName(), property.prop().replace("-", ""));
return method -> StringUtils.startsWith(method.getName(), "set")
&& StringUtils.equalsIgnoreCase(method.getName().replace("set", ""), property.prop().replace("-", ""));
}
protected Predicate<Method> containsGetterOf(ConfigProperty property) {
return method -> StringUtils.containsIgnoreCase(method.getName(), "get")
return method -> StringUtils.startsWith(method.getName(), "get")
&& StringUtils.containsIgnoreCase(method.getName(), property.prop().replace("-", ""));
}