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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.