Ignore:
Timestamp:
2017-09-15T01:20:41+02:00 (2 years ago)
Author:
Don-vip
Message:

see #11390 - SonarQube - squid:S3824 - "Map.get" and value test should be replaced with single method call

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r12856 r12865  
    13221322
    13231323        synchronized (ROTATE_CACHE) {
    1324             Map<Long, Image> cacheByAngle = ROTATE_CACHE.get(img);
    1325             if (cacheByAngle == null) {
    1326                 cacheByAngle = new HashMap<>();
    1327                 ROTATE_CACHE.put(img, cacheByAngle);
    1328             }
    1329 
     1324            Map<Long, Image> cacheByAngle = ROTATE_CACHE.computeIfAbsent(img, k -> new HashMap<>());
    13301325            Image rotatedImg = cacheByAngle.get(originalAngle);
    13311326
  • trunk/src/org/openstreetmap/josm/tools/ImageWarp.java

    r12798 r12865  
    9191
    9292        private Point2D getValue(int xIdx, int yIdx) {
    93             Map<Integer, Point2D> row = getRow(yIdx);
    94             Point2D val = row.get(xIdx);
    95             if (val == null) {
    96                 val = trfm.transform(new Point2D.Double(xIdx * stride, yIdx * stride));
    97                 row.put(xIdx, val);
    98             }
    99             return val;
     93            return getRow(yIdx).computeIfAbsent(xIdx, k -> trfm.transform(new Point2D.Double(xIdx * stride, yIdx * stride)));
    10094        }
    10195
  • trunk/src/org/openstreetmap/josm/tools/MultiMap.java

    r9790 r12865  
    6666     */
    6767    public void put(A key, B value) {
    68         Set<B> vals = map.get(key);
    69         if (vals == null) {
    70             vals = new LinkedHashSet<>();
    71             map.put(key, vals);
    72         }
    73         vals.add(value);
     68        map.computeIfAbsent(key, k -> new LinkedHashSet<>()).add(value);
    7469    }
    7570
     
    9590     */
    9691    public void putAll(A key, Collection<B> values) {
    97         Set<B> vals = map.get(key);
    98         if (vals == null) {
    99             vals = new LinkedHashSet<>(values);
    100             map.put(key, vals);
    101         }
    102         vals.addAll(values);
     92        map.computeIfAbsent(key, k -> new LinkedHashSet<>(values)).addAll(values);
    10393    }
    10494
Note: See TracChangeset for help on using the changeset viewer.