Changeset 11779 in josm for trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java
- Timestamp:
- 2017-03-25T23:34:39+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java
r11117 r11779 28 28 import org.openstreetmap.josm.data.projection.Projection; 29 29 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; 30 import org.openstreetmap.josm.gui.NavigatableComponent;31 30 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 32 31 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; … … 43 42 private static final MultipolygonCache INSTANCE = new MultipolygonCache(); 44 43 45 private final Map< NavigatableComponent, Map<DataSet, Map<Relation, Multipolygon>>> cache;44 private final Map<DataSet, Map<Relation, Multipolygon>> cache; 46 45 47 46 private final Collection<PolyData> selectedPolyData; … … 65 64 /** 66 65 * Gets a multipolygon from cache. 67 * @param nc The navigatable component68 66 * @param r The multipolygon relation 69 67 * @return A multipolygon object for the given relation, or {@code null} 70 */ 71 public Multipolygon get(NavigatableComponent nc, Relation r) { 72 return get(nc, r, false); 68 * @since 11779 69 */ 70 public Multipolygon get(Relation r) { 71 return get(r, false); 73 72 } 74 73 75 74 /** 76 75 * Gets a multipolygon from cache. 77 * @param nc The navigatable component78 76 * @param r The multipolygon relation 79 77 * @param forceRefresh if {@code true}, a new object will be created even of present in cache 80 78 * @return A multipolygon object for the given relation, or {@code null} 81 */ 82 public Multipolygon get(NavigatableComponent nc, Relation r, boolean forceRefresh) { 79 * @since 11779 80 */ 81 public Multipolygon get(Relation r, boolean forceRefresh) { 83 82 Multipolygon multipolygon = null; 84 if (nc != null && r != null) { 85 Map<DataSet, Map<Relation, Multipolygon>> map1 = cache.get(nc); 86 if (map1 == null) { 87 map1 = new ConcurrentHashMap<>(); 88 cache.put(nc, map1); 89 } 90 Map<Relation, Multipolygon> map2 = map1.get(r.getDataSet()); 83 if (r != null) { 84 Map<Relation, Multipolygon> map2 = cache.get(r.getDataSet()); 91 85 if (map2 == null) { 92 86 map2 = new ConcurrentHashMap<>(); 93 map1.put(r.getDataSet(), map2);87 cache.put(r.getDataSet(), map2); 94 88 } 95 89 multipolygon = map2.get(r); … … 108 102 109 103 /** 110 * Clears the cache for the given navigatable component.111 * @param nc the navigatable component112 */113 public void clear(NavigatableComponent nc) {114 Map<DataSet, Map<Relation, Multipolygon>> map = cache.remove(nc);115 if (map != null) {116 map.clear();117 }118 }119 120 /**121 104 * Clears the cache for the given dataset. 122 105 * @param ds the data set 123 106 */ 124 107 public void clear(DataSet ds) { 125 for (Map<DataSet, Map<Relation, Multipolygon>> map1 : cache.values()) { 126 Map<Relation, Multipolygon> map2 = map1.remove(ds); 127 if (map2 != null) { 128 map2.clear(); 129 } 108 Map<Relation, Multipolygon> map2 = cache.remove(ds); 109 if (map2 != null) { 110 map2.clear(); 130 111 } 131 112 } … … 140 121 private Collection<Map<Relation, Multipolygon>> getMapsFor(DataSet ds) { 141 122 List<Map<Relation, Multipolygon>> result = new ArrayList<>(); 142 for (Map<DataSet, Map<Relation, Multipolygon>> map : cache.values()) { 143 Map<Relation, Multipolygon> map2 = map.get(ds); 144 if (map2 != null) { 145 result.add(map2); 146 } 123 Map<Relation, Multipolygon> map2 = cache.get(ds); 124 if (map2 != null) { 125 result.add(map2); 147 126 } 148 127 return result;
Note:
See TracChangeset
for help on using the changeset viewer.