Changeset 12982 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-10-11T14:09:31+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r12946 r12982 17 17 import java.lang.reflect.Field; 18 18 import java.nio.charset.StandardCharsets; 19 import java.util.AbstractMap;20 19 import java.util.ArrayList; 21 20 import java.util.Collection; … … 37 36 import java.util.regex.Matcher; 38 37 import java.util.regex.Pattern; 39 import java.util.stream.Collectors;40 38 import java.util.stream.Stream; 41 39 … … 56 54 import org.openstreetmap.josm.spi.preferences.Setting; 57 55 import org.openstreetmap.josm.spi.preferences.StringSetting; 58 import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;59 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;60 56 import org.openstreetmap.josm.io.OfflineAccessException; 61 57 import org.openstreetmap.josm.io.OnlineResource; … … 100 96 101 97 private static final String[] OBSOLETE_PREF_KEYS = { 102 "imagery.layers.addedIds", /* remove entry after June 2017 */103 98 "projection", /* remove entry after Nov. 2017 */ 104 99 "projection.sub", /* remove entry after Nov. 2017 */ … … 1561 1556 */ 1562 1557 private void removeObsolete(int loadedVersion) { 1563 // drop in March 20171564 removeUrlFromEntries(loadedVersion, 10063,1565 "validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries",1566 "resource://data/validator/power.mapcss");1567 // drop in March 20171568 if (loadedVersion < 11058) {1569 migrateOldColorKeys();1570 }1571 // drop in September 20171572 if (loadedVersion < 11424) {1573 addNewerDefaultEntry(1574 "validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries",1575 "resource://data/validator/territories.mapcss");1576 }1577 1578 1558 for (String key : OBSOLETE_PREF_KEYS) { 1579 1559 if (settingsMap.containsKey(key)) { … … 1584 1564 } 1585 1565 1586 private void migrateOldColorKeys() {1587 settingsMap.keySet().stream()1588 .filter(key -> key.startsWith(COLOR_PREFIX))1589 .flatMap(this::searchOldColorKey)1590 .collect(Collectors.toList()) // to avoid ConcurrentModificationException1591 .forEach(entry -> {1592 final String oldKey = entry.getKey();1593 final String newKey = entry.getValue();1594 Logging.info("Migrating old color key {0} => {1}", oldKey, newKey);1595 put(newKey, get(oldKey));1596 put(oldKey, null);1597 });1598 }1599 1600 private Stream<AbstractMap.SimpleImmutableEntry<String, String>> searchOldColorKey(String key) {1601 final String newKey = ColorProperty.getColorKey(key.substring(COLOR_PREFIX.length()));1602 return key.equals(newKey) || settingsMap.containsKey(newKey)1603 ? Stream.empty()1604 : Stream.of(new AbstractMap.SimpleImmutableEntry<>(key, newKey));1605 }1606 1607 private void removeUrlFromEntries(int loadedVersion, int versionMax, String key, String urlPart) {1608 if (loadedVersion < versionMax) {1609 Setting<?> setting = settingsMap.get(key);1610 if (setting instanceof MapListSetting) {1611 List<Map<String, String>> l = new LinkedList<>();1612 boolean modified = false;1613 for (Map<String, String> map: ((MapListSetting) setting).getValue()) {1614 String url = map.get("url");1615 if (url != null && url.contains(urlPart)) {1616 modified = true;1617 } else {1618 l.add(map);1619 }1620 }1621 if (modified) {1622 putListOfMaps(key, l);1623 }1624 }1625 }1626 }1627 1628 private void addNewerDefaultEntry(String key, final String url) {1629 Setting<?> setting = settingsMap.get(key);1630 if (setting instanceof MapListSetting) {1631 List<Map<String, String>> l = new ArrayList<>(((MapListSetting) setting).getValue());1632 if (l.stream().noneMatch(x -> x.containsValue(url))) {1633 ValidatorPrefHelper helper = ValidatorPrefHelper.INSTANCE;1634 Optional<ExtendedSourceEntry> val = helper.getDefault().stream().filter(x -> url.equals(x.url)).findFirst();1635 if (val.isPresent()) {1636 l.add(helper.serialize(val.get()));1637 }1638 putListOfMaps(key, l);1639 }1640 }1641 }1642 1643 1566 /** 1644 1567 * Enables or not the preferences file auto-save mechanism (save each time a setting is changed).
Note:
See TracChangeset
for help on using the changeset viewer.