Changeset 14147 in josm


Ignore:
Timestamp:
2018-08-12T15:16:18+02:00 (8 months ago)
Author:
Don-vip
Message:

see #15229 - code refactoring - move getAllPrefix* methods from Preferences to AbstractPreferences

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r14145 r14147  
    2121import java.util.HashSet;
    2222import java.util.Iterator;
    23 import java.util.LinkedList;
    24 import java.util.List;
    2523import java.util.Map;
    2624import java.util.Map.Entry;
     
    4846import org.openstreetmap.josm.spi.preferences.ListSetting;
    4947import org.openstreetmap.josm.spi.preferences.Setting;
    50 import org.openstreetmap.josm.spi.preferences.StringSetting;
    5148import org.openstreetmap.josm.tools.CheckParameterUtil;
    5249import org.openstreetmap.josm.tools.ListenerList;
     
    286283
    287284    /**
    288      * Gets all normal (string) settings that have a key starting with the prefix
    289      * @param prefix The start of the key
    290      * @return The key names of the settings
    291      */
    292     public synchronized Map<String, String> getAllPrefix(final String prefix) {
    293         final Map<String, String> all = new TreeMap<>();
    294         for (final Entry<String, Setting<?>> e : settingsMap.entrySet()) {
    295             if (e.getKey().startsWith(prefix) && (e.getValue() instanceof StringSetting)) {
    296                 all.put(e.getKey(), ((StringSetting) e.getValue()).getValue());
    297             }
    298         }
    299         return all;
    300     }
    301 
    302     /**
    303      * Gets all list settings that have a key starting with the prefix
    304      * @param prefix The start of the key
    305      * @return The key names of the list settings
    306      */
    307     public synchronized List<String> getAllPrefixCollectionKeys(final String prefix) {
    308         final List<String> all = new LinkedList<>();
    309         for (Map.Entry<String, Setting<?>> entry : settingsMap.entrySet()) {
    310             if (entry.getKey().startsWith(prefix) && entry.getValue() instanceof ListSetting) {
    311                 all.add(entry.getKey());
    312             }
    313         }
    314         return all;
    315     }
    316 
    317     /**
    318285     * Get all named colors, including customized and the default ones.
    319286     * @return a map of all named colors (maps preference key to {@link ColorInfo})
  • trunk/src/org/openstreetmap/josm/spi/preferences/AbstractPreferences.java

    r14122 r14147  
    22package org.openstreetmap.josm.spi.preferences;
    33
     4import java.util.LinkedList;
    45import java.util.List;
    56import java.util.Map;
     7import java.util.Map.Entry;
     8import java.util.TreeMap;
    69
    710import org.openstreetmap.josm.tools.Logging;
     
    148151     */
    149152    public abstract <T extends Setting<?>> T getSetting(String key, T def, Class<T> klass);
     153
     154    /**
     155     * Gets all normal (string) settings that have a key starting with the prefix
     156     * @param prefix The start of the key
     157     * @return The key names of the settings
     158     */
     159    public Map<String, String> getAllPrefix(String prefix) {
     160        final Map<String, String> all = new TreeMap<>();
     161        for (final Entry<String, Setting<?>> e : getAllSettings().entrySet()) {
     162            if (e.getKey().startsWith(prefix) && (e.getValue() instanceof StringSetting)) {
     163                all.put(e.getKey(), ((StringSetting) e.getValue()).getValue());
     164            }
     165        }
     166        return all;
     167    }
     168
     169    /**
     170     * Gets all list settings that have a key starting with the prefix
     171     * @param prefix The start of the key
     172     * @return The key names of the list settings
     173     */
     174    public List<String> getAllPrefixCollectionKeys(String prefix) {
     175        final List<String> all = new LinkedList<>();
     176        for (Entry<String, Setting<?>> entry : getAllSettings().entrySet()) {
     177            if (entry.getKey().startsWith(prefix) && entry.getValue() instanceof ListSetting) {
     178                all.add(entry.getKey());
     179            }
     180        }
     181        return all;
     182    }
    150183}
Note: See TracChangeset for help on using the changeset viewer.