Changeset 9755 in josm
- Timestamp:
- 2016-02-08T00:01:48+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r9717 r9755 72 72 import org.openstreetmap.josm.tools.ColorHelper; 73 73 import org.openstreetmap.josm.tools.I18n; 74 import org.openstreetmap.josm.tools.MultiMap; 74 75 import org.openstreetmap.josm.tools.Utils; 75 76 import org.xml.sax.SAXException; … … 1397 1398 Entry e = (Entry) o; 1398 1399 Object evalue = e.getValue(); 1399 if (evalue instanceof Collection) { 1400 JsonArrayBuilder a = Json.createArrayBuilder(); 1401 for (Object evo: (Collection) evalue) { 1402 a.add(evo.toString()); 1403 } 1404 object.add(e.getKey().toString(), a.build()); 1405 } else { 1406 object.add(e.getKey().toString(), evalue.toString()); 1407 } 1400 object.add(e.getKey().toString(), evalue.toString()); 1408 1401 } 1409 1402 writer.writeObject(object.build()); … … 1420 1413 for (Entry<String, JsonValue> e: object.entrySet()) { 1421 1414 JsonValue value = e.getValue(); 1415 if (value instanceof JsonString) { 1416 // in some cases, when JsonValue.toString() is called, then additional quotation marks are left in value 1417 ret.put(e.getKey(), ((JsonString) value).getString()); 1418 } else { 1419 ret.put(e.getKey(), e.getValue().toString()); 1420 } 1421 } 1422 } 1423 return ret; 1424 } 1425 1426 @SuppressWarnings("rawtypes") 1427 private static String multiMapToJson(MultiMap map) { 1428 StringWriter stringWriter = new StringWriter(); 1429 try (JsonWriter writer = Json.createWriter(stringWriter)) { 1430 JsonObjectBuilder object = Json.createObjectBuilder(); 1431 for (Object o: map.entrySet()) { 1432 Entry e = (Entry) o; 1433 Set evalue = (Set) e.getValue(); 1434 JsonArrayBuilder a = Json.createArrayBuilder(); 1435 for (Object evo: (Collection) evalue) { 1436 a.add(evo.toString()); 1437 } 1438 object.add(e.getKey().toString(), a.build()); 1439 } 1440 writer.writeObject(object.build()); 1441 } 1442 return stringWriter.toString(); 1443 } 1444 1445 @SuppressWarnings({ "rawtypes", "unchecked" }) 1446 private static MultiMap multiMapFromJson(String s) { 1447 MultiMap ret = null; 1448 try (JsonReader reader = Json.createReader(new StringReader(s))) { 1449 JsonObject object = reader.readObject(); 1450 ret = new MultiMap(object.size()); 1451 for (Entry<String, JsonValue> e: object.entrySet()) { 1452 JsonValue value = e.getValue(); 1422 1453 if (value instanceof JsonArray) { 1423 List<String> finalList = new ArrayList<String>();1424 1454 for (JsonString js: ((JsonArray) value).getValuesAs(JsonString.class)) { 1425 finalList.add(js.getString());1455 ret.put(e.getKey(), js.getString()); 1426 1456 } 1427 ret.put(e.getKey(), finalList);1428 1457 } else if (value instanceof JsonString) { 1429 1458 // in some cases, when JsonValue.toString() is called, then additional quotation marks are left in value … … 1475 1504 if (fieldValue instanceof Map) { 1476 1505 hash.put(key, mapToJson((Map) fieldValue)); 1506 } else if (fieldValue instanceof MultiMap) { 1507 hash.put(key, multiMapToJson((MultiMap) fieldValue)); 1477 1508 } else { 1478 1509 hash.put(key, fieldValue.toString()); … … 1539 1570 } else if (f.getType().isAssignableFrom(Map.class)) { 1540 1571 value = mapFromJson(key_value.getValue()); 1572 } else if (f.getType().isAssignableFrom(MultiMap.class)) { 1573 value = multiMapFromJson(key_value.getValue()); 1541 1574 } else 1542 1575 throw new RuntimeException("unsupported preference primitive type"); -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r9658 r9755 13 13 import java.util.Map; 14 14 import java.util.Objects; 15 import java.util.Set; 15 16 import java.util.TreeSet; 16 17 import java.util.regex.Matcher; … … 32 33 import org.openstreetmap.josm.tools.ImageProvider; 33 34 import org.openstreetmap.josm.tools.LanguageInfo; 35 import org.openstreetmap.josm.tools.MultiMap; 34 36 35 37 /** … … 219 221 @pref String icon; 220 222 @pref String description; 221 @pref M ap<String, List<String>> noTileHeaders;222 @pref M ap<String, List<String>> noTileChecksums;223 @pref MultiMap<String, String> noTileHeaders; 224 @pref MultiMap<String, String> noTileChecksums; 223 225 @pref int tileSize = -1; 224 226 @pref Map<String, String> metadataHeaders; … … 279 281 } 280 282 if (i.noTileHeaders != null && !i.noTileHeaders.isEmpty()) { 281 noTileHeaders = i.noTileHeaders;283 noTileHeaders = new MultiMap<>(i.noTileHeaders); 282 284 } 283 285 284 286 if (i.noTileChecksums != null && !i.noTileChecksums.isEmpty()) { 285 noTileChecksums = i.noTileChecksums;287 noTileChecksums = new MultiMap<>(i.noTileChecksums); 286 288 } 287 289 … … 412 414 icon = e.icon; 413 415 if (e.noTileHeaders != null) { 414 noTileHeaders = e.noTileHeaders ;416 noTileHeaders = e.noTileHeaders.toMap(); 415 417 } 416 418 if (e.noTileChecksums != null) { 417 noTileChecksums = e.noTileChecksums ;419 noTileChecksums = e.noTileChecksums.toMap(); 418 420 } 419 421 setTileSize(e.tileSize); … … 978 980 * @since 9613 979 981 */ 980 public void setNoTileHeaders(Map<String, List<String>> noTileHeaders) { 981 this.noTileHeaders = noTileHeaders; 982 } 983 984 @Override 985 public Map<String, List<String>> getNoTileHeaders() { 982 public void setNoTileHeaders(MultiMap<String, String> noTileHeaders) { 983 if (noTileHeaders == null) { 984 this.noTileHeaders = null; 985 } else { 986 this.noTileHeaders = noTileHeaders.toMap(); 987 } 988 } 989 990 @Override 991 public Map<String, Set<String>> getNoTileHeaders() { 986 992 return noTileHeaders; 987 993 } … … 994 1000 * @since 9613 995 1001 */ 996 public void setNoTileChecksums(Map<String, List<String>> noTileChecksums) { 997 this.noTileChecksums = noTileChecksums; 998 } 999 1000 @Override 1001 public Map<String, List<String>> getNoTileChecksums() { 1002 public void setNoTileChecksums(MultiMap<String, String> noTileChecksums) { 1003 if (noTileChecksums == null) { 1004 this.noTileChecksums = null; 1005 } else { 1006 this.noTileChecksums = noTileChecksums.toMap(); 1007 } 1008 } 1009 1010 @Override 1011 public Map<String, Set<String>> getNoTileChecksums() { 1002 1012 return noTileChecksums; 1003 1013 } -
trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
r9658 r9755 23 23 import org.openstreetmap.josm.tools.HttpClient; 24 24 import org.openstreetmap.josm.tools.LanguageInfo; 25 import org.openstreetmap.josm.tools.MultiMap; 25 26 import org.openstreetmap.josm.tools.Utils; 26 27 import org.xml.sax.Attributes; … … 99 100 private String lang; 100 101 private List<String> projections; 101 private M ap<String, List<String>> noTileHeaders;102 private M ap<String, List<String>> noTileChecksums;102 private MultiMap<String, String> noTileHeaders; 103 private MultiMap<String, String> noTileChecksums; 103 104 private Map<String, String> metadataHeaders; 104 105 … … 132 133 skipEntry = false; 133 134 newState = State.ENTRY; 134 noTileHeaders = new HashMap<>();135 noTileChecksums = new HashMap<>();135 noTileHeaders = new MultiMap<>(); 136 noTileChecksums = new MultiMap<>(); 136 137 metadataHeaders = new HashMap<>(); 137 138 } … … 196 197 mirrorEntry = new ImageryInfo(); 197 198 } else if ("no-tile-header".equals(qName)) { 198 String name = atts.getValue("name"); 199 List<String> l; 200 if (noTileHeaders.containsKey(name)) { 201 l = noTileHeaders.get(name); 202 } else { 203 l = new ArrayList<String>(); 204 noTileHeaders.put(atts.getValue("name"), l); 205 } 206 l.add(atts.getValue("value")); 199 noTileHeaders.put(atts.getValue("name"), atts.getValue("value")); 207 200 newState = State.NO_TILE; 208 201 } else if ("no-tile-checksum".equals(qName)) { 209 202 String type = atts.getValue("type"); 210 List<String> l; 211 if (noTileChecksums.containsKey(type)) { 212 l = noTileChecksums.get(type); 213 } else { 214 l = new ArrayList<String>(); 215 noTileChecksums.put(type, l); 216 } 217 l.add(atts.getValue("value")); 203 noTileChecksums.put(atts.getValue("type"), atts.getValue("value")); 218 204 newState = State.NO_TILESUM; 219 205 } else if ("metadata-header".equals(qName)) { -
trunk/src/org/openstreetmap/josm/tools/MultiMap.java
r9371 r9755 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 import java.util.Collections; 6 7 import java.util.HashMap; 7 8 import java.util.LinkedHashSet; … … 43 44 44 45 /** 46 * Constructs a new {@code MultiMap} from an ordinary {@code Map}. 47 * @param map0 the {@code Map} 48 */ 49 public MultiMap(Map<A, Set<B>> map0) { 50 if (map0 == null) { 51 map = new HashMap<>(); 52 } else { 53 map = new HashMap<>(Utils.hashMapInitialCapacity(map0.size())); 54 for (Entry<A, Set<B>> e : map0.entrySet()) { 55 map.put(e.getKey(), new LinkedHashSet<>(e.getValue())); 56 } 57 } 58 } 59 60 /** 45 61 * Map a key to a value. 46 62 * … … 216 232 public int hashCode() { 217 233 return Objects.hash(map); 234 } 235 236 /** 237 * Converts this {@code MultiMap} to a {@code Map} with {@code Set} values. 238 * @return the converted {@code Map} 239 */ 240 public Map<A, Set<B>> toMap() { 241 Map<A, Set<B>> result = new HashMap<>(); 242 for (Entry<A, Set<B>> e : map.entrySet()) { 243 result.put(e.getKey(), Collections.unmodifiableSet(e.getValue())); 244 } 245 return result; 218 246 } 219 247
Note:
See TracChangeset
for help on using the changeset viewer.