aherbert commented on a change in pull request #730:
URL: https://github.com/apache/commons-lang/pull/730#discussion_r631137318



##########
File path: src/main/java/org/apache/commons/lang3/EnumUtils.java
##########
@@ -294,6 +295,25 @@
         return map;
     }
 
+    /**
+     * <p>Gets the {@code Map} of enums.</p>
+     *
+     * <p>This method is useful when you need a map of enums.</p>
+     *
+     * @param <E> the type of enumeration
+     * @param <K> the type of the map key
+     * @param enumClass the class of the enum to query, not null
+     * @param keyFunction the function to query for the key, not null
+     * @return the modifiable map of enums, never null
+     */
+    public static <E extends Enum<E>, K> Map<K, E> getEnumMap(final Class<E> 
enumClass, final Function<E, K> keyFunction) {
+        final Map<K, E> map = new LinkedHashMap<>();

Review comment:
       Perhaps optimise the size of the hashmap:
   ```java
   final E[] elements = enumClass.getEnumConstants();
   final Map<K, E> map = new LinkedHashMap<>(elements.length);
   for (final E e : elements) {
   ```




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


Reply via email to