Skip to content

Commit

Permalink
Renamed setConfigValue to updateDynamicSetting for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
klaren committed Aug 16, 2017
1 parent a18079f commit 4c6af40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Expand Up @@ -565,21 +565,20 @@ public Optional<?> getValue( @Nonnull String key )
}

/**
* Updates a provided setting to a given value. This method is intended to be used for changing settings during
* runtime. If you want to change settings at startup, use {@link Config#augment}.
*
* TODO: DRAGONS! This code works for the current dynamic variables(3), but is not generic.
* TODO: DRAGONS! No migration or config validation is done.
* @implNote No migration or config validation is done. If you need this you have to refactor this method.
*
* @param setting The setting to set to the specified value.
* @param value The new value to set, passing {@code null} or empty should reset the value back to default value.
* @throws IllegalArgumentException if the provided setting is unknown or not dynamic.
* @throws InvalidSettingException if the value is not formatted correctly.
*/
public void setConfigValue( String setting, String value ) throws IllegalArgumentException, InvalidSettingException
public void updateDynamicSetting( String setting, String value ) throws IllegalArgumentException, InvalidSettingException
{
// Make sure the setting is valid and is marked as dynamic
Optional<ConfigValue> option =
configOptions.stream().map( it -> it.asConfigValues( params ) ).flatMap( List::stream )
.filter( it -> it.name().equals( setting ) ).findFirst();
Optional<ConfigValue> option = findConfigValue( setting );

if ( !option.isPresent() )
{
Expand Down Expand Up @@ -617,6 +616,12 @@ public void setConfigValue( String setting, String value ) throws IllegalArgumen
}
}

private Optional<ConfigValue> findConfigValue( String setting )
{
return configOptions.stream().map( it -> it.asConfigValues( params ) ).flatMap( List::stream )
.filter( it -> it.name().equals( setting ) ).findFirst();
}

/**
* @return all effective config values
*/
Expand Down
Expand Up @@ -280,7 +280,7 @@ public void setConfigValue( @Name( "setting" ) String setting, @Name( "value" )
assertAdmin();

Config config = resolver.resolveDependency( Config.class );
config.setConfigValue( setting, value ); // throws if something goes wrong
config.updateDynamicSetting( setting, value ); // throws if something goes wrong
}

/*
Expand Down

0 comments on commit 4c6af40

Please sign in to comment.