Ignore:
Timestamp:
2012-02-15T15:28:58+01:00 (12 years ago)
Author:
bastiK
Message:

remove old migration code; keep class structure for next migration step Array -> ListOfStructs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r4874 r4936  
    14171417    }
    14181418
    1419 
    1420     /**
    1421      * Convert mappaint and preset source preferences from a simple list to
    1422      * array with one line for each source entry.
    1423      *
    1424      * MapPaint:
    1425      *
    1426      *    Old format
    1427      *      key: mappaint.style.sources
    1428      *      value: list of "<name>=<url>" pairs. The "<name>=" part is optional.
    1429      *          The style is always active.
    1430      *      default: empty list
    1431      *
    1432      *      key: mappaint.style.enable-defaults
    1433      *      value: if true, the default style "resource://data/elemstyles.xml" should
    1434      *          be loaded.
    1435      *      default: true
    1436      *
    1437      *    New format
    1438      *      key: mappaint.style.sources-list
    1439      *      value: each line is a list with entries: url, name, shortdescription, active
    1440      *      default:
    1441      *          One line: "resource://data/elemstyles.xml", "standard", tr("Internal Style"), true
    1442      *
    1443      * Tagging Preset:
    1444      *
    1445      *      the same, but "name" and "active" are not needed and omitted
    1446      *
    1447      */
    1448     abstract public static class SourcePrefMigration {
    1449 
    1450         private final String oldPref;
    1451         private final String oldPrefEnableDefaults;
     1419    abstract public static class SourcePrefHelper {
     1420
    14521421        private final String pref;
    14531422
    1454         public SourcePrefMigration(String oldPref, String oldPrefEnableDefaults, String pref) {
    1455             this.oldPref = oldPref;
    1456             this.oldPrefEnableDefaults = oldPrefEnableDefaults;
     1423        public SourcePrefHelper(String pref) {
    14571424            this.pref = pref;
    14581425        }
     
    14651432
    14661433        public List<SourceEntry> get() {
    1467             List<SourceEntry> entries = readNewFormatImpl();
    1468             if (entries == null) {
    1469 
    1470                 entries = readOldFormat();
    1471                 put(entries);
    1472                 return entries;
    1473             }
    1474             return entries;
    1475         }
    1476 
    1477         public boolean put(Collection<? extends SourceEntry> entries) {
    1478             boolean changed = false;
    1479             if (entries.isEmpty()) {
    1480                 changed |= Main.pref.put(pref + "._empty_", true);
    1481                 changed |= Main.pref.putArray(pref, null);
    1482             } else {
    1483                 Collection<Collection<String>> setting = new ArrayList<Collection<String>>();
    1484                 for (SourceEntry e : entries) {
    1485                     setting.add(serialize(e));
    1486                 }
    1487                 changed |= Main.pref.put(pref + "._empty_", null);
    1488                 changed |= Main.pref.putArray(pref, setting);
    1489             }
    1490             return changed;
    1491         }
    1492 
    1493         public List<SourceEntry> readOldFormat() {
    1494             List<SourceEntry> result = new ArrayList<SourceEntry>();
    1495             if (Main.pref.getBoolean(oldPrefEnableDefaults, true)) {
    1496                 result.addAll(getDefault());
    1497             }
    1498 
    1499             List<String> lines = new LinkedList<String>(Main.pref.getCollection(oldPref));
    1500             for (String line : lines) {
    1501                 String[] a = null;
    1502                 if (line.indexOf("=") >= 0) {
    1503                     a = line.split("=", 2);
    1504                 } else {
    1505                     a = new String[] { null, line };
    1506                 }
    1507                 result.add(new SourceEntry(a[1], a[0], null, true));
    1508             }
    1509 
    1510             return result;
    1511         }
    1512 
    1513         public Collection<? extends SourceEntry> readNewFormat() {
    1514             List<SourceEntry> entries = readNewFormatImpl();
    1515             if (entries == null)
    1516                 return getDefault();
    1517             return entries;
    1518         }
    1519 
    1520         private List<SourceEntry> readNewFormatImpl() {
     1434            Collection<Collection<String>> mappaintSrc = Main.pref.getArray(pref, null);
     1435            if (mappaintSrc == null)
     1436                return new ArrayList<SourceEntry>(getDefault());
     1437
    15211438            List<SourceEntry> entries = new ArrayList<SourceEntry>();
    1522             Collection<Collection<String>> mappaintSrc = Main.pref.getArray(pref, null);
    1523             if (mappaintSrc == null || mappaintSrc.isEmpty()) {
    1524                 if (Main.pref.getBoolean(pref + "._empty_", false))
    1525                     return Collections.<SourceEntry>emptyList();
    1526                 return null;
    1527             }
    1528 
    15291439            for (Collection<String> sourcePref : mappaintSrc) {
    15301440                SourceEntry e = deserialize(new ArrayList<String>(sourcePref));
     
    15351445            return entries;
    15361446        }
     1447
     1448        public boolean put(Collection<? extends SourceEntry> entries) {
     1449            Collection<Collection<String>> setting = new ArrayList<Collection<String>>();
     1450            for (SourceEntry e : entries) {
     1451                setting.add(serialize(e));
     1452            }
     1453            return Main.pref.putArray(pref, setting);
     1454        }
    15371455    }
    15381456
Note: See TracChangeset for help on using the changeset viewer.