1515import java .util .List ;
1616import java .util .Map ;
1717import java .util .StringJoiner ;
18+ import java .util .function .BiFunction ;
1819import javax .annotation .Nullable ;
1920
2021/**
@@ -110,6 +111,9 @@ private static boolean isMap(Object object) {
110111 @ Override
111112 public String getString (String name ) {
112113 Object value = simpleEntries .get (name );
114+ if (value == null && hasDotNotation (name )) {
115+ return applyToChild (name , ExtendedConfigProperties ::getString );
116+ }
113117 if (value instanceof String ) {
114118 return (String ) value ;
115119 }
@@ -120,6 +124,9 @@ public String getString(String name) {
120124 @ Override
121125 public Boolean getBoolean (String name ) {
122126 Object value = simpleEntries .get (name );
127+ if (value == null && hasDotNotation (name )) {
128+ return applyToChild (name , ExtendedConfigProperties ::getBoolean );
129+ }
123130 if (value instanceof Boolean ) {
124131 return (Boolean ) value ;
125132 }
@@ -130,6 +137,9 @@ public Boolean getBoolean(String name) {
130137 @ Override
131138 public Integer getInt (String name ) {
132139 Object value = simpleEntries .get (name );
140+ if (value == null && hasDotNotation (name )) {
141+ return applyToChild (name , ExtendedConfigProperties ::getInt );
142+ }
133143 if (value instanceof Integer ) {
134144 return (Integer ) value ;
135145 }
@@ -140,6 +150,9 @@ public Integer getInt(String name) {
140150 @ Override
141151 public Long getLong (String name ) {
142152 Object value = simpleEntries .get (name );
153+ if (value == null && hasDotNotation (name )) {
154+ return applyToChild (name , ExtendedConfigProperties ::getLong );
155+ }
143156 if (value instanceof Integer ) {
144157 return ((Integer ) value ).longValue ();
145158 }
@@ -153,6 +166,9 @@ public Long getLong(String name) {
153166 @ Override
154167 public Double getDouble (String name ) {
155168 Object value = simpleEntries .get (name );
169+ if (value == null && hasDotNotation (name )) {
170+ return applyToChild (name , ExtendedConfigProperties ::getDouble );
171+ }
156172 if (value instanceof Float ) {
157173 return ((Float ) value ).doubleValue ();
158174 }
@@ -170,9 +186,16 @@ public Duration getDuration(String name) {
170186 }
171187
172188 @ Override
173- @ SuppressWarnings ("unchecked" )
189+ @ SuppressWarnings ({ "unchecked" , "NullAway" } )
174190 public List <String > getList (String name ) {
175191 Object value = simpleEntries .get (name );
192+ if (value == null && hasDotNotation (name )) {
193+ List <String > result = applyToChild (name , ExtendedConfigProperties ::getList );
194+ if (result != null ) {
195+ return result ;
196+ }
197+ return Collections .emptyList ();
198+ }
176199 if (value instanceof List ) {
177200 return (List <String >) value ;
178201 }
@@ -184,14 +207,47 @@ public Map<String, String> getMap(String name) {
184207 throw new UnsupportedOperationException ("Use getConfigProperties(String) instead" );
185208 }
186209
210+ private static boolean hasDotNotation (String name ) {
211+ return name .contains ("." );
212+ }
213+
214+ /** Should only be called after {@link #hasDotNotation(String)} returns {@code true}. */
215+ @ Nullable
216+ private <T > T applyToChild (
217+ String name , BiFunction <ExtendedConfigProperties , String , T > function ) {
218+ String [] parts = name .split ("\\ ." , 2 );
219+ assert parts .length == 2 ;
220+ if (parts .length != 2 ) {
221+ throw new IllegalStateException ("Error!" );
222+ }
223+ ExtendedConfigProperties childProps = getConfigPropertiesInternal (parts [0 ]);
224+ if (childProps == null ) {
225+ return null ;
226+ }
227+ return function .apply (childProps , parts [1 ]);
228+ }
229+
187230 @ Nullable
188231 public ExtendedConfigProperties getConfigProperties (String name ) {
232+ ExtendedConfigProperties value = getConfigPropertiesInternal (name );
233+ if (value == null && hasDotNotation (name )) {
234+ return applyToChild (name , ExtendedConfigProperties ::getConfigProperties );
235+ }
236+ return value ;
237+ }
238+
239+ @ Nullable
240+ private ExtendedConfigProperties getConfigPropertiesInternal (String name ) {
189241 return mapEntries .get (name );
190242 }
191243
192244 @ Nullable
193245 public List <ExtendedConfigProperties > getListConfigProperties (String name ) {
194- return listEntries .get (name );
246+ List <ExtendedConfigProperties > value = listEntries .get (name );
247+ if (value == null && hasDotNotation (name )) {
248+ return applyToChild (name , ExtendedConfigProperties ::getListConfigProperties );
249+ }
250+ return value ;
195251 }
196252
197253 @ Override
0 commit comments