Changeset 13764 in josm for trunk/src


Ignore:
Timestamp:
2018-05-14T01:43:54+02:00 (6 years ago)
Author:
Don-vip
Message:

add OsmData interface, abstraction of DataSet

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  
    246246     * Fires a commands change event after adding a command.
    247247     * @param cmd command added
     248     * @since 13729
    248249     */
    249250    public void afterAdd(Command cmd) {
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r13559 r13764  
    2828import org.openstreetmap.josm.data.APIDataSet.APIOperation;
    2929import org.openstreetmap.josm.data.Bounds;
    30 import org.openstreetmap.josm.data.Data;
    3130import org.openstreetmap.josm.data.DataSource;
    3231import org.openstreetmap.josm.data.ProjectionBounds;
     
    104103 * @author imi
    105104 */
    106 public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener, Lockable {
     105public final class DataSet implements OsmData<OsmPrimitive, Node, Way, Relation>, ProjectionChangeListener, Lockable {
    107106
    108107    /**
     
    115114     */
    116115    private static final int MAX_EVENTS = 1000;
     116
     117    private final QuadBucketPrimitiveStore<Node, Way, Relation> store = new QuadBucketPrimitiveStore<>();
    117118
    118119    private final Storage<OsmPrimitive> allPrimitives = new Storage<>(new Storage.PrimitiveIdHash(), true);
     
    273274    }
    274275
    275     /**
    276      * Returns the lock used for reading.
    277      * @return the lock used for reading
    278      */
     276    @Override
    279277    public Lock getReadLock() {
    280278        return lock.readLock();
     
    307305    private String version;
    308306
    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
    314308    public String getVersion() {
    315309        return version;
     
    327321    }
    328322
    329     /**
    330      * Get the download policy.
    331      * @return the download policy
    332      * @see #setDownloadPolicy(DownloadPolicy)
    333      * @since 13453
    334      */
     323    @Override
    335324    public DownloadPolicy getDownloadPolicy() {
    336325        return this.downloadPolicy;
    337326    }
    338327
    339     /**
    340      * Sets the download policy.
    341      * @param downloadPolicy the download policy
    342      * @see #getUploadPolicy()
    343      * @since 13453
    344      */
     328    @Override
    345329    public void setDownloadPolicy(DownloadPolicy downloadPolicy) {
    346330        this.downloadPolicy = downloadPolicy;
    347331    }
    348332
    349     /**
    350      * Get the upload policy.
    351      * @return the upload policy
    352      * @see #setUploadPolicy(UploadPolicy)
    353      */
     333    @Override
    354334    public UploadPolicy getUploadPolicy() {
    355335        return this.uploadPolicy;
    356336    }
    357337
    358     /**
    359      * Sets the upload policy.
    360      * @param uploadPolicy the upload policy
    361      * @see #getUploadPolicy()
    362      */
     338    @Override
    363339    public void setUploadPolicy(UploadPolicy uploadPolicy) {
    364340        this.uploadPolicy = uploadPolicy;
     
    389365    }
    390366
    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
    398368    public <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<? super OsmPrimitive> predicate) {
    399369        return new SubclassFilteredCollection<>(allPrimitives, predicate);
    400370    }
    401371
    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
    407373    public Collection<Node> getNodes() {
    408374        return getPrimitives(Node.class::isInstance);
     
    413379        lock.readLock().lock();
    414380        try {
    415             return super.searchNodes(bbox);
     381            return store.searchNodes(bbox);
    416382        } finally {
    417383            lock.readLock().unlock();
     
    419385    }
    420386
    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
    426388    public Collection<Way> getWays() {
    427389        return getPrimitives(Way.class::isInstance);
     
    432394        lock.readLock().lock();
    433395        try {
    434             return super.searchWays(bbox);
     396            return store.searchWays(bbox);
    435397        } finally {
    436398            lock.readLock().unlock();
     
    438400    }
    439401
    440     /**
    441      * Searches for relations in the given bounding box.
    442      * @param bbox the bounding box
    443      * @return List of relations in the given bbox. Can be empty but not null
    444      */
    445402    @Override
    446403    public List<Relation> searchRelations(BBox bbox) {
    447404        lock.readLock().lock();
    448405        try {
    449             return super.searchRelations(bbox);
     406            return store.searchRelations(bbox);
    450407        } finally {
    451408            lock.readLock().unlock();
     
    453410    }
    454411
    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
    460413    public Collection<Relation> getRelations() {
    461414        return getPrimitives(Relation.class::isInstance);
     
    463416
    464417    /**
    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);
    519454    }
    520455
     
    539474            primitive.setDataset(this);
    540475            primitive.updatePosition(); // Set cached bbox for way and relation (required for reindexWay and reindexRelation to work properly)
    541             super.addPrimitive(primitive);
     476            store.addPrimitive(primitive);
    542477            firePrimitivesAdded(Collections.singletonList(primitive), false);
    543478        } finally {
     
    549484     * Removes a primitive from the dataset. This method only removes the
    550485     * primitive form the respective collection of primitives managed
    551      * by this dataset, i.e. from {@link #nodes}, {@link #ways}, or
    552      * {@link #relations}. References from other primitives to this
     486     * by this dataset, i.e. from {@code store.nodes}, {@code store.ways}, or
     487     * {@code store.relations}. References from other primitives to this
    553488     * primitive are left unchanged.
    554489     *
     
    575510            throw new DataIntegrityProblemException("Primitive was re-selected by a selection listener: " + primitive);
    576511        }
    577         super.removePrimitive(primitive);
     512        store.removePrimitive(primitive);
    578513        allPrimitives.remove(primitive);
    579514        primitive.setDataset(null);
    580515    }
    581516
    582     @Override
    583517    protected void removePrimitive(OsmPrimitive primitive) {
    584518        checkModifiable();
     
    596530     *---------------------------------------------------*/
    597531
    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
    606533    public void addSelectionListener(DataSelectionListener listener) {
    607534        selectionListeners.addListener(listener);
    608535    }
    609536
    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
    615538    public void removeSelectionListener(DataSelectionListener listener) {
    616539        selectionListeners.removeListener(listener);
     
    663586    }
    664587
    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
    672589    public Collection<WaySegment> getHighlightedVirtualNodes() {
    673590        return Collections.unmodifiableCollection(highlightedVirtualNodes);
    674591    }
    675592
    676     /**
    677      * Returns an unmodifiable collection of WaySegments that should be highlighted.
    678      *
    679      * @return unmodifiable collection of WaySegments
    680      */
     593    @Override
    681594    public Collection<WaySegment> getHighlightedWaySegments() {
    682595        return Collections.unmodifiableCollection(highlightedWaySegments);
    683596    }
    684597
    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
    690599    public void addHighlightUpdateListener(HighlightUpdateListener listener) {
    691600        highlightUpdateListeners.addListener(listener);
    692601    }
    693602
    694     /**
    695      * Removes a listener that was added with {@link #addHighlightUpdateListener(HighlightUpdateListener)}
    696      * @param listener The Listener
    697      * @since 12014
    698      */
     603    @Override
    699604    public void removeHighlightUpdateListener(HighlightUpdateListener listener) {
    700605        highlightUpdateListeners.removeListener(listener);
    701606    }
    702607
    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
    711609    public Collection<OsmPrimitive> getSelected() {
    712610        return new SubclassFilteredCollection<>(getAllSelected(), p -> !p.isDeleted());
    713611    }
    714612
    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
    723614    public Collection<OsmPrimitive> getAllSelected() {
    724615        return currentSelectedPrimitives;
    725616    }
    726617
    727     /**
    728      * Returns selected nodes.
    729      * @return selected nodes
    730      */
     618    @Override
    731619    public Collection<Node> getSelectedNodes() {
    732620        return new SubclassFilteredCollection<>(getSelected(), Node.class::isInstance);
    733621    }
    734622
    735     /**
    736      * Returns selected ways.
    737      * @return selected ways
    738      */
     623    @Override
    739624    public Collection<Way> getSelectedWays() {
    740625        return new SubclassFilteredCollection<>(getSelected(), Way.class::isInstance);
    741626    }
    742627
    743     /**
    744      * Returns selected relations.
    745      * @return selected relations
    746      */
     628    @Override
    747629    public Collection<Relation> getSelectedRelations() {
    748630        return new SubclassFilteredCollection<>(getSelected(), Relation.class::isInstance);
    749631    }
    750632
    751     /**
    752      * Determines whether the selection is empty or not
    753      * @return whether the selection is empty or not
    754      */
     633    @Override
    755634    public boolean selectionEmpty() {
    756635        return currentSelectedPrimitives.isEmpty();
    757636    }
    758637
    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
    764639    public boolean isSelected(OsmPrimitive osm) {
    765640        return currentSelectedPrimitives.contains(osm);
    766641    }
    767642
    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
    774644    public void setHighlightedVirtualNodes(Collection<WaySegment> waySegments) {
    775645        if (highlightedVirtualNodes.isEmpty() && waySegments.isEmpty())
     
    780650    }
    781651
    782     /**
    783      * set what virtual ways should be highlighted.
    784      * @param waySegments Collection of way segments
    785      */
     652    @Override
    786653    public void setHighlightedWaySegments(Collection<WaySegment> waySegments) {
    787654        if (highlightedWaySegments.isEmpty() && waySegments.isEmpty())
     
    792659    }
    793660
    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
    800662    public void setSelected(Collection<? extends PrimitiveId> selection) {
    801663        setSelected(selection.stream());
    802664    }
    803665
    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
    810667    public void setSelected(PrimitiveId... osm) {
    811668        setSelected(Stream.of(osm).filter(Objects::nonNull));
     
    817674    }
    818675
    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
    825677    public void addSelected(Collection<? extends PrimitiveId> selection) {
    826678        addSelected(selection.stream());
    827679    }
    828680
    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
    835682    public void addSelected(PrimitiveId... osm) {
    836683        addSelected(Stream.of(osm));
     
    842689    }
    843690
    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
    848692    public void clearSelection(PrimitiveId... osm) {
    849693        clearSelection(Stream.of(osm));
    850694    }
    851695
    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
    856697    public void clearSelection(Collection<? extends PrimitiveId> list) {
    857698        clearSelection(list.stream());
    858699    }
    859700
    860     /**
    861      * Clears the current selection.
    862      */
     701    @Override
    863702    public void clearSelection() {
    864703        setSelected(Stream.empty());
     
    870709    }
    871710
    872     /**
    873      * Toggles the selected state of the given collection of primitives.
    874      * @param osm The primitives to toggle
    875      */
     711    @Override
    876712    public void toggleSelected(Collection<? extends PrimitiveId> osm) {
    877713        toggleSelected(osm.stream());
    878714    }
    879715
    880     /**
    881      * Toggles the selected state of the given collection of primitives.
    882      * @param osm The primitives to toggle
    883      */
     716    @Override
    884717    public void toggleSelected(PrimitiveId... osm) {
    885718        toggleSelected(Stream.of(osm));
     
    911744    }
    912745
    913     /**
    914      * clear all highlights of virtual nodes
    915      */
     746    @Override
    916747    public void clearHighlightedVirtualNodes() {
    917748        setHighlightedVirtualNodes(new ArrayList<WaySegment>());
    918749    }
    919750
    920     /**
    921      * clear all highlights of way segments
    922      */
     751    @Override
    923752    public void clearHighlightedWaySegments() {
    924753        setHighlightedWaySegments(new ArrayList<WaySegment>());
     
    928757    public synchronized Area getDataSourceArea() {
    929758        if (cachedDataSourceArea == null) {
    930             cachedDataSourceArea = Data.super.getDataSourceArea();
     759            cachedDataSourceArea = OsmData.super.getDataSourceArea();
    931760        }
    932761        return cachedDataSourceArea;
     
    936765    public synchronized List<Bounds> getDataSourceBounds() {
    937766        if (cachedDataSourceBounds == null) {
    938             cachedDataSourceBounds = Data.super.getDataSourceBounds();
     767            cachedDataSourceBounds = OsmData.super.getDataSourceBounds();
    939768        }
    940769        return Collections.unmodifiableList(cachedDataSourceBounds);
     
    946775    }
    947776
    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 &lt; 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
    956778    public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type) {
    957779        return getPrimitiveById(new SimplePrimitiveId(id, type));
    958780    }
    959781
    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 &lt; 0 for newly created primitives
    964      * @return the primitive
    965      */
     782    @Override
    966783    public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId) {
    967784        return primitiveId != null ? primitivesMap.get(primitiveId) : null;
     
    1078895    }
    1079896
    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
    1087898    public boolean isModified() {
    1088899        for (OsmPrimitive p : allPrimitives) {
     
    12161027
    12171028    void fireRelationMembersChanged(Relation r) {
    1218         reindexRelation(r);
     1029        store.reindexRelation(r, Relation::updatePosition);
    12191030        fireEvent(new RelationMembersChangedEvent(this, r));
    12201031    }
    12211032
    12221033    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);
    12241035        fireEvent(new NodeMovedEvent(this, node));
    12251036    }
    12261037
    12271038    void fireWayNodesChanged(Way way) {
    1228         reindexWay(way);
     1039        store.reindexWay(way, Way::updatePosition, Relation::updatePosition);
    12291040        fireEvent(new WayNodesChangedEvent(this, way));
    12301041    }
     
    13021113                primitive.setDataset(null);
    13031114            }
    1304             super.clear();
     1115            store.clear();
    13051116            allPrimitives.clear();
    13061117        } finally {
     
    13651176    }
    13661177
    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
    13721179    public String getName() {
    13731180        return name;
    13741181    }
    13751182
    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
    13811184    public void setName(String name) {
    13821185        this.name = name;
     
    13911194    }
    13921195
    1393     /**
    1394      * Returns the data sources bounding box.
    1395      * @return the data sources bounding box
    1396      */
     1196    @Override
    13971197    public synchronized ProjectionBounds getDataSourceBoundingBox() {
    13981198        BoundingXYVisitor bbox = new BoundingXYVisitor();
     
    14181218    }
    14191219
    1420     /**
    1421      * Clear the mappaint cache for this DataSet.
    1422      * @since 13420
    1423      */
     1220    @Override
    14241221    public void clearMappaintCache() {
    14251222        mappaintCacheIdx++;
  • trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java

    r13667 r13764  
    33
    44import java.util.Date;
     5import java.util.List;
    56
    67import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
     
    115116     */
    116117    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() {
    117127        return false;
    118128    }
     
    385395     */
    386396    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();
    387411}
  • trunk/src/org/openstreetmap/josm/data/osm/NodeData.java

    r13669 r13764  
    101101
    102102    @Override
     103    public BBox getBBox() {
     104        return new BBox(lon, lat);
     105    }
     106
     107    @Override
    103108    public boolean isReferredByWays(int n) {
    104109        return false;
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r13669 r13764  
    471471    }
    472472
    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
    478474    public boolean isPreserved() {
    479475        return (flags & FLAG_PRESERVED) != 0;
     
    990986    }
    991987
    992     /**
    993      * Gets a list of all primitives in the current dataset that reference this primitive.
    994      * @return The referrers
    995      */
     988    @Override
    996989    public final List<OsmPrimitive> getReferrers() {
    997990        return getReferrers(false);
     
    12131206
    12141207    /**
    1215      * Fetch the bounding box of the primitive
    1216      * @return Bounding box of the object
    1217      */
    1218     public abstract BBox getBBox();
    1219 
    1220     /**
    12211208     * Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...)
    12221209     */
  • trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java

    r13664 r13764  
    99import java.util.Arrays;
    1010import java.util.Collection;
     11import java.util.Collections;
    1112import java.util.List;
    1213import java.util.Map;
     
    164165
    165166    @Override
     167    public final List<PrimitiveData> getReferrers() {
     168        return Collections.emptyList();
     169    }
     170
     171    @Override
    166172    public StyleCache getCachedStyle() {
    167173        return null;
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBucketPrimitiveStore.java

    r12049 r13764  
    55import java.util.Collection;
    66import java.util.List;
     7import java.util.function.Consumer;
    78import java.util.stream.Collectors;
    89
    9 import org.openstreetmap.josm.data.coor.EastNorth;
    10 import org.openstreetmap.josm.data.coor.LatLon;
    1110import org.openstreetmap.josm.tools.JosmRuntimeException;
    1211
     
    1615 * This class does not do any synchronization.
    1716 * @author Michael Zangl
     17 * @param <N> type representing OSM nodes
     18 * @param <W> type representing OSM ways
     19 * @param <R> type representing OSM relations
    1820 * @since 12048
    1921 */
    20 public class QuadBucketPrimitiveStore {
     22public class QuadBucketPrimitiveStore<N extends INode, W extends IWay<N>, R extends IRelation> {
    2123    /**
    2224     * All nodes goes here, even when included in other data (ways etc). This enables the instant
    2325     * conversion of the whole DataSet by iterating over this data structure.
    2426     */
    25     private final QuadBuckets<Node> nodes = new QuadBuckets<>();
     27    private final QuadBuckets<N> nodes = new QuadBuckets<>();
    2628
    2729    /**
     
    3032     * The way nodes are stored only in the way list.
    3133     */
    32     private final QuadBuckets<Way> ways = new QuadBuckets<>();
     34    private final QuadBuckets<W> ways = new QuadBuckets<>();
    3335
    3436    /**
    3537     * All relations/relationships
    3638     */
    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    }
    3846
    3947    /**
     
    4250     * @return List of nodes in the given bbox. Can be empty but not null
    4351     */
    44     public List<Node> searchNodes(BBox bbox) {
     52    public List<N> searchNodes(BBox bbox) {
    4553        return nodes.search(bbox);
    4654    }
    4755
    4856    /**
    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.
    5258     * @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) {
    5762        return nodes.contains(n);
    5863    }
     
    6368     * @return List of ways in the given bbox. Can be empty but not null
    6469     */
    65     public List<Way> searchWays(BBox bbox) {
     70    public List<W> searchWays(BBox bbox) {
    6671        return ways.search(bbox);
    6772    }
    6873
    6974    /**
    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.
    7376     * @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) {
    7880        return ways.contains(w);
    7981    }
     
    8486     * @return List of relations in the given bbox. Can be empty but not null
    8587     */
    86     public List<Relation> searchRelations(BBox bbox) {
     88    public List<R> searchRelations(BBox bbox) {
    8789        // QuadBuckets might be useful here (don't forget to do reindexing after some of rm is changed)
    8890        return relations.stream()
     
    9294
    9395    /**
    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.
    9797     * @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) {
    102101        return relations.contains(r);
    103102    }
     
    108107     * @param primitive the primitive.
    109108     */
    110     public void addPrimitive(OsmPrimitive primitive) {
     109    @SuppressWarnings("unchecked")
     110    public void addPrimitive(IPrimitive primitive) {
    111111        boolean success = false;
    112         if (primitive instanceof Node) {
    113             success = nodes.add((Node) primitive);
    114         } else if (primitive instanceof Way) {
    115             success = ways.add((Way) primitive);
    116         } else if (primitive instanceof Relation) {
    117             success = relations.add((Relation) 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);
    118118        }
    119119        if (!success) {
     
    122122    }
    123123
    124     protected void removePrimitive(OsmPrimitive primitive) {
     124    protected void removePrimitive(IPrimitive primitive) {
    125125        boolean success = false;
    126         if (primitive instanceof Node) {
     126        if (primitive instanceof INode) {
    127127            success = nodes.remove(primitive);
    128         } else if (primitive instanceof Way) {
     128        } else if (primitive instanceof IWay) {
    129129            success = ways.remove(primitive);
    130         } else if (primitive instanceof Relation) {
     130        } else if (primitive instanceof IRelation) {
    131131            success = relations.remove(primitive);
    132132        }
     
    137137
    138138    /**
    139      * Re-index the relation after it's position was changed.
     139     * Re-index the node after it's position was changed.
    140140     * @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) {
    145147        if (!nodes.remove(node))
    146148            throw new JosmRuntimeException("Reindexing node failed to remove");
    147         node.setCoorInternal(newCoor, eastNorth);
     149        nUpdater.accept(node);
    148150        if (!nodes.add(node))
    149151            throw new JosmRuntimeException("Reindexing node failed to add");
    150         for (OsmPrimitive primitive: node.getReferrers()) {
    151             if (primitive instanceof Way) {
    152                 reindexWay((Way) primitive);
     152        for (IPrimitive primitive: node.getReferrers()) {
     153            if (primitive instanceof IWay) {
     154                reindexWay((W) primitive, wUpdater, rUpdater);
    153155            } else {
    154                 reindexRelation((Relation) primitive);
     156                reindexRelation((R) primitive, rUpdater);
    155157            }
    156158        }
     
    160162     * Re-index the way after it's position was changed.
    161163     * @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) {
    164169        BBox before = way.getBBox();
    165170        if (!ways.remove(way))
    166171            throw new JosmRuntimeException("Reindexing way failed to remove");
    167         way.updatePosition();
     172        wUpdater.accept(way);
    168173        if (!ways.add(way))
    169174            throw new JosmRuntimeException("Reindexing way failed to add");
    170175        if (!way.getBBox().equals(before)) {
    171             for (OsmPrimitive primitive: way.getReferrers()) {
    172                 reindexRelation((Relation) primitive);
     176            for (IPrimitive primitive: way.getReferrers()) {
     177                reindexRelation((R) primitive, rUpdater);
    173178            }
    174179        }
     
    178183     * Re-index the relation after it's position was changed.
    179184     * @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) {
    182189        BBox before = relation.getBBox();
    183         relation.updatePosition();
     190        rUpdater.accept(relation);
    184191        if (!before.equals(relation.getBBox())) {
    185             for (OsmPrimitive primitive: relation.getReferrers()) {
    186                 reindexRelation((Relation) primitive);
     192            for (IPrimitive primitive: relation.getReferrers()) {
     193                reindexRelation((R) primitive, rUpdater);
    187194            }
    188195        }
    189196    }
    190 
    191197
    192198    /**
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java

    r13304 r13764  
    2222 * @since 2165
    2323 */
    24 public class QuadBuckets<T extends OsmPrimitive> implements Collection<T> {
     24public class QuadBuckets<T extends IPrimitive> implements Collection<T> {
    2525    private static final boolean CONSISTENCY_TESTING = false;
    2626    private static final byte NW_INDEX = 1;
     
    3535    private static final int MAX_OBJECTS_PER_NODE = 48;
    3636
    37     static class QBLevel<T extends OsmPrimitive> extends BBox {
     37    static class QBLevel<T extends IPrimitive> extends BBox {
    3838        private final byte level;
    3939        private final byte index;
  • trunk/src/org/openstreetmap/josm/data/osm/RelationData.java

    r12017 r13764  
    9797    }
    9898
     99    @Override
     100    public BBox getBBox() {
     101        throw new UnsupportedOperationException();
     102    }
    99103}
  • trunk/src/org/openstreetmap/josm/data/osm/WayData.java

    r13717 r13764  
    9999    }
    100100
     101    @Override
     102    public BBox getBBox() {
     103        throw new UnsupportedOperationException();
     104    }
    101105}
Note: See TracChangeset for help on using the changeset viewer.