3434import org .elasticsearch .common .unit .ByteSizeUnit ;
3535import org .elasticsearch .common .unit .ByteSizeValue ;
3636import org .elasticsearch .common .unit .MemorySizeValue ;
37- import org .elasticsearch .common .unit .RatioValue ;
38- import org .elasticsearch .common .unit .SizeValue ;
3937import org .elasticsearch .common .unit .TimeValue ;
4038import org .elasticsearch .common .xcontent .DeprecationHandler ;
4139import org .elasticsearch .common .xcontent .LoggingDeprecationHandler ;
6462import java .util .List ;
6563import java .util .Map ;
6664import java .util .NoSuchElementException ;
65+ import java .util .Objects ;
6766import java .util .Set ;
6867import java .util .TreeMap ;
6968import java .util .ListIterator ;
7574import java .util .stream .Stream ;
7675
7776import static org .elasticsearch .common .unit .ByteSizeValue .parseBytesSizeValue ;
78- import static org .elasticsearch .common .unit .SizeValue .parseSizeValue ;
7977import static org .elasticsearch .common .unit .TimeValue .parseTimeValue ;
8078
8179/**
@@ -100,7 +98,7 @@ public final class Settings implements ToXContentFragment {
10098 */
10199 private final SetOnce <Set <String >> keys = new SetOnce <>();
102100
103- Settings (Map <String , Object > settings , SecureSettings secureSettings ) {
101+ private Settings (Map <String , Object > settings , SecureSettings secureSettings ) {
104102 // we use a sorted map for consistent serialization when using getAsMap()
105103 this .settings = Collections .unmodifiableSortedMap (new TreeMap <>(settings ));
106104 this .secureSettings = secureSettings ;
@@ -245,30 +243,6 @@ public String get(String setting, String defaultValue) {
245243 return retVal == null ? defaultValue : retVal ;
246244 }
247245
248- /**
249- * Returns the setting value associated with the setting key. If it does not exists,
250- * returns the default value provided.
251- */
252- String get (String setting , String defaultValue , boolean isList ) {
253- Object value = settings .get (setting );
254- if (value != null ) {
255- if (value instanceof List ) {
256- if (isList == false ) {
257- throw new IllegalArgumentException (
258- "Found list type value for setting [" + setting + "] but but did not expect a list for it."
259- );
260- }
261- } else if (isList ) {
262- throw new IllegalArgumentException (
263- "Expected list type value for setting [" + setting + "] but found [" + value .getClass () + ']'
264- );
265- }
266- return toString (value );
267- } else {
268- return defaultValue ;
269- }
270- }
271-
272246 /**
273247 * Returns the setting value (as float) associated with the setting key. If it does not exists,
274248 * returns the default value provided.
@@ -412,23 +386,6 @@ public ByteSizeValue getAsMemory(String setting, String defaultValue) throws Set
412386 return MemorySizeValue .parseBytesSizeValueOrHeapRatio (get (setting , defaultValue ), setting );
413387 }
414388
415- /**
416- * Returns the setting value (as a RatioValue) associated with the setting key. Provided values can
417- * either be a percentage value (eg. 23%), or expressed as a floating point number (eg. 0.23). If
418- * it does not exist, parses the default value provided.
419- */
420- public RatioValue getAsRatio (String setting , String defaultValue ) throws SettingsException {
421- return RatioValue .parseRatioValue (get (setting , defaultValue ));
422- }
423-
424- /**
425- * Returns the setting value (as size) associated with the setting key. If it does not exists,
426- * returns the default value provided.
427- */
428- public SizeValue getAsSize (String setting , SizeValue defaultValue ) throws SettingsException {
429- return parseSizeValue (get (setting ), defaultValue );
430- }
431-
432389 /**
433390 * The values associated with a setting key as an immutable list.
434391 * <p>
@@ -533,11 +490,7 @@ private Map<String, Settings> getGroupsInternal(String settingPrefix, boolean ig
533490 * Returns group settings for the given setting prefix.
534491 */
535492 public Map <String , Settings > getAsGroups () throws SettingsException {
536- return getAsGroups (false );
537- }
538-
539- public Map <String , Settings > getAsGroups (boolean ignoreNonGrouped ) throws SettingsException {
540- return getGroupsInternal ("" , ignoreNonGrouped );
493+ return getGroupsInternal ("" , false );
541494 }
542495
543496 /**
@@ -596,14 +549,12 @@ public boolean equals(Object o) {
596549 if (o == null || getClass () != o .getClass ()) return false ;
597550
598551 Settings that = (Settings ) o ;
599- if (settings != null ? !settings .equals (that .settings ) : that .settings != null ) return false ;
600- return true ;
552+ return Objects .equals (settings , that .settings );
601553 }
602554
603555 @ Override
604556 public int hashCode () {
605- int result = settings != null ? settings .hashCode () : 0 ;
606- return result ;
557+ return settings != null ? settings .hashCode () : 0 ;
607558 }
608559
609560 public static Settings readSettingsFromStream (StreamInput in ) throws IOException {
@@ -833,7 +784,7 @@ public static class Builder {
833784 // we use a sorted map for consistent serialization when using getAsMap()
834785 private final Map <String , Object > map = new TreeMap <>();
835786
836- private SetOnce <SecureSettings > secureSettings = new SetOnce <>();
787+ private final SetOnce <SecureSettings > secureSettings = new SetOnce <>();
837788
838789 private Builder () {
839790
@@ -977,18 +928,6 @@ public Builder putNull(String key) {
977928 return put (key , (String ) null );
978929 }
979930
980- /**
981- * Sets a setting with the provided setting key and class as value.
982- *
983- * @param key The setting key
984- * @param clazz The setting class value
985- * @return The builder
986- */
987- public Builder put (String key , Class clazz ) {
988- map .put (key , clazz .getName ());
989- return this ;
990- }
991-
992931 /**
993932 * Sets the setting with the provided setting key and the boolean value.
994933 *
@@ -1103,22 +1042,6 @@ public Builder putList(String setting, List<String> values) {
11031042 return this ;
11041043 }
11051044
1106- /**
1107- * Sets the setting group.
1108- */
1109- public Builder put (String settingPrefix , String groupName , String [] settings , String [] values ) throws SettingsException {
1110- if (settings .length != values .length ) {
1111- throw new SettingsException ("The settings length must match the value length" );
1112- }
1113- for (int i = 0 ; i < settings .length ; i ++) {
1114- if (values [i ] == null ) {
1115- continue ;
1116- }
1117- put (settingPrefix + "." + groupName + "." + settings [i ], values [i ]);
1118- }
1119- return this ;
1120- }
1121-
11221045 /**
11231046 * Sets all the provided settings including secure settings
11241047 */
@@ -1252,18 +1175,12 @@ public String resolvePlaceholder(String placeholderName) {
12521175
12531176 @ Override
12541177 public boolean shouldIgnoreMissing (String placeholderName ) {
1255- if (placeholderName .startsWith ("prompt." )) {
1256- return true ;
1257- }
1258- return false ;
1178+ return placeholderName .startsWith ("prompt." );
12591179 }
12601180
12611181 @ Override
12621182 public boolean shouldRemoveMissingPlaceholder (String placeholderName ) {
1263- if (placeholderName .startsWith ("prompt." )) {
1264- return false ;
1265- }
1266- return true ;
1183+ return !placeholderName .startsWith ("prompt." );
12671184 }
12681185 };
12691186
@@ -1437,7 +1354,7 @@ public boolean containsKey(Object key) {
14371354 @ Override
14381355 public int size () {
14391356 if (size == -1 ) {
1440- size = Math .toIntExact (delegate .keySet ().stream ().filter (( e ) -> filter . test ( e ) ).count ());
1357+ size = Math .toIntExact (delegate .keySet ().stream ().filter (filter ).count ());
14411358 }
14421359 return size ;
14431360 }
0 commit comments