@@ -71,61 +71,37 @@ final class DeclarativeConfigPropertiesBridge implements ConfigProperties {
7171 @ Nullable
7272 @ Override
7373 public String getString (String propertyName ) {
74- Object value = getOverride (propertyName );
75- if (value != null ) {
76- return value .toString ();
77- }
78- return getPropertyValue (propertyName , DeclarativeConfigProperties ::getString );
74+ return getPropertyValue (propertyName , String .class , DeclarativeConfigProperties ::getString );
7975 }
8076
8177 @ Nullable
8278 @ Override
8379 public Boolean getBoolean (String propertyName ) {
84- Object value = getOverride (propertyName );
85- if (value != null ) {
86- return (Boolean ) value ;
87- }
88- return getPropertyValue (propertyName , DeclarativeConfigProperties ::getBoolean );
80+ return getPropertyValue (propertyName , Boolean .class , DeclarativeConfigProperties ::getBoolean );
8981 }
9082
9183 @ Nullable
9284 @ Override
9385 public Integer getInt (String propertyName ) {
94- Object value = getOverride (propertyName );
95- if (value != null ) {
96- return (Integer ) value ;
97- }
98- return getPropertyValue (propertyName , DeclarativeConfigProperties ::getInt );
86+ return getPropertyValue (propertyName , Integer .class , DeclarativeConfigProperties ::getInt );
9987 }
10088
10189 @ Nullable
10290 @ Override
10391 public Long getLong (String propertyName ) {
104- Object value = getOverride (propertyName );
105- if (value != null ) {
106- return (Long ) value ;
107- }
108- return getPropertyValue (propertyName , DeclarativeConfigProperties ::getLong );
92+ return getPropertyValue (propertyName , Long .class , DeclarativeConfigProperties ::getLong );
10993 }
11094
11195 @ Nullable
11296 @ Override
11397 public Double getDouble (String propertyName ) {
114- Object value = getOverride (propertyName );
115- if (value != null ) {
116- return (Double ) value ;
117- }
118- return getPropertyValue (propertyName , DeclarativeConfigProperties ::getDouble );
98+ return getPropertyValue (propertyName , Double .class , DeclarativeConfigProperties ::getDouble );
11999 }
120100
121101 @ Nullable
122102 @ Override
123103 public Duration getDuration (String propertyName ) {
124- Object value = getOverride (propertyName );
125- if (value != null ) {
126- return (Duration ) value ;
127- }
128- Long millis = getPropertyValue (propertyName , DeclarativeConfigProperties ::getLong );
104+ Long millis = getPropertyValue (propertyName , Long .class , DeclarativeConfigProperties ::getLong );
129105 if (millis == null ) {
130106 return null ;
131107 }
@@ -135,26 +111,19 @@ public Duration getDuration(String propertyName) {
135111 @ SuppressWarnings ("unchecked" )
136112 @ Override
137113 public List <String > getList (String propertyName ) {
138- Object value = getOverride (propertyName );
139- if (value != null ) {
140- return (List <String >) value ;
141- }
142114 List <String > propertyValue =
143115 getPropertyValue (
144116 propertyName ,
117+ List .class ,
145118 (properties , lastPart ) -> properties .getScalarList (lastPart , String .class ));
146119 return propertyValue == null ? Collections .emptyList () : propertyValue ;
147120 }
148121
149122 @ SuppressWarnings ("unchecked" )
150123 @ Override
151124 public Map <String , String > getMap (String propertyName ) {
152- Object fixed = getOverride (propertyName );
153- if (fixed != null ) {
154- return (Map <String , String >) fixed ;
155- }
156125 DeclarativeConfigProperties propertyValue =
157- getPropertyValue (propertyName , DeclarativeConfigProperties ::getStructured );
126+ getPropertyValue (propertyName , DeclarativeConfigProperties . class , DeclarativeConfigProperties ::getStructured );
158127 if (propertyValue == null ) {
159128 return Collections .emptyMap ();
160129 }
@@ -174,7 +143,12 @@ public Map<String, String> getMap(String propertyName) {
174143
175144 @ Nullable
176145 private <T > T getPropertyValue (
177- String property , BiFunction <DeclarativeConfigProperties , String , T > extractor ) {
146+ String property , Class <T > clazz , BiFunction <DeclarativeConfigProperties , String , T > extractor ) {
147+ T override = clazz .cast (overrideValues .get (property ));
148+ if (override != null ) {
149+ return override ;
150+ }
151+
178152 if (baseNode == null ) {
179153 return null ;
180154 }
@@ -212,9 +186,4 @@ private String translateProperty(String property) {
212186 }
213187 return property ;
214188 }
215-
216- @ Nullable
217- private Object getOverride (String propertyName ) {
218- return overrideValues .get (propertyName );
219- }
220189}
0 commit comments