Ignore:
Timestamp:
2010-12-10T10:15:21+01:00 (13 years ago)
Author:
bastiK
Message:

new list of recently opened files; little preference rework

File:
1 edited

Legend:

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

    r3709 r3710  
    631631    }
    632632
     633    /**
     634     * Get a list of values for a certain key
     635     * @param key the identifier for the setting
     636     * @return the corresponding value if the property has been set before,
     637     *  an empty Collection otherwise.
     638     */
     639    synchronized public Collection<String> getCollection(String key) {
     640        putCollectionDefault(key, null);
     641        String s = get(key);
     642        if (s != null && s.length() != 0)
     643            return Arrays.asList(s.split("\u001e"));
     644        return Collections.emptyList();
     645    }
     646
    633647    synchronized public void removeFromCollection(String key, String value) {
    634648        List<String> a = new ArrayList<String>(getCollection(key, Collections.<String>emptyList()));
     
    638652
    639653    synchronized public boolean putCollection(String key, Collection<String> val) {
    640         String s = null;
    641         if(val != null)
    642         {
    643             for(String a : val)
    644             {
    645                 if (a == null) {
    646                     a = "";
    647                 }
    648                 if(s != null) {
    649                     s += "\u001e" + a;
    650                 } else {
    651                     s = a;
    652                 }
    653             }
    654         }
    655         return put(key, s);
     654        return put(key, join("\u001e", val));
    656655    }
    657656   
    658657    synchronized private void putCollectionDefault(String key, Collection<String> val) {
    659         if (val == null) {
    660             putDefault(key, null);
    661         } else {
    662             String s = null;
    663             for(String a : val)
    664             {
    665                 if(s != null) {
    666                     s += "\u001e" + a;
    667                 } else {
    668                     s = a;
    669                 }
    670             }
    671             putDefault(key, s);
    672         }
     658        putDefault(key, join("\u001e", val));
    673659    }
    674660   
     
    766752    }
    767753
     754    /**
     755     * Joins a collection of strings into a single string with fields
     756     * separated by the value of sep.
     757     * @param sep the separator
     758     * @param values collection of strings, null strings are converted to the
     759     *  empty string
     760     * @return null if values is null. The joined string otherwise.
     761     */
     762    public static String join(String sep, Collection<?> values) {
     763        if (values == null)
     764            return null;
     765        if (values.isEmpty())
     766            return "";
     767        StringBuilder s = null;
     768        for (Object a : values) {
     769            if (a == null) {
     770                a = "";
     771            }
     772            if(s != null) {
     773                s.append(sep).append(a.toString());
     774            } else {
     775                s = new StringBuilder(a.toString());
     776            }
     777        }
     778        return s.toString();
     779    }
     780
    768781}
Note: See TracChangeset for help on using the changeset viewer.