Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8287602

(fs) Avoid redundant HashMap.containsKey call in MimeTypesFileTypeDetector.putIfAbsent

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P5 P5
    • 19
    • None
    • core-libs
    • b26

      Only non-null values are put into Map<String,String> mimeTypeMap. It means, we can replace containsKey+put calls with single putIfAbsent call. It makes code a bit cleaner and faster.

       private void putIfAbsent(String key, String value) {
           if (key != null && !key.isEmpty() &&
               value != null && !value.isEmpty() &&
               !mimeTypeMap.containsKey(key))
           {
               mimeTypeMap.put(key, value);
           }
       }

            aturbanov Andrey Turbanov
            aturbanov Andrey Turbanov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: