Ignore:
Timestamp:
2017-03-25T23:34:39+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #14572 - Don't index MultipolygonCache by NavigatableComponent

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java

    r11117 r11779  
    2828import org.openstreetmap.josm.data.projection.Projection;
    2929import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
    30 import org.openstreetmap.josm.gui.NavigatableComponent;
    3130import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
    3231import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     
    4342    private static final MultipolygonCache INSTANCE = new MultipolygonCache();
    4443
    45     private final Map<NavigatableComponent, Map<DataSet, Map<Relation, Multipolygon>>> cache;
     44    private final Map<DataSet, Map<Relation, Multipolygon>> cache;
    4645
    4746    private final Collection<PolyData> selectedPolyData;
     
    6564    /**
    6665     * Gets a multipolygon from cache.
    67      * @param nc The navigatable component
    6866     * @param r The multipolygon relation
    6967     * @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);
    7372    }
    7473
    7574    /**
    7675     * Gets a multipolygon from cache.
    77      * @param nc The navigatable component
    7876     * @param r The multipolygon relation
    7977     * @param forceRefresh if {@code true}, a new object will be created even of present in cache
    8078     * @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) {
    8382        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());
    9185            if (map2 == null) {
    9286                map2 = new ConcurrentHashMap<>();
    93                 map1.put(r.getDataSet(), map2);
     87                cache.put(r.getDataSet(), map2);
    9488            }
    9589            multipolygon = map2.get(r);
     
    108102
    109103    /**
    110      * Clears the cache for the given navigatable component.
    111      * @param nc the navigatable component
    112      */
    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     /**
    121104     * Clears the cache for the given dataset.
    122105     * @param ds the data set
    123106     */
    124107    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();
    130111        }
    131112    }
     
    140121    private Collection<Map<Relation, Multipolygon>> getMapsFor(DataSet ds) {
    141122        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);
    147126        }
    148127        return result;
Note: See TracChangeset for help on using the changeset viewer.