[GitHub] [nifi] phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p…
phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p… URL: https://github.com/apache/nifi/pull/3853#discussion_r363415464 ## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java ## @@ -561,9 +563,8 @@ private void updateEventRepository(final Checkpoint checkpoint) { return first; } -final Map combined = new HashMap<>(); -combined.putAll(first); -combined.putAll(second); +final Map combined = new HashMap<>(first); +second.forEach((key, value) -> combined.merge(key, value, (v1, v2) -> v1 + v2)); Review comment: In retrospect after a nice refreshing break I'm not sure how I arrived at such a question. This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [nifi] phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p…
phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p… URL: https://github.com/apache/nifi/pull/3853#discussion_r363415464 ## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java ## @@ -561,9 +563,8 @@ private void updateEventRepository(final Checkpoint checkpoint) { return first; } -final Map combined = new HashMap<>(); -combined.putAll(first); -combined.putAll(second); +final Map combined = new HashMap<>(first); +second.forEach((key, value) -> combined.merge(key, value, (v1, v2) -> v1 + v2)); Review comment: In retrospect after a nice refreshing break I'm not sure how I arrived that such a question. This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [nifi] phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p…
phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p… URL: https://github.com/apache/nifi/pull/3853#discussion_r340747184 ## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java ## @@ -3406,6 +3396,41 @@ private void checkpoint(final StandardProcessSession session, final List void mergeMaps(final Map destination, final Map toMerge, final BiFunction merger) { +if (toMerge == null) { +return; +} + +if (destination.isEmpty()) { +destination.putAll(toMerge); +} else { +toMerge.forEach((key, value) -> destination.merge(key, value, merger)); +} +} + +private void mergeMapsWithMutableValue(final Map destination, final Map toMerge, final BiConsumer merger) { +if (toMerge == null) { +return; +} + +if (destination.isEmpty()) { +destination.putAll(toMerge); +return; +} + +for (final Map.Entry entry : toMerge.entrySet()) { +final K key = entry.getKey(); +final V value = entry.getValue(); + +final V destinationValue = destination.get(key); +if (destinationValue == null) { Review comment: Could this simply be a foreach -> merge with a biconsumer accepting the original bi consumer? Might shorten the code..but again my ten thousand foot overview look might be totally off base. This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [nifi] phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p…
phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p… URL: https://github.com/apache/nifi/pull/3853#discussion_r340743192 ## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java ## @@ -3406,6 +3396,41 @@ private void checkpoint(final StandardProcessSession session, final List void mergeMaps(final Map destination, final Map toMerge, final BiFunction merger) { +if (toMerge == null) { Review comment: As a safety could you add a null check for destination too? This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [nifi] phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p…
phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p… URL: https://github.com/apache/nifi/pull/3853#discussion_r340742409 ## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java ## @@ -561,9 +563,8 @@ private void updateEventRepository(final Checkpoint checkpoint) { return first; } -final Map combined = new HashMap<>(); -combined.putAll(first); -combined.putAll(second); +final Map combined = new HashMap<>(first); +second.forEach((key, value) -> combined.merge(key, value, (v1, v2) -> v1 + v2)); Review comment: Could this not be expressed a little more succinctly as second.forEach(combined.putIfAbsent) ? Same relative outcome no? I am glancing quickly so ignore me if I'm crazy. This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [nifi] phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p…
phrocker commented on a change in pull request #3853: NIFI-6822: Ensure that when we manage a Map of ID -> Count, that we p… URL: https://github.com/apache/nifi/pull/3853#discussion_r340742409 ## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java ## @@ -561,9 +563,8 @@ private void updateEventRepository(final Checkpoint checkpoint) { return first; } -final Map combined = new HashMap<>(); -combined.putAll(first); -combined.putAll(second); +final Map combined = new HashMap<>(first); +second.forEach((key, value) -> combined.merge(key, value, (v1, v2) -> v1 + v2)); Review comment: Could this not be expressed a little more succinctly as second.forEach(combined.putIfAbsent) ? This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services