leventov commented on a change in pull request #8059: Refactoring to use 
`CollectionUtils.mapValues`
URL: https://github.com/apache/incubator-druid/pull/8059#discussion_r303093404
 
 

 ##########
 File path: core/src/main/java/org/apache/druid/utils/CollectionUtils.java
 ##########
 @@ -83,6 +86,17 @@ public int size()
     return result;
   }
 
+  /**
+   * Returns a transformed map from the given input map where the key is 
modified based on the given keyMapper
+   * function.
+   */
+  public static <K, V, K2> Map<K2, V> mapKeys(Map<K, V> map, Function<K, K2> 
keyMapper)
+  {
+    final Map<K2, V> result = Maps.newHashMapWithExpectedSize(map.size());
+    map.forEach((k, v) -> result.put(keyMapper.apply(k), v));
 
 Review comment:
   I think it's better if this method fails with IllegalStateException on keys 
collisions if the key mapper is not a bijection, similar to 
[`ImmutableMap.Builder`](https://guava.dev/releases/19.0/api/docs/com/google/common/collect/ImmutableMap.Builder.html).
 This should also be reflected in the method's javadoc.

----------------------------------------------------------------
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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to