Changeset 3547 in josm
- Timestamp:
- 2010-09-19T21:54:08+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r3531 r3547 26 26 import java.util.Map.Entry; 27 27 import java.util.concurrent.CopyOnWriteArrayList; 28 import java.util.regex.Matcher;29 import java.util.regex.Pattern;30 28 31 29 import javax.swing.JOptionPane; … … 205 203 synchronized public Map<String, String> getAllPrefix(final String prefix) { 206 204 final Map<String,String> all = new TreeMap<String,String>(); 207 for (final Entry<String,String> e : properties.entrySet()) 205 for (final Entry<String,String> e : properties.entrySet()) { 208 206 if (e.getKey().startsWith(prefix)) { 209 207 all.put(e.getKey(), e.getValue()); 210 208 } 209 } 211 210 return all; 212 211 } … … 214 213 synchronized private Map<String, String> getAllPrefixDefault(final String prefix) { 215 214 final Map<String,String> all = new TreeMap<String,String>(); 216 for (final Entry<String,String> e : defaults.entrySet()) 215 for (final Entry<String,String> e : defaults.entrySet()) { 217 216 if (e.getKey().startsWith(prefix)) { 218 217 all.put(e.getKey(), e.getValue()); 219 218 } 219 } 220 220 return all; 221 221 } … … 223 223 synchronized public TreeMap<String, String> getAllColors() { 224 224 final TreeMap<String,String> all = new TreeMap<String,String>(); 225 for (final Entry<String,String> e : defaults.entrySet()) 225 for (final Entry<String,String> e : defaults.entrySet()) { 226 226 if (e.getKey().startsWith("color.") && e.getValue() != null) { 227 227 all.put(e.getKey().substring(6), e.getValue()); 228 228 } 229 for (final Entry<String,String> e : properties.entrySet()) 229 } 230 for (final Entry<String,String> e : properties.entrySet()) { 230 231 if (e.getKey().startsWith("color.")) { 231 232 all.put(e.getKey().substring(6), e.getValue()); 232 233 } 234 } 233 235 return all; 234 236 } … … 579 581 return def; 580 582 } 583 581 584 synchronized public void removeFromCollection(String key, String value) { 582 585 List<String> a = new ArrayList<String>(getCollection(key, Collections.<String>emptyList())); … … 584 587 putCollection(key, a); 585 588 } 589 586 590 synchronized public boolean putCollection(String key, Collection<String> val) { 587 591 String s = null; … … 590 594 for(String a : val) 591 595 { 596 if (a == null) { 597 a = ""; 598 } 592 599 if(s != null) { 593 600 s += "\u001e" + a; … … 599 606 return put(key, s); 600 607 } 608 601 609 synchronized private void putCollectionDefault(String key, Collection<String> val) { 602 610 String s = null; … … 611 619 putDefault(key, s); 612 620 } 621 613 622 synchronized public Collection<Collection<String>> getArray(String key, 614 623 Collection<Collection<String>> def) { … … 618 627 int num = 0; 619 628 Collection<Collection<String>> col = new LinkedList<Collection<String>>(); 620 while(properties.containsKey(key+num)) 629 while(properties.containsKey(key+num)) { 621 630 col.add(getCollection(key+num++, null)); 631 } 622 632 return num == 0 && def != null ? def : col; 623 633 } 634 624 635 synchronized public boolean putArray(String key, Collection<Collection<String>> val) { 625 boolean res = true;636 boolean changed = false; 626 637 key += "."; 627 638 Collection<String> keys = getAllPrefix(key).keySet(); … … 630 641 for(Collection<String> c : val) { 631 642 keys.remove(key+num); 632 if(!putCollection(key+num++, c)) 633 res = false; 643 changed |= putCollection(key+num++, c); 634 644 } 635 645 } … … 638 648 try { 639 649 Integer.valueOf(k.substring(l)); 640 put(k, null); 641 } catch(Exception e) { 642 } 643 } 644 return res; 650 changed |= put(k, null); 651 } catch(NumberFormatException e) { 652 System.err.println("Warning: invalid preference."); 653 e.printStackTrace(); 654 } 655 } 656 return changed; 645 657 } 646 658
Note:
See TracChangeset
for help on using the changeset viewer.