Changeset 12865 in josm
- Timestamp:
- 2017-09-15T01:20:41+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/APIDataSet.java
r12673 r12865 282 282 283 283 public Set<Relation> getChildren(Relation relation) { 284 Set<Relation> p = children.get(relation); 285 if (p == null) { 286 p = new HashSet<>(); 287 children.put(relation, p); 288 } 289 return p; 284 return children.computeIfAbsent(relation, k -> new HashSet<>()); 290 285 } 291 286 -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r12857 r12865 47 47 import org.openstreetmap.josm.data.preferences.ColorProperty; 48 48 import org.openstreetmap.josm.data.preferences.DoubleProperty; 49 import org.openstreetmap.josm.spi.preferences.IPreferences;50 49 import org.openstreetmap.josm.data.preferences.IntegerProperty; 51 50 import org.openstreetmap.josm.data.preferences.ListListSetting; … … 63 62 import org.openstreetmap.josm.spi.preferences.AbstractPreferences; 64 63 import org.openstreetmap.josm.spi.preferences.IBaseDirectories; 64 import org.openstreetmap.josm.spi.preferences.IPreferences; 65 65 import org.openstreetmap.josm.tools.CheckParameterUtil; 66 66 import org.openstreetmap.josm.tools.ColorHelper; … … 282 282 283 283 private ListenerList<PreferenceChangedListener> listenersForKey(String key) { 284 ListenerList<PreferenceChangedListener> keyListener = keyListeners.get(key); 285 if (keyListener == null) { 286 keyListener = ListenerList.create(); 287 keyListeners.put(key, keyListener); 288 } 289 return keyListener; 284 return keyListeners.computeIfAbsent(key, k -> ListenerList.create()); 290 285 } 291 286 -
trunk/src/org/openstreetmap/josm/data/cache/CacheEntryAttributes.java
r12620 r12865 89 89 */ 90 90 private long getLongAttr(String key) { 91 String val = attrs.get(key);92 if (val == null) {93 attrs.put(key, "0");94 return 0;95 }96 91 try { 97 return Long.parseLong( val);92 return Long.parseLong(attrs.computeIfAbsent(key, k -> "0")); 98 93 } catch (NumberFormatException e) { 99 94 attrs.put(key, "0"); -
trunk/src/org/openstreetmap/josm/data/cache/HostLimitQueue.java
r12620 r12865 159 159 if (limit == null) { 160 160 synchronized (hostSemaphores) { 161 limit = hostSemaphores.get(host); 162 if (limit == null) { 163 limit = new Semaphore(hostLimit); 164 hostSemaphores.put(host, limit); 165 } 161 limit = hostSemaphores.computeIfAbsent(host, k -> new Semaphore(hostLimit)); 166 162 } 167 163 } -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
r12765 r12865 68 68 String deduplicationKey = getCacheKey(); 69 69 synchronized (inProgress) { 70 Set<TileLoaderListener> newListeners = inProgress.get(deduplicationKey); 71 if (newListeners == null) { 72 newListeners = new HashSet<>(); 73 inProgress.put(deduplicationKey, newListeners); 74 } 75 newListeners.add(listener); 70 inProgress.computeIfAbsent(deduplicationKey, k -> new HashSet<>()).add(listener); 76 71 } 77 72 } -
trunk/src/org/openstreetmap/josm/data/osm/User.java
r12537 r12865 74 74 } 75 75 76 Long ouid = uid; 77 User user = userMap.get(ouid); 78 if (user == null) { 79 user = new User(uid, name); 80 userMap.put(ouid, user); 81 } 76 User user = userMap.computeIfAbsent(uid, k -> new User(uid, name)); 82 77 if (name != null) user.addName(name); 83 78 -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryDataSet.java
r12636 r12865 125 125 public void put(HistoryOsmPrimitive primitive) { 126 126 PrimitiveId id = new SimplePrimitiveId(primitive.getId(), primitive.getType()); 127 if (data.get(id) == null) { 128 data.put(id, new ArrayList<HistoryOsmPrimitive>()); 129 } 130 data.get(id).add(primitive); 127 data.computeIfAbsent(id, k-> new ArrayList<>()).add(primitive); 131 128 fireHistoryUpdated(id); 132 129 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java
r12620 r12865 315 315 */ 316 316 public static List<List<WaySegment>> getSegments(Map<Point2D, List<WaySegment>> cellSegments, EastNorth n1, EastNorth n2) { 317 318 317 List<List<WaySegment>> cells = new ArrayList<>(); 319 318 for (Point2D cell : ValUtil.getSegmentCells(n1, n2, OsmValidator.getGridDetail())) { 320 List<WaySegment> segments = cellSegments.get(cell); 321 if (segments == null) { 322 segments = new ArrayList<>(); 323 cellSegments.put(cell, segments); 324 } 325 cells.add(segments); 319 cells.add(cellSegments.computeIfAbsent(cell, k -> new ArrayList<>())); 326 320 } 327 321 return cells; -
trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java
r12006 r12865 129 129 Map<String, RoleInfo> map = new HashMap<>(); 130 130 for (RelationMember m : n.getMembers()) { 131 String role = m.getRole(); 132 RoleInfo ri = map.get(role); 133 if (ri == null) { 134 ri = new RoleInfo(); 135 map.put(role, ri); 136 } 137 ri.total++; 131 map.computeIfAbsent(m.getRole(), k -> new RoleInfo()).total++; 138 132 } 139 133 return map; -
trunk/src/org/openstreetmap/josm/data/validation/util/ValUtil.java
r11852 r12865 56 56 cell = new Point2D.Double(x0, y0); 57 57 cellNodes.add(cell); 58 List<Way> ways = cellWays.get(cell); 59 if (ways == null) { 60 ways = new ArrayList<>(); 61 cellWays.put(cell, ways); 62 } 63 cells.add(ways); 58 cells.add(cellWays.computeIfAbsent(cell, k -> new ArrayList<>())); 64 59 65 60 // End of the way … … 67 62 if (!cellNodes.contains(cell)) { 68 63 cellNodes.add(cell); 69 ways = cellWays.get(cell); 70 if (ways == null) { 71 ways = new ArrayList<>(); 72 cellWays.put(cell, ways); 73 } 74 cells.add(ways); 64 cells.add(cellWays.computeIfAbsent(cell, k -> new ArrayList<>())); 75 65 } 76 66 … … 87 77 if (!cellNodes.contains(cell)) { 88 78 cellNodes.add(cell); 89 ways = cellWays.get(cell); 90 if (ways == null) { 91 ways = new ArrayList<>(); 92 cellWays.put(cell, ways); 93 } 94 cells.add(ways); 79 cells.add(cellWays.computeIfAbsent(cell, k -> new ArrayList<>())); 95 80 } 96 81 … … 99 84 if (!cellNodes.contains(cell)) { 100 85 cellNodes.add(cell); 101 ways = cellWays.get(cell); 102 if (ways == null) { 103 ways = new ArrayList<>(); 104 cellWays.put(cell, ways); 105 } 106 cells.add(ways); 86 cells.add(cellWays.computeIfAbsent(cell, k -> new ArrayList<>())); 107 87 } 108 88 return cells; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationNodeMap.java
r10043 r12865 108 108 109 109 private void addPair(Node n, int i) { 110 Set<Integer> ts = map.nodes.get(n); 111 if (ts == null) { 112 ts = new TreeSet<>(); 113 map.nodes.put(n, ts); 114 } 115 ts.add(i); 116 117 Set<Node> ts2 = map.ways.get(i); 118 if (ts2 == null) { 119 ts2 = new TreeSet<>(); 120 map.ways.put(i, ts2); 121 } 122 ts2.add(n); 110 map.nodes.computeIfAbsent(n, k -> new TreeSet<>()).add(i); 111 map.ways.computeIfAbsent(i, k -> new TreeSet<>()).add(n); 123 112 } 124 113 125 114 private void addNodeWayMap(Node n, int i) { 126 Set<Integer> ts = onewayMap.nodes.get(n); 127 if (ts == null) { 128 ts = new TreeSet<>(); 129 onewayMap.nodes.put(n, ts); 130 } 131 ts.add(i); 115 onewayMap.nodes.computeIfAbsent(n, k -> new TreeSet<>()).add(i); 132 116 } 133 117 134 118 private void addWayNodeMap(Node n, int i) { 135 Set<Node> ts2 = onewayMap.ways.get(i); 136 if (ts2 == null) { 137 ts2 = new TreeSet<>(); 138 onewayMap.ways.put(i, ts2); 139 } 140 ts2.add(n); 119 onewayMap.ways.computeIfAbsent(i, k -> new TreeSet<>()).add(n); 141 120 } 142 121 143 122 private void addNodeWayMapReverse(Node n, int i) { 144 Set<Integer> ts = onewayReverseMap.nodes.get(n); 145 if (ts == null) { 146 ts = new TreeSet<>(); 147 onewayReverseMap.nodes.put(n, ts); 148 } 149 ts.add(i); 123 onewayReverseMap.nodes.computeIfAbsent(n, k -> new TreeSet<>()).add(i); 150 124 } 151 125 152 126 private void addWayNodeMapReverse(Node n, int i) { 153 Set<Node> ts2 = onewayReverseMap.ways.get(i); 154 if (ts2 == null) { 155 ts2 = new TreeSet<>(); 156 onewayReverseMap.ways.put(i, ts2); 157 } 158 ts2.add(n); 127 onewayReverseMap.ways.computeIfAbsent(i, k -> new TreeSet<>()).add(n); 159 128 } 160 129 161 130 private void addRemainingForward(Node n, int i) { 162 Set<Node> ts2 = remainingOneway.get(i); 163 if (ts2 == null) { 164 ts2 = new TreeSet<>(); 165 remainingOneway.put(i, ts2); 166 } 167 ts2.add(n); 131 remainingOneway.computeIfAbsent(i, k -> new TreeSet<>()).add(n); 168 132 } 169 133 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorter.java
r12663 r12865 151 151 for (AdditionalSorter sorter : ADDITIONAL_SORTERS) { 152 152 if (sorter.acceptsMember(m)) { 153 List<RelationMember> list; 154 list = customMap.get(sorter); 155 if (list == null) { 156 list = new LinkedList<>(); 157 customMap.put(sorter, list); 158 } 159 list.add(m); 160 wasAdded = true; 153 wasAdded = customMap.computeIfAbsent(sorter, k -> new LinkedList<>()).add(m); 161 154 break; 162 155 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java
r12859 r12865 506 506 } 507 507 508 private static void registerListeners(AutoCompletionManager autoCompletionManager) {509 autoCompletionManager.ds.addDataSetListener(autoCompletionManager);508 private AutoCompletionManager registerListeners() { 509 ds.addDataSetListener(this); 510 510 MainApplication.getLayerManager().addLayerChangeListener(new LayerChangeListener() { 511 511 @Override 512 512 public void layerRemoving(LayerRemoveEvent e) { 513 513 if (e.getRemovedLayer() instanceof OsmDataLayer 514 && ((OsmDataLayer) e.getRemovedLayer()).data == autoCompletionManager.ds) {515 INSTANCES.remove( autoCompletionManager.ds);516 autoCompletionManager.ds.removeDataSetListener(autoCompletionManager);514 && ((OsmDataLayer) e.getRemovedLayer()).data == ds) { 515 INSTANCES.remove(ds); 516 ds.removeDataSetListener(AutoCompletionManager.this); 517 517 MainApplication.getLayerManager().removeLayerChangeListener(this); 518 518 } … … 529 529 } 530 530 }); 531 return this; 531 532 } 532 533 … … 538 539 */ 539 540 public static AutoCompletionManager of(DataSet dataSet) { 540 AutoCompletionManager result = INSTANCES.get(dataSet); 541 if (result == null) { 542 result = new AutoCompletionManager(dataSet); 543 INSTANCES.put(dataSet, result); 544 registerListeners(result); 545 } 546 return result; 541 return INSTANCES.computeIfAbsent(dataSet, ds -> new AutoCompletionManager(ds).registerListeners()); 547 542 } 548 543 } -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r12856 r12865 1322 1322 1323 1323 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<>()); 1330 1325 Image rotatedImg = cacheByAngle.get(originalAngle); 1331 1326 -
trunk/src/org/openstreetmap/josm/tools/ImageWarp.java
r12798 r12865 91 91 92 92 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))); 100 94 } 101 95 -
trunk/src/org/openstreetmap/josm/tools/MultiMap.java
r9790 r12865 66 66 */ 67 67 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); 74 69 } 75 70 … … 95 90 */ 96 91 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); 103 93 } 104 94
Note:
See TracChangeset
for help on using the changeset viewer.