forked from hugegraph/hugegraph-sync
HugeGraph-1000: allow non-check of config options
Change-Id: Ida0a2d88818f0ca53e9ddf886cff88e7ceb52ed8
This commit is contained in:
parent
fe8b51d072
commit
9f994b33de
4
pom.xml
4
pom.xml
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>com.baidu.hugegraph</groupId>
|
||||
<artifactId>hugegraph-common</artifactId>
|
||||
<version>1.3.10-SNAPSHOT</version>
|
||||
<version>1.3.11-SNAPSHOT</version>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
|
|
@ -156,7 +156,7 @@
|
|||
</manifest>
|
||||
<manifestEntries>
|
||||
<Implementation-Version>
|
||||
1.3.9.0
|
||||
1.3.11.0
|
||||
</Implementation-Version>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
|
|
|
|||
|
|
@ -63,6 +63,10 @@ public class ConfigOption<T> {
|
|||
private final T defaultValue;
|
||||
private final Predicate<T> checkFunc;
|
||||
|
||||
public ConfigOption(String name, String desc, T value) {
|
||||
this(name, desc, null, value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConfigOption(String name, String desc, Predicate<T> func, T value) {
|
||||
this(name, false, desc, func, (Class<T>) value.getClass(), value);
|
||||
|
|
@ -81,9 +85,7 @@ public class ConfigOption<T> {
|
|||
this.desc = desc;
|
||||
this.checkFunc = func;
|
||||
|
||||
if (this.checkFunc != null) {
|
||||
check(this.defaultValue);
|
||||
}
|
||||
this.check(this.defaultValue);
|
||||
}
|
||||
|
||||
private Class<?> checkAndAssignDataType(Class<T> dataType) {
|
||||
|
|
@ -150,10 +152,12 @@ public class ConfigOption<T> {
|
|||
E.checkArgument(this.dataType.isInstance(value),
|
||||
"Invalid type of value '%s' for option '%s'",
|
||||
value, this.name);
|
||||
@SuppressWarnings("unchecked")
|
||||
T result = (T) value;
|
||||
E.checkArgument(this.checkFunc.apply(result),
|
||||
"Invalid option value for '%s': %s",
|
||||
this.name, value);
|
||||
if (this.checkFunc != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T result = (T) value;
|
||||
E.checkArgument(this.checkFunc.apply(result),
|
||||
"Invalid option value for '%s': %s",
|
||||
this.name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue