Changeset 16333 in josm for trunk/src


Ignore:
Timestamp:
2020-04-18T10:41:25+02:00 (4 years ago)
Author:
simon04
Message:

Java 8: use Map.computeIfAbsent

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java

    r15911 r16333  
    305305                    if (number != null) {
    306306                        number = number.trim().toUpperCase(Locale.ENGLISH);
    307                         List<OsmPrimitive> list = map.get(number);
    308                         if (list == null) {
    309                             list = new ArrayList<>();
    310                             map.put(number, list);
    311                         }
     307                        List<OsmPrimitive> list = map.computeIfAbsent(number, k -> new ArrayList<>());
    312308                        list.add(p);
    313309                    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Highways.java

    r15364 r16333  
    125125                    }
    126126                    if (!link || !linkOk) {
    127                         List<Way> list = map.get(value);
    128                         if (list == null) {
    129                             list = new ArrayList<>();
    130                             map.put(value, list);
    131                         }
     127                        List<Way> list = map.computeIfAbsent(value, k -> new ArrayList<>());
    132128                        list.add(h);
    133129                    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r16119 r16333  
    325325                    continue; // cannot be a problem node
    326326                }
    327                 List<Way> ways = nodeMap.get(n);
    328                 if (ways == null) {
    329                     ways = new ArrayList<>();
    330                     nodeMap.put(n, ways);
    331                 }
     327                List<Way> ways = nodeMap.computeIfAbsent(n, k -> new ArrayList<>());
    332328                ways.add(rm.getWay());
    333329                if (ways.size() > 2 || (ways.size() == 2 && i != 0 && i + 1 != numNodes)) {
     
    563559                    boolean samePoly = false;
    564560                    if (crossingPolys[0] != null && crossingPolys[1] != null) {
    565                         List<PolyData> crossingPolygons = problemPolygonMap.get(crossingPolys[0]);
    566                         if (crossingPolygons == null) {
    567                             crossingPolygons = new ArrayList<>();
    568                             problemPolygonMap.put(crossingPolys[0], crossingPolygons);
    569                         }
     561                        List<PolyData> crossingPolygons = problemPolygonMap.computeIfAbsent(crossingPolys[0], k -> new ArrayList<>());
    570562                        crossingPolygons.add(crossingPolys[1]);
    571563                        if (crossingPolys[0] == crossingPolys[1]) {
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolverModel.java

    r12660 r16333  
    8888        for (String key: tags.getKeys()) {
    8989            MultiValueResolutionDecision decision = new MultiValueResolutionDecision(tags.getTagsFor(key));
    90             if (decisions.get(key) == null) {
    91                 decisions.put(key, decision);
    92             }
     90            decisions.putIfAbsent(key, decision);
    9391        }
    9492        displayedKeys.clear();
     
    106104            }
    107105            for (String key: tags.getKeys()) {
    108                 if (!decisions.get(key).isDecided() && !keys.contains(key)) {
     106                if (!decisions.get(key).isDecided()) {
    109107                    keys.add(key);
    110108                }
  • trunk/src/org/openstreetmap/josm/io/ValidatorErrorWriter.java

    r16088 r16333  
    8181                    for (Entry<String, Map<String, List<TestError>>> e2 : e1.getValue().entrySet()) {
    8282                        ErrorClass errorClass = new ErrorClass(e1.getKey(), e2.getKey());
    83                         List<TestError> list = map.get(errorClass);
    84                         if (list == null) {
    85                             list = new ArrayList<>();
    86                             map.put(errorClass, list);
    87                         }
     83                        List<TestError> list = map.computeIfAbsent(errorClass, k -> new ArrayList<>());
    8884                        e2.getValue().values().forEach(list::addAll);
    8985                    }
Note: See TracChangeset for help on using the changeset viewer.