commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Mark (JIRA)" <>
Subject [jira] [Created] (COLLECTIONS-602) Improve efficiency of DefaultedMap.get
Date Fri, 19 May 2017 14:24:04 GMT
John Mark created COLLECTIONS-602:

             Summary: Improve efficiency of DefaultedMap.get
                 Key: COLLECTIONS-602
             Project: Commons Collections
          Issue Type: Bug
            Reporter: John Mark

The current implementation of {{}} is
inefficient since it always require two map lookups. There is no need to check map.containsKey()
every time. I would suggest implementing this method similar to the way that Java 8 does with
{{Map.getOrDefault()}}. My proposed implementation would be something like this:

public V get(final Object key) {
    V v;
    return ((v = map.get(key) != null) || map.containsKey(key)) ? v : value.transform((K)

It can be further optimized to not even call map.containsKey() if map is known to not contain
null values.

This message was sent by Atlassian JIRA

View raw message