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.
@@ -382,23 +356,6 @@ public ByteSizeValue getAsMemory(String setting, String defaultValue) throws Set
382356 return MemorySizeValue .parseBytesSizeValueOrHeapRatio (get (setting , defaultValue ), setting );
383357 }
384358
385- /**
386- * Returns the setting value (as a RatioValue) associated with the setting key. Provided values can
387- * either be a percentage value (eg. 23%), or expressed as a floating point number (eg. 0.23). If
388- * it does not exist, parses the default value provided.
389- */
390- public RatioValue getAsRatio (String setting , String defaultValue ) throws SettingsException {
391- return RatioValue .parseRatioValue (get (setting , defaultValue ));
392- }
393-
394- /**
395- * Returns the setting value (as size) associated with the setting key. If it does not exists,
396- * returns the default value provided.
397- */
398- public SizeValue getAsSize (String setting , SizeValue defaultValue ) throws SettingsException {
399- return parseSizeValue (get (setting ), defaultValue );
400- }
401-
402359 /**
403360 * The values associated with a setting key as an immutable list.
404361 * <p>
@@ -503,11 +460,7 @@ private Map<String, Settings> getGroupsInternal(String settingPrefix, boolean ig
503460 * Returns group settings for the given setting prefix.
504461 */
505462 public Map <String , Settings > getAsGroups () throws SettingsException {
506- return getAsGroups (false );
507- }
508-
509- public Map <String , Settings > getAsGroups (boolean ignoreNonGrouped ) throws SettingsException {
510- return getGroupsInternal ("" , ignoreNonGrouped );
463+ return getGroupsInternal ("" , false );
511464 }
512465
513466 /**
@@ -566,14 +519,12 @@ public boolean equals(Object o) {
566519 if (o == null || getClass () != o .getClass ()) return false ;
567520
568521 Settings that = (Settings ) o ;
569- if (settings != null ? !settings .equals (that .settings ) : that .settings != null ) return false ;
570- return true ;
522+ return Objects .equals (settings , that .settings );
571523 }
572524
573525 @ Override
574526 public int hashCode () {
575- int result = settings != null ? settings .hashCode () : 0 ;
576- return result ;
527+ return settings != null ? settings .hashCode () : 0 ;
577528 }
578529
579530 public static Settings readSettingsFromStream (StreamInput in ) throws IOException {
@@ -791,7 +742,7 @@ public static class Builder {
791742 // we use a sorted map for consistent serialization when using getAsMap()
792743 private final Map <String , Object > map = new TreeMap <>();
793744
794- private SetOnce <SecureSettings > secureSettings = new SetOnce <>();
745+ private final SetOnce <SecureSettings > secureSettings = new SetOnce <>();
795746
796747 private Builder () {
797748
@@ -935,18 +886,6 @@ public Builder putNull(String key) {
935886 return put (key , (String ) null );
936887 }
937888
938- /**
939- * Sets a setting with the provided setting key and class as value.
940- *
941- * @param key The setting key
942- * @param clazz The setting class value
943- * @return The builder
944- */
945- public Builder put (String key , Class clazz ) {
946- map .put (key , clazz .getName ());
947- return this ;
948- }
949-
950889 /**
951890 * Sets the setting with the provided setting key and the boolean value.
952891 *
@@ -1061,22 +1000,6 @@ public Builder putList(String setting, List<String> values) {
10611000 return this ;
10621001 }
10631002
1064- /**
1065- * Sets the setting group.
1066- */
1067- public Builder put (String settingPrefix , String groupName , String [] settings , String [] values ) throws SettingsException {
1068- if (settings .length != values .length ) {
1069- throw new SettingsException ("The settings length must match the value length" );
1070- }
1071- for (int i = 0 ; i < settings .length ; i ++) {
1072- if (values [i ] == null ) {
1073- continue ;
1074- }
1075- put (settingPrefix + "." + groupName + "." + settings [i ], values [i ]);
1076- }
1077- return this ;
1078- }
1079-
10801003 /**
10811004 * Sets all the provided settings including secure settings
10821005 */
@@ -1210,18 +1133,12 @@ public String resolvePlaceholder(String placeholderName) {
12101133
12111134 @ Override
12121135 public boolean shouldIgnoreMissing (String placeholderName ) {
1213- if (placeholderName .startsWith ("prompt." )) {
1214- return true ;
1215- }
1216- return false ;
1136+ return placeholderName .startsWith ("prompt." );
12171137 }
12181138
12191139 @ Override
12201140 public boolean shouldRemoveMissingPlaceholder (String placeholderName ) {
1221- if (placeholderName .startsWith ("prompt." )) {
1222- return false ;
1223- }
1224- return true ;
1141+ return !placeholderName .startsWith ("prompt." );
12251142 }
12261143 };
12271144
@@ -1395,7 +1312,7 @@ public boolean containsKey(Object key) {
13951312 @ Override
13961313 public int size () {
13971314 if (size == -1 ) {
1398- size = Math .toIntExact (delegate .keySet ().stream ().filter (( e ) -> filter . test ( e ) ).count ());
1315+ size = Math .toIntExact (delegate .keySet ().stream ().filter (filter ).count ());
13991316 }
14001317 return size ;
14011318 }
0 commit comments