Skip to content

Commit 20d39f7

Browse files
committed
Polish
1 parent 818d3bd commit 20d39f7

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -193,49 +193,49 @@ private void extractPropertiesFromServices(Properties properties,
193193
}
194194
}
195195

196+
@SuppressWarnings("unchecked")
196197
private void flatten(Properties properties, Map<String, Object> input, String path) {
197198
for (Entry<String, Object> entry : input.entrySet()) {
198-
String key = entry.getKey();
199-
if (StringUtils.hasText(path)) {
200-
if (key.startsWith("[")) {
201-
key = path + key;
202-
}
203-
else {
204-
key = path + "." + key;
205-
}
206-
}
199+
String key = getFullKey(path, entry.getKey());
207200
Object value = entry.getValue();
208-
if (value instanceof String) {
209-
properties.put(key, value);
210-
}
211-
else if (value instanceof Number) {
212-
properties.put(key, value.toString());
213-
}
214-
else if (value instanceof Boolean) {
215-
properties.put(key, value.toString());
216-
}
217-
else if (value instanceof Map) {
201+
if (value instanceof Map) {
218202
// Need a compound key
219-
@SuppressWarnings("unchecked")
220-
Map<String, Object> map = (Map<String, Object>) value;
221-
flatten(properties, map, key);
203+
flatten(properties, (Map<String, Object>) value, key);
222204
}
223205
else if (value instanceof Collection) {
224206
// Need a compound key
225-
@SuppressWarnings("unchecked")
226207
Collection<Object> collection = (Collection<Object>) value;
227208
properties.put(key,
228209
StringUtils.collectionToCommaDelimitedString(collection));
229210
int count = 0;
230-
for (Object object : collection) {
231-
flatten(properties,
232-
Collections.singletonMap("[" + (count++) + "]", object), key);
211+
for (Object item : collection) {
212+
String itemKey = "[" + (count++) + "]";
213+
flatten(properties, Collections.singletonMap(itemKey, item), key);
233214
}
234215
}
216+
else if (value instanceof String) {
217+
properties.put(key, value);
218+
}
219+
else if (value instanceof Number) {
220+
properties.put(key, value.toString());
221+
}
222+
else if (value instanceof Boolean) {
223+
properties.put(key, value.toString());
224+
}
235225
else {
236226
properties.put(key, value == null ? "" : value);
237227
}
238228
}
239229
}
240230

231+
private String getFullKey(String path, String key) {
232+
if (!StringUtils.hasText(path)) {
233+
return key;
234+
}
235+
if (key.startsWith("[")) {
236+
return path + key;
237+
}
238+
return path + "." + key;
239+
}
240+
241241
}

0 commit comments

Comments
 (0)