@@ -71,61 +71,37 @@ final class DeclarativeConfigPropertiesBridge implements ConfigProperties {
71
71
@ Nullable
72
72
@ Override
73
73
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 );
79
75
}
80
76
81
77
@ Nullable
82
78
@ Override
83
79
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 );
89
81
}
90
82
91
83
@ Nullable
92
84
@ Override
93
85
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 );
99
87
}
100
88
101
89
@ Nullable
102
90
@ Override
103
91
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 );
109
93
}
110
94
111
95
@ Nullable
112
96
@ Override
113
97
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 );
119
99
}
120
100
121
101
@ Nullable
122
102
@ Override
123
103
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 );
129
105
if (millis == null ) {
130
106
return null ;
131
107
}
@@ -135,26 +111,19 @@ public Duration getDuration(String propertyName) {
135
111
@ SuppressWarnings ("unchecked" )
136
112
@ Override
137
113
public List <String > getList (String propertyName ) {
138
- Object value = getOverride (propertyName );
139
- if (value != null ) {
140
- return (List <String >) value ;
141
- }
142
114
List <String > propertyValue =
143
115
getPropertyValue (
144
116
propertyName ,
117
+ List .class ,
145
118
(properties , lastPart ) -> properties .getScalarList (lastPart , String .class ));
146
119
return propertyValue == null ? Collections .emptyList () : propertyValue ;
147
120
}
148
121
149
122
@ SuppressWarnings ("unchecked" )
150
123
@ Override
151
124
public Map <String , String > getMap (String propertyName ) {
152
- Object fixed = getOverride (propertyName );
153
- if (fixed != null ) {
154
- return (Map <String , String >) fixed ;
155
- }
156
125
DeclarativeConfigProperties propertyValue =
157
- getPropertyValue (propertyName , DeclarativeConfigProperties ::getStructured );
126
+ getPropertyValue (propertyName , DeclarativeConfigProperties . class , DeclarativeConfigProperties ::getStructured );
158
127
if (propertyValue == null ) {
159
128
return Collections .emptyMap ();
160
129
}
@@ -174,7 +143,12 @@ public Map<String, String> getMap(String propertyName) {
174
143
175
144
@ Nullable
176
145
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
+
178
152
if (baseNode == null ) {
179
153
return null ;
180
154
}
@@ -212,9 +186,4 @@ private String translateProperty(String property) {
212
186
}
213
187
return property ;
214
188
}
215
-
216
- @ Nullable
217
- private Object getOverride (String propertyName ) {
218
- return overrideValues .get (propertyName );
219
- }
220
189
}
0 commit comments