@@ -507,35 +507,21 @@ public Map<String, Settings> getGroups(String settingPrefix, boolean ignoreNonGr
507507 }
508508
509509 private Map <String , Settings > getGroupsInternal (String settingPrefix , boolean ignoreNonGrouped ) throws SettingsException {
510- // we don't really care that it might happen twice
511- Map <String , Map <String , String >> map = new LinkedHashMap <>();
512- for (Object o : settings .keySet ()) {
513- String setting = (String ) o ;
514- if (setting .startsWith (settingPrefix )) {
515- String nameValue = setting .substring (settingPrefix .length ());
516- int dotIndex = nameValue .indexOf ('.' );
517- if (dotIndex == -1 ) {
518- if (ignoreNonGrouped ) {
519- continue ;
520- }
521- throw new SettingsException ("Failed to get setting group for [" + settingPrefix + "] setting prefix and setting ["
522- + setting + "] because of a missing '.'" );
523- }
524- String name = nameValue .substring (0 , dotIndex );
525- String value = nameValue .substring (dotIndex + 1 );
526- Map <String , String > groupSettings = map .get (name );
527- if (groupSettings == null ) {
528- groupSettings = new LinkedHashMap <>();
529- map .put (name , groupSettings );
510+ Settings prefixSettings = getByPrefix (settingPrefix );
511+ Map <String , Settings > groups = new HashMap <>();
512+ for (String groupName : prefixSettings .names ()) {
513+ Settings groupSettings = prefixSettings .getByPrefix (groupName + "." );
514+ if (groupSettings .isEmpty ()) {
515+ if (ignoreNonGrouped ) {
516+ continue ;
530517 }
531- groupSettings .put (value , get (setting ));
518+ throw new SettingsException ("Failed to get setting group for [" + settingPrefix + "] setting prefix and setting ["
519+ + settingPrefix + groupName + "] because of a missing '.'" );
532520 }
521+ groups .put (groupName , groupSettings );
533522 }
534- Map <String , Settings > retVal = new LinkedHashMap <>();
535- for (Map .Entry <String , Map <String , String >> entry : map .entrySet ()) {
536- retVal .put (entry .getKey (), new Settings (Collections .unmodifiableMap (entry .getValue ()), secureSettings ));
537- }
538- return Collections .unmodifiableMap (retVal );
523+
524+ return Collections .unmodifiableMap (groups );
539525 }
540526 /**
541527 * Returns group settings for the given setting prefix.
0 commit comments