diff --git a/server/src/main/java/org/elasticsearch/common/settings/Settings.java b/server/src/main/java/org/elasticsearch/common/settings/Settings.java index ac43a1800b4..107c7bb9b8a 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -34,8 +34,6 @@ import org.elasticsearch.common.logging.LogConfigurator; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.MemorySizeValue; -import org.elasticsearch.common.unit.RatioValue; -import org.elasticsearch.common.unit.SizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; @@ -64,6 +62,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.Set; import java.util.TreeMap; import java.util.ListIterator; @@ -75,7 +74,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import static org.elasticsearch.common.unit.ByteSizeValue.parseBytesSizeValue; -import static org.elasticsearch.common.unit.SizeValue.parseSizeValue; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; /** @@ -100,7 +98,7 @@ public final class Settings implements ToXContentFragment { */ private final SetOnce> keys = new SetOnce<>(); - Settings(Map settings, SecureSettings secureSettings) { + private Settings(Map settings, SecureSettings secureSettings) { // we use a sorted map for consistent serialization when using getAsMap() this.settings = Collections.unmodifiableSortedMap(new TreeMap<>(settings)); this.secureSettings = secureSettings; @@ -245,30 +243,6 @@ public final class Settings implements ToXContentFragment { return retVal == null ? defaultValue : retVal; } - /** - * Returns the setting value associated with the setting key. If it does not exists, - * returns the default value provided. - */ - String get(String setting, String defaultValue, boolean isList) { - Object value = settings.get(setting); - if (value != null) { - if (value instanceof List) { - if (isList == false) { - throw new IllegalArgumentException( - "Found list type value for setting [" + setting + "] but but did not expect a list for it." - ); - } - } else if (isList) { - throw new IllegalArgumentException( - "Expected list type value for setting [" + setting + "] but found [" + value.getClass() + ']' - ); - } - return toString(value); - } else { - return defaultValue; - } - } - /** * Returns the setting value (as float) associated with the setting key. If it does not exists, * returns the default value provided. @@ -382,23 +356,6 @@ public final class Settings implements ToXContentFragment { return MemorySizeValue.parseBytesSizeValueOrHeapRatio(get(setting, defaultValue), setting); } - /** - * Returns the setting value (as a RatioValue) associated with the setting key. Provided values can - * either be a percentage value (eg. 23%), or expressed as a floating point number (eg. 0.23). If - * it does not exist, parses the default value provided. - */ - public RatioValue getAsRatio(String setting, String defaultValue) throws SettingsException { - return RatioValue.parseRatioValue(get(setting, defaultValue)); - } - - /** - * Returns the setting value (as size) associated with the setting key. If it does not exists, - * returns the default value provided. - */ - public SizeValue getAsSize(String setting, SizeValue defaultValue) throws SettingsException { - return parseSizeValue(get(setting), defaultValue); - } - /** * The values associated with a setting key as an immutable list. *

@@ -503,11 +460,7 @@ public final class Settings implements ToXContentFragment { * Returns group settings for the given setting prefix. */ public Map getAsGroups() throws SettingsException { - return getAsGroups(false); - } - - public Map getAsGroups(boolean ignoreNonGrouped) throws SettingsException { - return getGroupsInternal("", ignoreNonGrouped); + return getGroupsInternal("", false); } /** @@ -566,14 +519,12 @@ public final class Settings implements ToXContentFragment { if (o == null || getClass() != o.getClass()) return false; Settings that = (Settings) o; - if (settings != null ? !settings.equals(that.settings) : that.settings != null) return false; - return true; + return Objects.equals(settings, that.settings); } @Override public int hashCode() { - int result = settings != null ? settings.hashCode() : 0; - return result; + return settings != null ? settings.hashCode() : 0; } public static Settings readSettingsFromStream(StreamInput in) throws IOException { @@ -791,7 +742,7 @@ public final class Settings implements ToXContentFragment { // we use a sorted map for consistent serialization when using getAsMap() private final Map map = new TreeMap<>(); - private SetOnce secureSettings = new SetOnce<>(); + private final SetOnce secureSettings = new SetOnce<>(); private Builder() { @@ -935,18 +886,6 @@ public final class Settings implements ToXContentFragment { return put(key, (String) null); } - /** - * Sets a setting with the provided setting key and class as value. - * - * @param key The setting key - * @param clazz The setting class value - * @return The builder - */ - public Builder put(String key, Class clazz) { - map.put(key, clazz.getName()); - return this; - } - /** * Sets the setting with the provided setting key and the boolean value. * @@ -1061,22 +1000,6 @@ public final class Settings implements ToXContentFragment { return this; } - /** - * Sets the setting group. - */ - public Builder put(String settingPrefix, String groupName, String[] settings, String[] values) throws SettingsException { - if (settings.length != values.length) { - throw new SettingsException("The settings length must match the value length"); - } - for (int i = 0; i < settings.length; i++) { - if (values[i] == null) { - continue; - } - put(settingPrefix + "." + groupName + "." + settings[i], values[i]); - } - return this; - } - /** * Sets all the provided settings including secure settings */ @@ -1210,18 +1133,12 @@ public final class Settings implements ToXContentFragment { @Override public boolean shouldIgnoreMissing(String placeholderName) { - if (placeholderName.startsWith("prompt.")) { - return true; - } - return false; + return placeholderName.startsWith("prompt."); } @Override public boolean shouldRemoveMissingPlaceholder(String placeholderName) { - if (placeholderName.startsWith("prompt.")) { - return false; - } - return true; + return !placeholderName.startsWith("prompt."); } }; @@ -1395,7 +1312,7 @@ public final class Settings implements ToXContentFragment { @Override public int size() { if (size == -1) { - size = Math.toIntExact(delegate.keySet().stream().filter((e) -> filter.test(e)).count()); + size = Math.toIntExact(delegate.keySet().stream().filter(filter).count()); } return size; }