Ignore:
Timestamp:
2017-04-15T01:38:46+02:00 (9 years ago)
Author:
Don-vip
Message:

sonar - squid:S1192 - String literals should not be duplicated

File:
1 edited

Legend:

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

    r11746 r11913  
    106106public class Preferences {
    107107
     108    private static final String COLOR_PREFIX = "color.";
     109
    108110    private static final String[] OBSOLETE_PREF_KEYS = {
    109111      "hdop.factor", /* remove entry after April 2017 */
     
    501503        final Map<String, String> all = new TreeMap<>();
    502504        for (final Entry<String, Setting<?>> e : defaultsMap.entrySet()) {
    503             if (e.getKey().startsWith("color.") && e.getValue() instanceof StringSetting) {
     505            if (e.getKey().startsWith(COLOR_PREFIX) && e.getValue() instanceof StringSetting) {
    504506                StringSetting d = (StringSetting) e.getValue();
    505507                if (d.getValue() != null) {
     
    509511        }
    510512        for (final Entry<String, Setting<?>> e : settingsMap.entrySet()) {
    511             if (e.getKey().startsWith("color.") && (e.getValue() instanceof StringSetting)) {
     513            if (e.getKey().startsWith(COLOR_PREFIX) && (e.getValue() instanceof StringSetting)) {
    512514                all.put(e.getKey().substring(6), ((StringSetting) e.getValue()).getValue());
    513515            }
     
    864866        String colKey = ColorProperty.getColorKey(colName);
    865867        registerColor(colKey, colName);
    866         String colStr = specName != null ? get("color."+specName) : "";
     868        String colStr = specName != null ? get(COLOR_PREFIX+specName) : "";
    867869        if (colStr.isEmpty()) {
    868870            colStr = get(colKey, ColorHelper.color2html(def, true));
     
    888890
    889891    public synchronized Color getDefaultColor(String colKey) {
    890         StringSetting col = Utils.cast(defaultsMap.get("color."+colKey), StringSetting.class);
     892        StringSetting col = Utils.cast(defaultsMap.get(COLOR_PREFIX+colKey), StringSetting.class);
    891893        String colStr = col == null ? null : col.getValue();
    892894        return colStr == null || colStr.isEmpty() ? null : ColorHelper.html2color(colStr);
     
    894896
    895897    public synchronized boolean putColor(String colKey, Color val) {
    896         return put("color."+colKey, val != null ? ColorHelper.color2html(val, true) : null);
     898        return put(COLOR_PREFIX+colKey, val != null ? ColorHelper.color2html(val, true) : null);
    897899    }
    898900
     
    15321534    private void migrateOldColorKeys() {
    15331535        settingsMap.keySet().stream()
    1534                 .filter(key -> key.startsWith("color."))
     1536                .filter(key -> key.startsWith(COLOR_PREFIX))
    15351537                .flatMap(key -> {
    1536                     final String newKey = ColorProperty.getColorKey(key.substring("color.".length()));
     1538                    final String newKey = ColorProperty.getColorKey(key.substring(COLOR_PREFIX.length()));
    15371539                    return key.equals(newKey) || settingsMap.containsKey(newKey)
    15381540                            ? Stream.empty()
Note: See TracChangeset for help on using the changeset viewer.