Merge pull request #1270 from navi-infra/INFRA-4022-4

INFRA-4022 | Dhruv | fixes flatmap ignoring empty collection
This commit is contained in:
Dhruv Joshi
2024-11-28 21:16:32 +05:30
committed by GitHub
2 changed files with 11 additions and 3 deletions

View File

@@ -34,6 +34,9 @@ public final class FlatMapUtil {
final var root = entry.getKey();
if (entry.getValue() instanceof Map<?, ?>) {
Map<?, ?> properties = (Map<?, ?>) entry.getValue();
if (properties.isEmpty()) {
return Stream.of(new SimpleEntry<>(root, Map.of()));
}
return properties.entrySet()
.stream()
.map(e -> mapToEntry(root, e))
@@ -42,6 +45,9 @@ public final class FlatMapUtil {
if (entry.getValue() instanceof List<?>) {
List<?> list = (List<?>) entry.getValue();
if (list.isEmpty()) {
return Stream.of(new SimpleEntry<>(root, List.of()));
}
return IntStream.range(0, list.size())
.mapToObj(i -> mapToEntry(root, list.get(i), i))
.flatMap(FlatMapUtil::flatten);
@@ -54,8 +60,10 @@ public final class FlatMapUtil {
return new SimpleEntry<>(getKey(root, e), e.getValue());
}
private static SimpleEntry<String, Object> mapToEntry(final String root, final Object value,
final int i) {
private static SimpleEntry<String, Object> mapToEntry(
final String root, final Object value,
final int i
) {
return new SimpleEntry<>(getKey(root, i), value);
}

View File

@@ -110,7 +110,7 @@ public class MapDiffUtil {
final var result = new HashMap<String, Object>();
for (var e : map.entrySet()) {
Entry<String, Object> entry = e;
if (e.getKey().contains("environmentVariables")) {
if (e.getKey().contains("environmentVariables/")) {
entry = mapEnvVarToKey(map).apply(e);
}
result.put(entry.getKey(), entry.getValue());