help
public class ContextDataEntry {
private String id;
private Map<String, String> parameters = new HashMap();
}
// ...
public Map<String, Map<String, String>> toData(final List<ContextDataEntry> entries) {
Map<String, Map<String, String>> result = new HashMap<>();
entries.forEach(contextDataEntry -> {
if (!result.containsKey(contextDataEntry.getId())) {
result.put(contextDataEntry.getId(), new HashMap<>());
}
Map<String, String> stringStringMap = result.get(contextDataEntry.getId());
contextDataEntry.getParameters().forEach((key, value) -> {
stringStringMap.merge(key, value, (v1, v2) -> v2);
});
});
return result;
}
nie umiem takiego zgrabnego merdża zrobić :(
Test pod to:
@Test
void test() {
var result = uut.toData(List.of(new ContextDataEntry("id", Map.of("value", "dupa1")),
new ContextDataEntry("id2", Map.of("value", "dupa2")),
new ContextDataEntry("id", Map.of("value", "dupa3"))));
assertThat(result.get("id").get("value")).isEqualTo("dupa3");
assertThat(result.get("id2").get("value")).isEqualTo("dupa2");
}