Merge pull request #36463 from elevne

* pr/36463:
  Polish contribution
  Harmonize use of Stream in ConfigDataLocationBindHandler.onSuccess

Closes gh-36463
pull/36620/head
Stephane Nicoll 1 year ago
commit 8bc9ada957

@ -16,6 +16,7 @@
package org.springframework.boot.context.config; package org.springframework.boot.context.config;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -44,23 +45,17 @@ class ConfigDataLocationBindHandler extends AbstractBindHandler {
return withOrigin(context, (ConfigDataLocation) result); return withOrigin(context, (ConfigDataLocation) result);
} }
if (result instanceof List) { if (result instanceof List) {
List<Object> list = ((List<Object>) result).stream().filter(Objects::nonNull).collect(Collectors.toList()); return ((List<Object>) result).stream()
for (int i = 0; i < list.size(); i++) { .filter(Objects::nonNull)
Object element = list.get(i); .map((element) -> (element instanceof ConfigDataLocation)
if (element instanceof ConfigDataLocation) { ? withOrigin(context, (ConfigDataLocation) element) : element)
list.set(i, withOrigin(context, (ConfigDataLocation) element)); .collect(Collectors.toCollection(ArrayList::new));
}
}
return list;
} }
if (result instanceof ConfigDataLocation[]) { if (result instanceof ConfigDataLocation[]) {
ConfigDataLocation[] locations = Arrays.stream((ConfigDataLocation[]) result) return Arrays.stream((ConfigDataLocation[]) result)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map((element) -> withOrigin(context, element))
.toArray(ConfigDataLocation[]::new); .toArray(ConfigDataLocation[]::new);
for (int i = 0; i < locations.length; i++) {
locations[i] = withOrigin(context, locations[i]);
}
return locations;
} }
return result; return result;
} }

Loading…
Cancel
Save