Changeset 13764 in josm
- Timestamp:
- 2018-05-14T01:43:54+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r13739 r13764 246 246 * Fires a commands change event after adding a command. 247 247 * @param cmd command added 248 * @since 13729 248 249 */ 249 250 public void afterAdd(Command cmd) { -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r13559 r13764 28 28 import org.openstreetmap.josm.data.APIDataSet.APIOperation; 29 29 import org.openstreetmap.josm.data.Bounds; 30 import org.openstreetmap.josm.data.Data;31 30 import org.openstreetmap.josm.data.DataSource; 32 31 import org.openstreetmap.josm.data.ProjectionBounds; … … 104 103 * @author imi 105 104 */ 106 public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener, Lockable {105 public final class DataSet implements OsmData<OsmPrimitive, Node, Way, Relation>, ProjectionChangeListener, Lockable { 107 106 108 107 /** … … 115 114 */ 116 115 private static final int MAX_EVENTS = 1000; 116 117 private final QuadBucketPrimitiveStore<Node, Way, Relation> store = new QuadBucketPrimitiveStore<>(); 117 118 118 119 private final Storage<OsmPrimitive> allPrimitives = new Storage<>(new Storage.PrimitiveIdHash(), true); … … 273 274 } 274 275 275 /** 276 * Returns the lock used for reading. 277 * @return the lock used for reading 278 */ 276 @Override 279 277 public Lock getReadLock() { 280 278 return lock.readLock(); … … 307 305 private String version; 308 306 309 /** 310 * Replies the API version this dataset was created from. May be null. 311 * 312 * @return the API version this dataset was created from. May be null. 313 */ 307 @Override 314 308 public String getVersion() { 315 309 return version; … … 327 321 } 328 322 329 /** 330 * Get the download policy. 331 * @return the download policy 332 * @see #setDownloadPolicy(DownloadPolicy) 333 * @since 13453 334 */ 323 @Override 335 324 public DownloadPolicy getDownloadPolicy() { 336 325 return this.downloadPolicy; 337 326 } 338 327 339 /** 340 * Sets the download policy. 341 * @param downloadPolicy the download policy 342 * @see #getUploadPolicy() 343 * @since 13453 344 */ 328 @Override 345 329 public void setDownloadPolicy(DownloadPolicy downloadPolicy) { 346 330 this.downloadPolicy = downloadPolicy; 347 331 } 348 332 349 /** 350 * Get the upload policy. 351 * @return the upload policy 352 * @see #setUploadPolicy(UploadPolicy) 353 */ 333 @Override 354 334 public UploadPolicy getUploadPolicy() { 355 335 return this.uploadPolicy; 356 336 } 357 337 358 /** 359 * Sets the upload policy. 360 * @param uploadPolicy the upload policy 361 * @see #getUploadPolicy() 362 */ 338 @Override 363 339 public void setUploadPolicy(UploadPolicy uploadPolicy) { 364 340 this.uploadPolicy = uploadPolicy; … … 389 365 } 390 366 391 /** 392 * Gets a filtered collection of primitives matching the given predicate. 393 * @param <T> The primitive type. 394 * @param predicate The predicate to match 395 * @return The list of primtives. 396 * @since 10590 397 */ 367 @Override 398 368 public <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<? super OsmPrimitive> predicate) { 399 369 return new SubclassFilteredCollection<>(allPrimitives, predicate); 400 370 } 401 371 402 /** 403 * Replies an unmodifiable collection of nodes in this dataset 404 * 405 * @return an unmodifiable collection of nodes in this dataset 406 */ 372 @Override 407 373 public Collection<Node> getNodes() { 408 374 return getPrimitives(Node.class::isInstance); … … 413 379 lock.readLock().lock(); 414 380 try { 415 return s uper.searchNodes(bbox);381 return store.searchNodes(bbox); 416 382 } finally { 417 383 lock.readLock().unlock(); … … 419 385 } 420 386 421 /** 422 * Replies an unmodifiable collection of ways in this dataset 423 * 424 * @return an unmodifiable collection of ways in this dataset 425 */ 387 @Override 426 388 public Collection<Way> getWays() { 427 389 return getPrimitives(Way.class::isInstance); … … 432 394 lock.readLock().lock(); 433 395 try { 434 return s uper.searchWays(bbox);396 return store.searchWays(bbox); 435 397 } finally { 436 398 lock.readLock().unlock(); … … 438 400 } 439 401 440 /**441 * Searches for relations in the given bounding box.442 * @param bbox the bounding box443 * @return List of relations in the given bbox. Can be empty but not null444 */445 402 @Override 446 403 public List<Relation> searchRelations(BBox bbox) { 447 404 lock.readLock().lock(); 448 405 try { 449 return s uper.searchRelations(bbox);406 return store.searchRelations(bbox); 450 407 } finally { 451 408 lock.readLock().unlock(); … … 453 410 } 454 411 455 /** 456 * Replies an unmodifiable collection of relations in this dataset 457 * 458 * @return an unmodifiable collection of relations in this dataset 459 */ 412 @Override 460 413 public Collection<Relation> getRelations() { 461 414 return getPrimitives(Relation.class::isInstance); … … 463 416 464 417 /** 465 * Returns a collection containing all primitives of the dataset. 466 * @return A collection containing all primitives of the dataset. Data is not ordered 467 */ 468 public Collection<OsmPrimitive> allPrimitives() { 469 return getPrimitives(o -> true); 470 } 471 472 /** 473 * Returns a collection containing all not-deleted primitives. 474 * @return A collection containing all not-deleted primitives. 475 * @see OsmPrimitive#isDeleted 476 */ 477 public Collection<OsmPrimitive> allNonDeletedPrimitives() { 478 return getPrimitives(p -> !p.isDeleted()); 479 } 480 481 /** 482 * Returns a collection containing all not-deleted complete primitives. 483 * @return A collection containing all not-deleted complete primitives. 484 * @see OsmPrimitive#isDeleted 485 * @see OsmPrimitive#isIncomplete 486 */ 487 public Collection<OsmPrimitive> allNonDeletedCompletePrimitives() { 488 return getPrimitives(primitive -> !primitive.isDeleted() && !primitive.isIncomplete()); 489 } 490 491 /** 492 * Returns a collection containing all not-deleted complete physical primitives. 493 * @return A collection containing all not-deleted complete physical primitives (nodes and ways). 494 * @see OsmPrimitive#isDeleted 495 * @see OsmPrimitive#isIncomplete 496 */ 497 public Collection<OsmPrimitive> allNonDeletedPhysicalPrimitives() { 498 return getPrimitives( 499 primitive -> !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation)); 500 } 501 502 /** 503 * Returns a collection containing all modified primitives. 504 * @return A collection containing all modified primitives. 505 * @see OsmPrimitive#isModified 506 */ 507 public Collection<OsmPrimitive> allModifiedPrimitives() { 508 return getPrimitives(OsmPrimitive::isModified); 509 } 510 511 /** 512 * Returns a collection containing all primitives preserved from filtering. 513 * @return A collection containing all primitives preserved from filtering. 514 * @see OsmPrimitive#isPreserved 515 * @since 13309 516 */ 517 public Collection<OsmPrimitive> allPreservedPrimitives() { 518 return getPrimitives(OsmPrimitive::isPreserved); 418 * Determines if the given node can be retrieved in the data set through its bounding box. Useful for dataset consistency test. 419 * For efficiency reasons this method does not lock the dataset, you have to lock it manually. 420 * 421 * @param n The node to search 422 * @return {@code true} if {@code n} can be retrieved in this data set, {@code false} otherwise 423 * @since 7501 424 */ 425 @Override 426 public boolean containsNode(Node n) { 427 return store.containsNode(n); 428 } 429 430 /** 431 * Determines if the given way can be retrieved in the data set through its bounding box. Useful for dataset consistency test. 432 * For efficiency reasons this method does not lock the dataset, you have to lock it manually. 433 * 434 * @param w The way to search 435 * @return {@code true} if {@code w} can be retrieved in this data set, {@code false} otherwise 436 * @since 7501 437 */ 438 @Override 439 public boolean containsWay(Way w) { 440 return store.containsWay(w); 441 } 442 443 /** 444 * Determines if the given relation can be retrieved in the data set through its bounding box. Useful for dataset consistency test. 445 * For efficiency reasons this method does not lock the dataset, you have to lock it manually. 446 * 447 * @param r The relation to search 448 * @return {@code true} if {@code r} can be retrieved in this data set, {@code false} otherwise 449 * @since 7501 450 */ 451 @Override 452 public boolean containsRelation(Relation r) { 453 return store.containsRelation(r); 519 454 } 520 455 … … 539 474 primitive.setDataset(this); 540 475 primitive.updatePosition(); // Set cached bbox for way and relation (required for reindexWay and reindexRelation to work properly) 541 s uper.addPrimitive(primitive);476 store.addPrimitive(primitive); 542 477 firePrimitivesAdded(Collections.singletonList(primitive), false); 543 478 } finally { … … 549 484 * Removes a primitive from the dataset. This method only removes the 550 485 * primitive form the respective collection of primitives managed 551 * by this dataset, i.e. from {@ link #nodes}, {@link #ways}, or552 * {@ link #relations}. References from other primitives to this486 * by this dataset, i.e. from {@code store.nodes}, {@code store.ways}, or 487 * {@code store.relations}. References from other primitives to this 553 488 * primitive are left unchanged. 554 489 * … … 575 510 throw new DataIntegrityProblemException("Primitive was re-selected by a selection listener: " + primitive); 576 511 } 577 s uper.removePrimitive(primitive);512 store.removePrimitive(primitive); 578 513 allPrimitives.remove(primitive); 579 514 primitive.setDataset(null); 580 515 } 581 516 582 @Override583 517 protected void removePrimitive(OsmPrimitive primitive) { 584 518 checkModifiable(); … … 596 530 *---------------------------------------------------*/ 597 531 598 /** 599 * Add a listener that listens to selection changes in this specific data set. 600 * @param listener The listener. 601 * @see #removeSelectionListener(DataSelectionListener) 602 * @see SelectionEventManager#addSelectionListener(SelectionChangedListener, 603 * org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode) 604 * To add a global listener. 605 */ 532 @Override 606 533 public void addSelectionListener(DataSelectionListener listener) { 607 534 selectionListeners.addListener(listener); 608 535 } 609 536 610 /** 611 * Remove a listener that listens to selection changes in this specific data set. 612 * @param listener The listener. 613 * @see #addSelectionListener(DataSelectionListener) 614 */ 537 @Override 615 538 public void removeSelectionListener(DataSelectionListener listener) { 616 539 selectionListeners.removeListener(listener); … … 663 586 } 664 587 665 /** 666 * Returns an unmodifiable collection of *WaySegments* whose virtual 667 * nodes should be highlighted. WaySegments are used to avoid having 668 * to create a VirtualNode class that wouldn't have much purpose otherwise. 669 * 670 * @return unmodifiable collection of WaySegments 671 */ 588 @Override 672 589 public Collection<WaySegment> getHighlightedVirtualNodes() { 673 590 return Collections.unmodifiableCollection(highlightedVirtualNodes); 674 591 } 675 592 676 /** 677 * Returns an unmodifiable collection of WaySegments that should be highlighted. 678 * 679 * @return unmodifiable collection of WaySegments 680 */ 593 @Override 681 594 public Collection<WaySegment> getHighlightedWaySegments() { 682 595 return Collections.unmodifiableCollection(highlightedWaySegments); 683 596 } 684 597 685 /** 686 * Adds a listener that gets notified whenever way segment / virtual nodes highlights change. 687 * @param listener The Listener 688 * @since 12014 689 */ 598 @Override 690 599 public void addHighlightUpdateListener(HighlightUpdateListener listener) { 691 600 highlightUpdateListeners.addListener(listener); 692 601 } 693 602 694 /** 695 * Removes a listener that was added with {@link #addHighlightUpdateListener(HighlightUpdateListener)} 696 * @param listener The Listener 697 * @since 12014 698 */ 603 @Override 699 604 public void removeHighlightUpdateListener(HighlightUpdateListener listener) { 700 605 highlightUpdateListeners.removeListener(listener); 701 606 } 702 607 703 /** 704 * Replies an unmodifiable collection of primitives currently selected 705 * in this dataset, except deleted ones. May be empty, but not null. 706 * 707 * When iterating through the set it is ordered by the order in which the primitives were added to the selection. 708 * 709 * @return unmodifiable collection of primitives 710 */ 608 @Override 711 609 public Collection<OsmPrimitive> getSelected() { 712 610 return new SubclassFilteredCollection<>(getAllSelected(), p -> !p.isDeleted()); 713 611 } 714 612 715 /** 716 * Replies an unmodifiable collection of primitives currently selected 717 * in this dataset, including deleted ones. May be empty, but not null. 718 * 719 * When iterating through the set it is ordered by the order in which the primitives were added to the selection. 720 * 721 * @return unmodifiable collection of primitives 722 */ 613 @Override 723 614 public Collection<OsmPrimitive> getAllSelected() { 724 615 return currentSelectedPrimitives; 725 616 } 726 617 727 /** 728 * Returns selected nodes. 729 * @return selected nodes 730 */ 618 @Override 731 619 public Collection<Node> getSelectedNodes() { 732 620 return new SubclassFilteredCollection<>(getSelected(), Node.class::isInstance); 733 621 } 734 622 735 /** 736 * Returns selected ways. 737 * @return selected ways 738 */ 623 @Override 739 624 public Collection<Way> getSelectedWays() { 740 625 return new SubclassFilteredCollection<>(getSelected(), Way.class::isInstance); 741 626 } 742 627 743 /** 744 * Returns selected relations. 745 * @return selected relations 746 */ 628 @Override 747 629 public Collection<Relation> getSelectedRelations() { 748 630 return new SubclassFilteredCollection<>(getSelected(), Relation.class::isInstance); 749 631 } 750 632 751 /** 752 * Determines whether the selection is empty or not 753 * @return whether the selection is empty or not 754 */ 633 @Override 755 634 public boolean selectionEmpty() { 756 635 return currentSelectedPrimitives.isEmpty(); 757 636 } 758 637 759 /** 760 * Determines whether the given primitive is selected or not 761 * @param osm the primitive 762 * @return whether {@code osm} is selected or not 763 */ 638 @Override 764 639 public boolean isSelected(OsmPrimitive osm) { 765 640 return currentSelectedPrimitives.contains(osm); 766 641 } 767 642 768 /** 769 * set what virtual nodes should be highlighted. Requires a Collection of 770 * *WaySegments* to avoid a VirtualNode class that wouldn't have much use 771 * otherwise. 772 * @param waySegments Collection of way segments 773 */ 643 @Override 774 644 public void setHighlightedVirtualNodes(Collection<WaySegment> waySegments) { 775 645 if (highlightedVirtualNodes.isEmpty() && waySegments.isEmpty()) … … 780 650 } 781 651 782 /** 783 * set what virtual ways should be highlighted. 784 * @param waySegments Collection of way segments 785 */ 652 @Override 786 653 public void setHighlightedWaySegments(Collection<WaySegment> waySegments) { 787 654 if (highlightedWaySegments.isEmpty() && waySegments.isEmpty()) … … 792 659 } 793 660 794 /** 795 * Sets the current selection to the primitives in <code>selection</code> 796 * and notifies all {@link SelectionChangedListener}. 797 * 798 * @param selection the selection 799 */ 661 @Override 800 662 public void setSelected(Collection<? extends PrimitiveId> selection) { 801 663 setSelected(selection.stream()); 802 664 } 803 665 804 /** 805 * Sets the current selection to the primitives in <code>osm</code> 806 * and notifies all {@link SelectionChangedListener}. 807 * 808 * @param osm the primitives to set. <code>null</code> values are ignored for now, but this may be removed in the future. 809 */ 666 @Override 810 667 public void setSelected(PrimitiveId... osm) { 811 668 setSelected(Stream.of(osm).filter(Objects::nonNull)); … … 817 674 } 818 675 819 /** 820 * Adds the primitives in <code>selection</code> to the current selection 821 * and notifies all {@link SelectionChangedListener}. 822 * 823 * @param selection the selection 824 */ 676 @Override 825 677 public void addSelected(Collection<? extends PrimitiveId> selection) { 826 678 addSelected(selection.stream()); 827 679 } 828 680 829 /** 830 * Adds the primitives in <code>osm</code> to the current selection 831 * and notifies all {@link SelectionChangedListener}. 832 * 833 * @param osm the primitives to add 834 */ 681 @Override 835 682 public void addSelected(PrimitiveId... osm) { 836 683 addSelected(Stream.of(osm)); … … 842 689 } 843 690 844 /** 845 * Removes the selection from every value in the collection. 846 * @param osm The collection of ids to remove the selection from. 847 */ 691 @Override 848 692 public void clearSelection(PrimitiveId... osm) { 849 693 clearSelection(Stream.of(osm)); 850 694 } 851 695 852 /** 853 * Removes the selection from every value in the collection. 854 * @param list The collection of ids to remove the selection from. 855 */ 696 @Override 856 697 public void clearSelection(Collection<? extends PrimitiveId> list) { 857 698 clearSelection(list.stream()); 858 699 } 859 700 860 /** 861 * Clears the current selection. 862 */ 701 @Override 863 702 public void clearSelection() { 864 703 setSelected(Stream.empty()); … … 870 709 } 871 710 872 /** 873 * Toggles the selected state of the given collection of primitives. 874 * @param osm The primitives to toggle 875 */ 711 @Override 876 712 public void toggleSelected(Collection<? extends PrimitiveId> osm) { 877 713 toggleSelected(osm.stream()); 878 714 } 879 715 880 /** 881 * Toggles the selected state of the given collection of primitives. 882 * @param osm The primitives to toggle 883 */ 716 @Override 884 717 public void toggleSelected(PrimitiveId... osm) { 885 718 toggleSelected(Stream.of(osm)); … … 911 744 } 912 745 913 /** 914 * clear all highlights of virtual nodes 915 */ 746 @Override 916 747 public void clearHighlightedVirtualNodes() { 917 748 setHighlightedVirtualNodes(new ArrayList<WaySegment>()); 918 749 } 919 750 920 /** 921 * clear all highlights of way segments 922 */ 751 @Override 923 752 public void clearHighlightedWaySegments() { 924 753 setHighlightedWaySegments(new ArrayList<WaySegment>()); … … 928 757 public synchronized Area getDataSourceArea() { 929 758 if (cachedDataSourceArea == null) { 930 cachedDataSourceArea = Data.super.getDataSourceArea();759 cachedDataSourceArea = OsmData.super.getDataSourceArea(); 931 760 } 932 761 return cachedDataSourceArea; … … 936 765 public synchronized List<Bounds> getDataSourceBounds() { 937 766 if (cachedDataSourceBounds == null) { 938 cachedDataSourceBounds = Data.super.getDataSourceBounds();767 cachedDataSourceBounds = OsmData.super.getDataSourceBounds(); 939 768 } 940 769 return Collections.unmodifiableList(cachedDataSourceBounds); … … 946 775 } 947 776 948 /** 949 * Returns a primitive with a given id from the data set. null, if no such primitive exists 950 * 951 * @param id uniqueId of the primitive. Might be < 0 for newly created primitives 952 * @param type the type of the primitive. Must not be null. 953 * @return the primitive 954 * @throws NullPointerException if type is null 955 */ 777 @Override 956 778 public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type) { 957 779 return getPrimitiveById(new SimplePrimitiveId(id, type)); 958 780 } 959 781 960 /** 961 * Returns a primitive with a given id from the data set. null, if no such primitive exists 962 * 963 * @param primitiveId type and uniqueId of the primitive. Might be < 0 for newly created primitives 964 * @return the primitive 965 */ 782 @Override 966 783 public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId) { 967 784 return primitiveId != null ? primitivesMap.get(primitiveId) : null; … … 1078 895 } 1079 896 1080 /** 1081 * Replies true if there is at least one primitive in this dataset with 1082 * {@link OsmPrimitive#isModified()} == <code>true</code>. 1083 * 1084 * @return true if there is at least one primitive in this dataset with 1085 * {@link OsmPrimitive#isModified()} == <code>true</code>. 1086 */ 897 @Override 1087 898 public boolean isModified() { 1088 899 for (OsmPrimitive p : allPrimitives) { … … 1216 1027 1217 1028 void fireRelationMembersChanged(Relation r) { 1218 reindexRelation(r);1029 store.reindexRelation(r, Relation::updatePosition); 1219 1030 fireEvent(new RelationMembersChangedEvent(this, r)); 1220 1031 } 1221 1032 1222 1033 void fireNodeMoved(Node node, LatLon newCoor, EastNorth eastNorth) { 1223 reindexNode(node, newCoor, eastNorth);1034 store.reindexNode(node, n -> n.setCoorInternal(newCoor, eastNorth), Way::updatePosition, Relation::updatePosition); 1224 1035 fireEvent(new NodeMovedEvent(this, node)); 1225 1036 } 1226 1037 1227 1038 void fireWayNodesChanged(Way way) { 1228 reindexWay(way);1039 store.reindexWay(way, Way::updatePosition, Relation::updatePosition); 1229 1040 fireEvent(new WayNodesChangedEvent(this, way)); 1230 1041 } … … 1302 1113 primitive.setDataset(null); 1303 1114 } 1304 s uper.clear();1115 store.clear(); 1305 1116 allPrimitives.clear(); 1306 1117 } finally { … … 1365 1176 } 1366 1177 1367 /** 1368 * Returns the name of this data set (optional). 1369 * @return the name of this data set. Can be {@code null} 1370 * @since 12718 1371 */ 1178 @Override 1372 1179 public String getName() { 1373 1180 return name; 1374 1181 } 1375 1182 1376 /** 1377 * Sets the name of this data set. 1378 * @param name the new name of this data set. Can be {@code null} to reset it 1379 * @since 12718 1380 */ 1183 @Override 1381 1184 public void setName(String name) { 1382 1185 this.name = name; … … 1391 1194 } 1392 1195 1393 /** 1394 * Returns the data sources bounding box. 1395 * @return the data sources bounding box 1396 */ 1196 @Override 1397 1197 public synchronized ProjectionBounds getDataSourceBoundingBox() { 1398 1198 BoundingXYVisitor bbox = new BoundingXYVisitor(); … … 1418 1218 } 1419 1219 1420 /** 1421 * Clear the mappaint cache for this DataSet. 1422 * @since 13420 1423 */ 1220 @Override 1424 1221 public void clearMappaintCache() { 1425 1222 mappaintCacheIdx++; -
trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java
r13667 r13764 3 3 4 4 import java.util.Date; 5 import java.util.List; 5 6 6 7 import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor; … … 115 116 */ 116 117 default boolean isDisabledAndHidden() { 118 return false; 119 } 120 121 /** 122 * Replies true, if this primitive is preserved from filtering. 123 * @return {@code true} if this object has the "preserved" flag enabled 124 * @since 13764 125 */ 126 default boolean isPreserved() { 117 127 return false; 118 128 } … … 385 395 */ 386 396 boolean reversedDirection(); 397 398 /** 399 * Fetches the bounding box of the primitive. 400 * @return Bounding box of the object 401 * @since 13764 402 */ 403 BBox getBBox(); 404 405 /** 406 * Gets a list of all primitives in the current dataset that reference this primitive. 407 * @return The referrers 408 * @since 13764 409 */ 410 List<? extends IPrimitive> getReferrers(); 387 411 } -
trunk/src/org/openstreetmap/josm/data/osm/NodeData.java
r13669 r13764 101 101 102 102 @Override 103 public BBox getBBox() { 104 return new BBox(lon, lat); 105 } 106 107 @Override 103 108 public boolean isReferredByWays(int n) { 104 109 return false; -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r13669 r13764 471 471 } 472 472 473 /** 474 * Replies true, if this primitive is preserved from filtering. 475 * @return {@code true} if this object has the "preserved" flag enabled 476 * @since 13309 477 */ 473 @Override 478 474 public boolean isPreserved() { 479 475 return (flags & FLAG_PRESERVED) != 0; … … 990 986 } 991 987 992 /** 993 * Gets a list of all primitives in the current dataset that reference this primitive. 994 * @return The referrers 995 */ 988 @Override 996 989 public final List<OsmPrimitive> getReferrers() { 997 990 return getReferrers(false); … … 1213 1206 1214 1207 /** 1215 * Fetch the bounding box of the primitive1216 * @return Bounding box of the object1217 */1218 public abstract BBox getBBox();1219 1220 /**1221 1208 * Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...) 1222 1209 */ -
trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java
r13664 r13764 9 9 import java.util.Arrays; 10 10 import java.util.Collection; 11 import java.util.Collections; 11 12 import java.util.List; 12 13 import java.util.Map; … … 164 165 165 166 @Override 167 public final List<PrimitiveData> getReferrers() { 168 return Collections.emptyList(); 169 } 170 171 @Override 166 172 public StyleCache getCachedStyle() { 167 173 return null; -
trunk/src/org/openstreetmap/josm/data/osm/QuadBucketPrimitiveStore.java
r12049 r13764 5 5 import java.util.Collection; 6 6 import java.util.List; 7 import java.util.function.Consumer; 7 8 import java.util.stream.Collectors; 8 9 9 import org.openstreetmap.josm.data.coor.EastNorth;10 import org.openstreetmap.josm.data.coor.LatLon;11 10 import org.openstreetmap.josm.tools.JosmRuntimeException; 12 11 … … 16 15 * This class does not do any synchronization. 17 16 * @author Michael Zangl 17 * @param <N> type representing OSM nodes 18 * @param <W> type representing OSM ways 19 * @param <R> type representing OSM relations 18 20 * @since 12048 19 21 */ 20 public class QuadBucketPrimitiveStore {22 public class QuadBucketPrimitiveStore<N extends INode, W extends IWay<N>, R extends IRelation> { 21 23 /** 22 24 * All nodes goes here, even when included in other data (ways etc). This enables the instant 23 25 * conversion of the whole DataSet by iterating over this data structure. 24 26 */ 25 private final QuadBuckets<N ode> nodes = new QuadBuckets<>();27 private final QuadBuckets<N> nodes = new QuadBuckets<>(); 26 28 27 29 /** … … 30 32 * The way nodes are stored only in the way list. 31 33 */ 32 private final QuadBuckets<W ay> ways = new QuadBuckets<>();34 private final QuadBuckets<W> ways = new QuadBuckets<>(); 33 35 34 36 /** 35 37 * All relations/relationships 36 38 */ 37 private final Collection<Relation> relations = new ArrayList<>(); 39 private final Collection<R> relations = new ArrayList<>(); 40 41 /** 42 * Constructs a new {@code QuadBucketPrimitiveStore}. 43 */ 44 public QuadBucketPrimitiveStore() { 45 } 38 46 39 47 /** … … 42 50 * @return List of nodes in the given bbox. Can be empty but not null 43 51 */ 44 public List<N ode> searchNodes(BBox bbox) {52 public List<N> searchNodes(BBox bbox) { 45 53 return nodes.search(bbox); 46 54 } 47 55 48 56 /** 49 * Determines if the given node can be retrieved in the data set through its bounding box. Useful for dataset consistency test. 50 * For efficiency reasons this method does not lock the dataset, you have to lock it manually. 51 * 57 * Determines if the given node can be retrieved in the store through its bounding box. Useful for dataset consistency test. 52 58 * @param n The node to search 53 * @return {@code true} if {@code n} ban be retrieved in this data set, {@code false} otherwise 54 * @since 7501 55 */ 56 public boolean containsNode(Node n) { 59 * @return {@code true} if {@code n} can be retrieved in this store, {@code false} otherwise 60 */ 61 public boolean containsNode(N n) { 57 62 return nodes.contains(n); 58 63 } … … 63 68 * @return List of ways in the given bbox. Can be empty but not null 64 69 */ 65 public List<W ay> searchWays(BBox bbox) {70 public List<W> searchWays(BBox bbox) { 66 71 return ways.search(bbox); 67 72 } 68 73 69 74 /** 70 * Determines if the given way can be retrieved in the data set through its bounding box. Useful for dataset consistency test. 71 * For efficiency reasons this method does not lock the dataset, you have to lock it manually. 72 * 75 * Determines if the given way can be retrieved in the store through its bounding box. Useful for dataset consistency test. 73 76 * @param w The way to search 74 * @return {@code true} if {@code w} ban be retrieved in this data set, {@code false} otherwise 75 * @since 7501 76 */ 77 public boolean containsWay(Way w) { 77 * @return {@code true} if {@code w} can be retrieved in this store, {@code false} otherwise 78 */ 79 public boolean containsWay(W w) { 78 80 return ways.contains(w); 79 81 } … … 84 86 * @return List of relations in the given bbox. Can be empty but not null 85 87 */ 86 public List<R elation> searchRelations(BBox bbox) {88 public List<R> searchRelations(BBox bbox) { 87 89 // QuadBuckets might be useful here (don't forget to do reindexing after some of rm is changed) 88 90 return relations.stream() … … 92 94 93 95 /** 94 * Determines if the given relation can be retrieved in the data set through its bounding box. Useful for dataset consistency test. 95 * For efficiency reasons this method does not lock the dataset, you have to lock it manually. 96 * 96 * Determines if the given relation can be retrieved in the store through its bounding box. Useful for dataset consistency test. 97 97 * @param r The relation to search 98 * @return {@code true} if {@code r} ban be retrieved in this data set, {@code false} otherwise 99 * @since 7501 100 */ 101 public boolean containsRelation(Relation r) { 98 * @return {@code true} if {@code r} can be retrieved in this store, {@code false} otherwise 99 */ 100 public boolean containsRelation(R r) { 102 101 return relations.contains(r); 103 102 } … … 108 107 * @param primitive the primitive. 109 108 */ 110 public void addPrimitive(OsmPrimitive primitive) { 109 @SuppressWarnings("unchecked") 110 public void addPrimitive(IPrimitive primitive) { 111 111 boolean success = false; 112 if (primitive instanceof Node) {113 success = nodes.add((N ode) primitive);114 } else if (primitive instanceof Way) {115 success = ways.add((W ay) primitive);116 } else if (primitive instanceof Relation) {117 success = relations.add((R elation) primitive);112 if (primitive instanceof INode) { 113 success = nodes.add((N) primitive); 114 } else if (primitive instanceof IWay) { 115 success = ways.add((W) primitive); 116 } else if (primitive instanceof IRelation) { 117 success = relations.add((R) primitive); 118 118 } 119 119 if (!success) { … … 122 122 } 123 123 124 protected void removePrimitive( OsmPrimitive primitive) {124 protected void removePrimitive(IPrimitive primitive) { 125 125 boolean success = false; 126 if (primitive instanceof Node) {126 if (primitive instanceof INode) { 127 127 success = nodes.remove(primitive); 128 } else if (primitive instanceof Way) {128 } else if (primitive instanceof IWay) { 129 129 success = ways.remove(primitive); 130 } else if (primitive instanceof Relation) {130 } else if (primitive instanceof IRelation) { 131 131 success = relations.remove(primitive); 132 132 } … … 137 137 138 138 /** 139 * Re-index the relationafter it's position was changed.139 * Re-index the node after it's position was changed. 140 140 * @param node The node to re-index 141 * @param newCoor The new coordinates 142 * @param eastNorth The new east/north position 143 */ 144 protected void reindexNode(Node node, LatLon newCoor, EastNorth eastNorth) { 141 * @param nUpdater update node position 142 * @param wUpdater update way position 143 * @param rUpdater update relation position 144 */ 145 @SuppressWarnings("unchecked") 146 protected void reindexNode(N node, Consumer<N> nUpdater, Consumer<W> wUpdater, Consumer<R> rUpdater) { 145 147 if (!nodes.remove(node)) 146 148 throw new JosmRuntimeException("Reindexing node failed to remove"); 147 n ode.setCoorInternal(newCoor, eastNorth);149 nUpdater.accept(node); 148 150 if (!nodes.add(node)) 149 151 throw new JosmRuntimeException("Reindexing node failed to add"); 150 for ( OsmPrimitive primitive: node.getReferrers()) {151 if (primitive instanceof Way) {152 reindexWay((W ay) primitive);152 for (IPrimitive primitive: node.getReferrers()) { 153 if (primitive instanceof IWay) { 154 reindexWay((W) primitive, wUpdater, rUpdater); 153 155 } else { 154 reindexRelation((R elation) primitive);156 reindexRelation((R) primitive, rUpdater); 155 157 } 156 158 } … … 160 162 * Re-index the way after it's position was changed. 161 163 * @param way The way to re-index 162 */ 163 protected void reindexWay(Way way) { 164 * @param wUpdater update way position 165 * @param rUpdater update relation position 166 */ 167 @SuppressWarnings("unchecked") 168 protected void reindexWay(W way, Consumer<W> wUpdater, Consumer<R> rUpdater) { 164 169 BBox before = way.getBBox(); 165 170 if (!ways.remove(way)) 166 171 throw new JosmRuntimeException("Reindexing way failed to remove"); 167 w ay.updatePosition();172 wUpdater.accept(way); 168 173 if (!ways.add(way)) 169 174 throw new JosmRuntimeException("Reindexing way failed to add"); 170 175 if (!way.getBBox().equals(before)) { 171 for ( OsmPrimitive primitive: way.getReferrers()) {172 reindexRelation((R elation) primitive);176 for (IPrimitive primitive: way.getReferrers()) { 177 reindexRelation((R) primitive, rUpdater); 173 178 } 174 179 } … … 178 183 * Re-index the relation after it's position was changed. 179 184 * @param relation The relation to re-index 180 */ 181 protected static void reindexRelation(Relation relation) { 185 * @param rUpdater update relation position 186 */ 187 @SuppressWarnings("unchecked") 188 protected void reindexRelation(R relation, Consumer<R> rUpdater) { 182 189 BBox before = relation.getBBox(); 183 r elation.updatePosition();190 rUpdater.accept(relation); 184 191 if (!before.equals(relation.getBBox())) { 185 for ( OsmPrimitive primitive: relation.getReferrers()) {186 reindexRelation((R elation) primitive);192 for (IPrimitive primitive: relation.getReferrers()) { 193 reindexRelation((R) primitive, rUpdater); 187 194 } 188 195 } 189 196 } 190 191 197 192 198 /** -
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r13304 r13764 22 22 * @since 2165 23 23 */ 24 public class QuadBuckets<T extends OsmPrimitive> implements Collection<T> {24 public class QuadBuckets<T extends IPrimitive> implements Collection<T> { 25 25 private static final boolean CONSISTENCY_TESTING = false; 26 26 private static final byte NW_INDEX = 1; … … 35 35 private static final int MAX_OBJECTS_PER_NODE = 48; 36 36 37 static class QBLevel<T extends OsmPrimitive> extends BBox {37 static class QBLevel<T extends IPrimitive> extends BBox { 38 38 private final byte level; 39 39 private final byte index; -
trunk/src/org/openstreetmap/josm/data/osm/RelationData.java
r12017 r13764 97 97 } 98 98 99 @Override 100 public BBox getBBox() { 101 throw new UnsupportedOperationException(); 102 } 99 103 } -
trunk/src/org/openstreetmap/josm/data/osm/WayData.java
r13717 r13764 99 99 } 100 100 101 @Override 102 public BBox getBBox() { 103 throw new UnsupportedOperationException(); 104 } 101 105 }
Note:
See TracChangeset
for help on using the changeset viewer.