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<Provena
             this.contentSizeOut += session.contentSizeOut;
         }
 
+        private <K, V> void mergeMaps(final Map<K, V> destination, final 
Map<K, V> toMerge, final BiFunction<? super V, ? super V, ? extends V> merger) {
+            if (toMerge == null) {
+                return;
+            }
+
+            if (destination.isEmpty()) {
+                destination.putAll(toMerge);
+            } else {
+                toMerge.forEach((key, value) -> destination.merge(key, value, 
merger));
+            }
+        }
+
+        private <K, V> void mergeMapsWithMutableValue(final Map<K, V> 
destination, final Map<K, V> toMerge, final BiConsumer<? super V, ? super V> 
merger) {
+            if (toMerge == null) {
+                return;
+            }
+
+            if (destination.isEmpty()) {
+                destination.putAll(toMerge);
+                return;
+            }
+
+            for (final Map.Entry<K, V> 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:
[email protected]


With regards,
Apache Git Services

Reply via email to