mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-23 10:35:18 +01:00
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:
parent
7eff3c86ec
commit
88e28689f7
@ -34,6 +34,9 @@ public interface ConfigEntry {
|
||||
|
||||
void setDefaultValue(@Nullable Object defaultValue);
|
||||
|
||||
@Contract("_ -> this")
|
||||
ConfigEntry withDefaultValue(@Nullable Object defaultValue);
|
||||
|
||||
/**
|
||||
* @see #withComment(Supplier)
|
||||
*/
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user