Changeset 11527 in josm


Ignore:
Timestamp:
2017-02-02T18:52:17+01:00 (7 years ago)
Author:
stoecker
Message:

drop imagery entries which have an id, but are no longer in default list

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r11461 r11527  
    107107
    108108    private static final String[] OBSOLETE_PREF_KEYS = {
    109       "hdop.factor" /* remove entry after April 2017 */
     109      "hdop.factor", /* remove entry after April 2017 */
     110      "imagery.layers.addedIds" /* remove entry after June 2017 */
    110111    };
    111112
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r11347 r11527  
    10331033     */
    10341034    public void setNoTileHeaders(MultiMap<String, String> noTileHeaders) {
    1035        if (noTileHeaders == null) {
     1035       if (noTileHeaders == null || noTileHeaders.isEmpty()) {
    10361036           this.noTileHeaders = null;
    10371037       } else {
     
    10531053     */
    10541054    public void setNoTileChecksums(MultiMap<String, String> noTileChecksums) {
    1055         if (noTileChecksums == null) {
     1055        if (noTileChecksums == null || noTileChecksums.isEmpty()) {
    10561056            this.noTileChecksums = null;
    10571057        } else {
     
    10731073     */
    10741074    public void setMetadataHeaders(Map<String, String> metadataHeaders) {
    1075         this.metadataHeaders = metadataHeaders;
     1075        if (metadataHeaders == null || metadataHeaders.isEmpty()) {
     1076            this.metadataHeaders = null;
     1077        } else {
     1078            this.metadataHeaders = metadataHeaders;
     1079        }
    10761080    }
    10771081
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java

    r11385 r11527  
    170170            updateEntriesFromDefaults();
    171171            buildIdMap(layers, layerIds);
     172            dropOldEntries();
    172173        }
    173174    }
     
    232233        Main.pref.putCollection("imagery.layers.default", newKnownDefaults);
    233234
    234         // Add ids to user entries without id.
    235         // Only do this the first time for each id, so the user can have
    236         // custom entries that don't get updated automatically
    237         Collection<String> addedIds = Main.pref.getCollection("imagery.layers.addedIds");
    238         Collection<String> newAddedIds = new TreeSet<>(addedIds);
    239         for (ImageryInfo info : layers) {
    240             for (ImageryInfo def : defaultLayers) {
    241                 if (isSimilar(def, info) && def.getId() != null && !addedIds.contains(def.getId())) {
    242                     if (!defaultLayerIds.containsKey(def.getId())) {
    243                         // ignore ids used more than once (have been purged from the map)
    244                         continue;
    245                     }
    246                     newAddedIds.add(def.getId());
    247                     if (info.getId() == null) {
    248                         info.setId(def.getId());
    249                         changed = true;
    250                     }
    251                 }
    252             }
    253         }
    254         Main.pref.putCollection("imagery.layers.addedIds", newAddedIds);
    255 
    256235        // automatically update user entries with same id as a default entry
    257236        for (int i = 0; i < layers.size(); i++) {
     
    263242            if (matchingDefault != null && !matchingDefault.equalsPref(info)) {
    264243                layers.set(i, matchingDefault);
     244                Main.info(tr("Update imagery ''{0}''", info.getName()));
    265245                changed = true;
    266246            }
     
    268248
    269249        if (changed) {
     250            save();
     251        }
     252    }
     253
     254    /**
     255     * Drop entries with Id which do no longer exist (removed from defaults).
     256     */
     257    public void dropOldEntries() {
     258        List<String> drop = new ArrayList<>();
     259
     260        for (Map.Entry<String, ImageryInfo> info : layerIds.entrySet()) {
     261            if (!defaultLayerIds.containsKey(info.getKey())) {
     262                remove(info.getValue());
     263                drop.add(info.getKey());
     264                Main.info(tr("Drop old imagery ''{0}''", info.getValue().getName()));
     265            }
     266        }
     267
     268        if (!drop.isEmpty()) {
     269            for (String id : drop) {
     270                layerIds.remove(id);
     271            }
    270272            save();
    271273        }
Note: See TracChangeset for help on using the changeset viewer.