Changeset 17095 in josm
- Timestamp:
- 2020-10-07T19:44:55+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
r16913 r17095 11 11 import java.util.Map; 12 12 import java.util.Objects; 13 import java.util.Optional; 13 14 import java.util.Stack; 14 15 import java.util.concurrent.ConcurrentHashMap; … … 28 29 import org.openstreetmap.josm.tools.Logging; 29 30 import org.openstreetmap.josm.tools.MultiMap; 31 import org.openstreetmap.josm.tools.StringParser; 30 32 import org.openstreetmap.josm.tools.Utils; 31 33 import org.openstreetmap.josm.tools.XmlUtils; … … 362 364 switch(qName) { 363 365 case "type": 364 boolean found = false; 365 for (ImageryType type : ImageryType.values()) { 366 if (Objects.equals(accumulator.toString(), type.getTypeString())) { 367 mirrorEntry.setImageryType(type); 368 found = true; 369 break; 370 } 371 } 372 if (!found) { 366 Optional<ImageryType> type = Arrays.stream(ImageryType.values()) 367 .filter(t -> Objects.equals(accumulator.toString(), t.getTypeString())) 368 .findFirst(); 369 if (type.isPresent()) { 370 mirrorEntry.setImageryType(type.get()); 371 } else { 373 372 mirrorEntry = null; 374 373 } … … 385 384 case MIN_ZOOM: 386 385 case MAX_ZOOM: 387 Integer val = null; 388 try { 389 val = Integer.valueOf(accumulator.toString()); 390 } catch (NumberFormatException e) { 391 val = null; 392 } 393 if (val == null) { 386 Optional<Integer> zoom = tryParseInt(); 387 if (!zoom.isPresent()) { 394 388 mirrorEntry = null; 395 389 } else { 396 390 if (MIN_ZOOM.equals(qName)) { 397 mirrorEntry.setDefaultMinZoom( val);391 mirrorEntry.setDefaultMinZoom(zoom.get()); 398 392 } else { 399 mirrorEntry.setDefaultMaxZoom( val);393 mirrorEntry.setDefaultMaxZoom(zoom.get()); 400 394 } 401 395 } 402 396 break; 403 397 case TILE_SIZE: 404 Integer tileSize = null; 405 try { 406 tileSize = Integer.valueOf(accumulator.toString()); 407 } catch (NumberFormatException e) { 408 tileSize = null; 409 } 410 if (tileSize == null) { 398 Optional<Integer> tileSize = tryParseInt(); 399 if (!tileSize.isPresent()) { 411 400 mirrorEntry = null; 412 401 } else { 413 entry.setTileSize(tileSize. intValue());402 entry.setTileSize(tileSize.get()); 414 403 } 415 404 break; … … 462 451 case MIN_ZOOM: 463 452 case MAX_ZOOM: 464 Integer val = null; 465 try { 466 val = Integer.valueOf(accumulator.toString()); 467 } catch (NumberFormatException e) { 468 val = null; 469 } 470 if (val == null) { 453 Optional<Integer> zoom = tryParseInt(); 454 if (!zoom.isPresent()) { 471 455 skipEntry = true; 472 456 } else { 473 457 if (MIN_ZOOM.equals(qName)) { 474 entry.setDefaultMinZoom( val);458 entry.setDefaultMinZoom(zoom.get()); 475 459 } else { 476 entry.setDefaultMaxZoom( val);460 entry.setDefaultMaxZoom(zoom.get()); 477 461 } 478 462 } … … 509 493 break; 510 494 case TILE_SIZE: 511 Integer tileSize = null; 512 try { 513 tileSize = Integer.valueOf(accumulator.toString()); 514 } catch (NumberFormatException e) { 515 tileSize = null; 516 } 517 if (tileSize == null) { 495 Optional<Integer> tileSize = tryParseInt(); 496 if (!tileSize.isPresent()) { 518 497 skipEntry = true; 519 498 } else { 520 entry.setTileSize(tileSize. intValue());499 entry.setTileSize(tileSize.get()); 521 500 } 522 501 break; … … 573 552 private ImageryBounds intern(ImageryBounds imageryBounds) { 574 553 return boundsInterner.computeIfAbsent(imageryBounds, ignore -> imageryBounds); 554 } 555 556 private Optional<Integer> tryParseInt() { 557 return StringParser.DEFAULT.tryParse(Integer.class, accumulator.toString()); 575 558 } 576 559 }
Note:
See TracChangeset
for help on using the changeset viewer.