mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
Finalize coherent feature
This commit is contained in:
@@ -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"));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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("-", ""));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user