Changeset 4634 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 04.12.2011 19:17:56 (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r4614 r4634 65 65 * accessed using one of the get...() methods. You can use the same preference 66 66 * key in different parts of the code, but the default value must be the same 67 * everywhere. null is a legitimate default value. 67 * everywhere. A default value of null means, the setting has been requested, but 68 * no default value was set. This is used in advanced preferences to present a list 69 * off all possible settings. 68 70 * 69 71 * At the moment, there is no such thing as an empty value. … … 99 101 T getValue(); 100 102 void visit(SettingVisitor visitor); 103 Setting<T> getNullInstance(); 101 104 } 102 105 … … 118 121 visitor.visit(this); 119 122 } 123 public StringSetting getNullInstance() { 124 return new StringSetting(null); 125 } 120 126 } 121 127 … … 127 133 visitor.visit(this); 128 134 } 135 public ListSetting getNullInstance() { 136 return new ListSetting(null); 137 } 129 138 } 130 139 … … 136 145 visitor.visit(this); 137 146 } 147 public ListListSetting getNullInstance() { 148 return new ListListSetting(null); 149 } 138 150 } 139 151 … … 144 156 public void visit(SettingVisitor visitor) { 145 157 visitor.visit(this); 158 } 159 public MapListSetting getNullInstance() { 160 return new MapListSetting(null); 146 161 } 147 162 } … … 825 840 */ 826 841 public Collection<String> getCollection(String key, Collection<String> def) { 827 if (def != null) { 828 putCollectionDefault(key, new ArrayList<String>(def)); 829 } 842 putCollectionDefault(key, def == null ? null : new ArrayList<String>(def)); 830 843 Collection<String> prop = getCollectionInternal(key); 831 844 if (prop != null) … … 904 917 } 905 918 906 p rivatestatic boolean equalCollection(Collection<String> a, Collection<String> b) {919 public static boolean equalCollection(Collection<String> a, Collection<String> b) { 907 920 if (a == null) return b == null; 908 921 if (b == null) return false; … … 947 960 } 948 961 putArrayDefault(key, Collections.unmodifiableList(defCopy)); 962 } else { 963 putArrayDefault(key, null); 949 964 } 950 965 List<List<String>> prop = getArrayInternal(key); … … 955 970 } else 956 971 return def; 972 } 973 974 public Collection<Collection<String>> getArray(String key) { 975 putArrayDefault(key, null); 976 List<List<String>> prop = getArrayInternal(key); 977 if (prop != null) { 978 @SuppressWarnings("unchecked") 979 Collection<Collection<String>> prop_cast = (Collection) prop; 980 return prop_cast; 981 } else 982 return Collections.emptyList(); 957 983 } 958 984 … … 1020 1046 } 1021 1047 1022 p rivatestatic boolean equalArray(Collection<Collection<String>> a, Collection<List<String>> b) {1048 public static boolean equalArray(Collection<Collection<String>> a, Collection<List<String>> b) { 1023 1049 if (a == null) return b == null; 1024 1050 if (b == null) return false; … … 1043 1069 } 1044 1070 putListOfStructsDefault(key, Collections.unmodifiableList(defCopy)); 1071 } else { 1072 putListOfStructsDefault(key, null); 1045 1073 } 1046 1074 Collection<Map<String, String>> prop = getListOfStructsInternal(key); … … 1117 1145 } 1118 1146 1119 p rivatestatic boolean equalListOfStructs(Collection<Map<String, String>> a, Collection<Map<String, String>> b) {1147 public static boolean equalListOfStructs(Collection<Map<String, String>> a, Collection<Map<String, String>> b) { 1120 1148 if (a == null) return b == null; 1121 1149 if (b == null) return false; … … 1298 1326 } 1299 1327 return struct; 1328 } 1329 1330 public boolean putSetting(final String key, Setting value) { 1331 if (value == null) return false; 1332 class PutVisitor implements SettingVisitor { 1333 public boolean changed; 1334 public void visit(StringSetting setting) { 1335 changed = put(key, setting.getValue()); 1336 } 1337 public void visit(ListSetting setting) { 1338 changed = putCollection(key, setting.getValue()); 1339 } 1340 public void visit(ListListSetting setting) { 1341 changed = putArray(key, (Collection) setting.getValue()); 1342 } 1343 public void visit(MapListSetting setting) { 1344 changed = putListOfStructs(key, setting.getValue()); 1345 } 1346 }; 1347 PutVisitor putVisitor = new PutVisitor(); 1348 value.visit(putVisitor); 1349 return putVisitor.changed; 1350 } 1351 1352 public Map<String, Setting> getAllSettings() { 1353 Map<String, Setting> settings = new TreeMap<String, Setting>(); 1354 1355 for (Entry<String, String> e : properties.entrySet()) { 1356 settings.put(e.getKey(), new StringSetting(e.getValue())); 1357 } 1358 for (Entry<String, List<String>> e : collectionProperties.entrySet()) { 1359 settings.put(e.getKey(), new ListSetting(e.getValue())); 1360 } 1361 for (Entry<String, List<List<String>>> e : arrayProperties.entrySet()) { 1362 settings.put(e.getKey(), new ListListSetting(e.getValue())); 1363 } 1364 for (Entry<String, List<Map<String, String>>> e : listOfStructsProperties.entrySet()) { 1365 settings.put(e.getKey(), new MapListSetting(e.getValue())); 1366 } 1367 return settings; 1368 } 1369 1370 public Map<String, Setting> getAllDefaults() { 1371 Map<String, Setting> allDefaults = new TreeMap<String, Setting>(); 1372 1373 for (Entry<String, String> e : defaults.entrySet()) { 1374 allDefaults.put(e.getKey(), new StringSetting(e.getValue())); 1375 } 1376 for (Entry<String, List<String>> e : collectionDefaults.entrySet()) { 1377 allDefaults.put(e.getKey(), new ListSetting(e.getValue())); 1378 } 1379 for (Entry<String, List<List<String>>> e : arrayDefaults.entrySet()) { 1380 allDefaults.put(e.getKey(), new ListListSetting(e.getValue())); 1381 } 1382 for (Entry<String, List<Map<String, String>>> e : listOfStructsDefaults.entrySet()) { 1383 allDefaults.put(e.getKey(), new MapListSetting(e.getValue())); 1384 } 1385 return allDefaults; 1300 1386 } 1301 1387
Note: See TracChangeset
for help on using the changeset viewer.
