Adds ConfigEntry#withDefaultValue for easier chaining

This allows to chain the default value instead of using the setter or constructor.
Long keys/values can be put into individual lines which improves readability.

In the future, we might want to have a Builder class that contains all thise #with methods
This commit is contained in:
Christian Koop 2022-12-30 15:20:36 +01:00
parent 7eff3c86ec
commit 88e28689f7
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
3 changed files with 15 additions and 0 deletions

View File

@ -34,6 +34,9 @@ public interface ConfigEntry {
void setDefaultValue(@Nullable Object defaultValue);
@Contract("_ -> this")
ConfigEntry withDefaultValue(@Nullable Object defaultValue);
/**
* @see #withComment(Supplier)
*/

View File

@ -40,6 +40,12 @@ public class ReadOnlyConfigEntry implements ConfigEntry {
throw new UnsupportedOperationException("Cannot set defaultValue on a read-only config entry");
}
@Override
@Contract("_ -> fail")
public ConfigEntry withDefaultValue(@Nullable Object defaultValue) {
throw new UnsupportedOperationException("Cannot set defaultValue on a read-only config entry");
}
@Override
@Contract("_ -> fail")
public ConfigEntry withComment(Supplier<String> comment) {

View File

@ -50,6 +50,12 @@ public class YamlConfigEntry implements WriteableConfigEntry {
this.defaultValue = defaultValue;
}
@Override
public ConfigEntry withDefaultValue(@Nullable Object defaultValue) {
this.setDefaultValue(defaultValue);
return this;
}
@Override
public ConfigEntry withUpgradeStep(int version, @Nullable String keyInGivenVersion, @Nullable Function<@Nullable Object, @Nullable Object> valueConverter) {
if (keyInGivenVersion == null && valueConverter == null) {