Ticket #19061: 19061.patch

File 19061.patch, 51.5 KB (added by taylor.smock, 4 years ago)

Initial WIP patch (very broken, its a work in progress)

  • .classpath

     
    2727                        <attribute name="test" value="true"/>
    2828                </attributes>
    2929        </classpathentry>
    30         <classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=JOSM&amp;ivyXmlPath=ivy.xml&amp;confs=*&amp;ivySettingsPath=ivysettings.xml&amp;loadSettingsOnDemand=false&amp;ivyUserDir=&amp;propertyFiles="/>
     30        <classpathentry exported="true" kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=JOSM&amp;ivyXmlPath=ivy.xml&amp;confs=*&amp;ivySettingsPath=ivysettings.xml&amp;loadSettingsOnDemand=false&amp;ivyUserDir=&amp;propertyFiles="/>
    3131        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
    3232                <attributes>
    3333                        <attribute name="module" value="true"/>
  • josm-latest.jnlp

     
    33<jnlp spec="6.0+" codebase="https://josm.openstreetmap.de/download/" href="josm-latest.jnlp">
    44    <information>
    55        <title>JOSM (development version)</title>
    6         <vendor>OpenStreetMap</vendor> 
    7         <homepage href="https://josm.openstreetmap.de"/> 
     6        <vendor>OpenStreetMap</vendor>
     7        <homepage href="https://josm.openstreetmap.de"/>
    88        <description>Java OpenStreetMap editor</description>
    99        <description kind="one-line">JOSM</description>
    1010        <description kind="tooltip">JOSM</description>
     
    2020        <all-permissions/>
    2121    </security>
    2222    <resources>
    23         <java version="1.8+" max-heap-size="2048m" java-vm-args="--add-modules=java.scripting,java.sql --add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED --add-exports=jdk.deploy/com.sun.deploy.config=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.desktop/javax.imageio.spi=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED"/>
     23        <java version="1.8+" max-heap-size="2048m" java-vm-args="--add-modules=java.scripting,java.sql --add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED --add-exports=jdk.deploy/com.sun.deploy.config=ALL-UNNAMED --add-opens=jdk.swing.interop=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.desktop/javax.imageio.spi=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED"/>
    2424        <jar href="josm-latest.jar"/>
    2525        <property name="java.util.Arrays.useLegacyMergeSort" value="true"/>
    2626    </resources>
  • src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

     
    1111import java.awt.event.KeyEvent;
    1212import java.awt.event.MouseEvent;
    1313import java.awt.geom.Point2D;
     14import java.util.ArrayList;
    1415import java.util.Collection;
    1516import java.util.Collections;
    1617import java.util.HashSet;
     
    3233import org.openstreetmap.josm.data.UndoRedoHandler;
    3334import org.openstreetmap.josm.data.coor.EastNorth;
    3435import org.openstreetmap.josm.data.osm.DataSet;
    35 import org.openstreetmap.josm.data.osm.Node;
     36import org.openstreetmap.josm.data.osm.INode;
     37import org.openstreetmap.josm.data.osm.IPrimitive;
     38import org.openstreetmap.josm.data.osm.IWay;
    3639import org.openstreetmap.josm.data.osm.OsmData;
    3740import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3841import org.openstreetmap.josm.data.osm.Way;
     
    183186     * to remove the highlight from them again as otherwise the whole data
    184187     * set would have to be checked.
    185188     */
    186     private transient Optional<OsmPrimitive> currentHighlight = Optional.empty();
     189    private transient Optional<IPrimitive> currentHighlight = Optional.empty();
    187190
    188191    /**
    189192     * Create a new SelectAction
     
    257260     * @return {@code true} if repaint is required
    258261     */
    259262    private boolean giveUserFeedback(MouseEvent e, int modifiers) {
    260         Optional<OsmPrimitive> c = Optional.ofNullable(
     263        Optional<IPrimitive> c = Optional.ofNullable(
    261264                mv.getNearestNodeOrWay(e.getPoint(), mv.isSelectablePredicate, true));
    262265
    263266        updateKeyModifiersEx(modifiers);
    264267        determineMapMode(c.isPresent());
    265268
    266         Optional<OsmPrimitive> newHighlight = Optional.empty();
     269        Optional<IPrimitive> newHighlight = Optional.empty();
    267270
    268271        virtualManager.clear();
    269272        if (mode == Mode.MOVE && !dragInProgress() && virtualManager.activateVirtualNodeNearPoint(e.getPoint())) {
     
    300303     * @param nearbyStuff primitives near the cursor
    301304     * @return the cursor that should be displayed
    302305     */
    303     private Cursor getCursor(OsmPrimitive nearbyStuff) {
     306    private Cursor getCursor(IPrimitive nearbyStuff) {
    304307        String c = "rect";
    305308        switch(mode) {
    306309        case MOVE:
     
    308311                c = "virtual_node";
    309312                break;
    310313            }
    311             final OsmPrimitive osm = nearbyStuff;
     314            final IPrimitive osm = nearbyStuff;
    312315
    313316            if (dragInProgress()) {
    314317                // only consider merge if ctrl is pressed and there are nodes in
     
    319322                }
    320323                // only show merge to node cursor if nearby node and that node is currently
    321324                // not being dragged
    322                 final boolean hasTarget = osm instanceof Node && !osm.isSelected();
     325                final boolean hasTarget = osm instanceof INode && !osm.isSelected();
    323326                c = hasTarget ? "merge_to_node" : "merge";
    324327                break;
    325328            }
    326329
    327             c = (osm instanceof Node) ? "node" : c;
    328             c = (osm instanceof Way) ? "way" : c;
     330            c = (osm instanceof INode) ? "node" : c;
     331            c = (osm instanceof IWay) ? "way" : c;
    329332            if (shift) {
    330333                c += "_add";
    331334            } else if (ctrl) {
     
    369372        return true;
    370373    }
    371374
    372     private boolean repaintIfRequired(Optional<OsmPrimitive> newHighlight) {
     375    private boolean repaintIfRequired(Optional<IPrimitive> newHighlight) {
    373376        if (!drawTargetHighlight || currentHighlight.equals(newHighlight))
    374377            return false;
    375378        currentHighlight.ifPresent(osm -> osm.setHighlighted(false));
     
    413416
    414417        // primitives under cursor are stored in c collection
    415418
    416         OsmPrimitive nearestPrimitive = mv.getNearestNodeOrWay(e.getPoint(), mv.isSelectablePredicate, true);
     419        IPrimitive nearestPrimitive = mv.getNearestNodeOrWay(e.getPoint(), mv.isSelectablePredicate, true);
    417420
    418421        determineMapMode(nearestPrimitive != null);
    419422
     
    437440            if (!cancelDrawMode && nearestPrimitive instanceof Way) {
    438441                virtualManager.activateVirtualNodeNearPoint(e.getPoint());
    439442            }
    440             OsmPrimitive toSelect = cycleManager.cycleSetup(nearestPrimitive, e.getPoint());
     443            IPrimitive toSelect = cycleManager.cycleSetup(nearestPrimitive, e.getPoint());
    441444            selectPrims(asColl(toSelect), false, false);
    442445            useLastMoveCommandIfPossible();
    443446            // Schedule a timer to update status line "initialMoveDelay+1" ms in the future
     
    510513            // If ctrl is pressed we are in merge mode. Look for a nearby node,
    511514            // highlight it and adjust the cursor accordingly.
    512515            final boolean canMerge = ctrl && !getLayerManager().getEditDataSet().getSelectedNodes().isEmpty();
    513             final OsmPrimitive p = canMerge ? findNodeToMergeTo(e.getPoint()) : null;
     516            final IPrimitive p = canMerge ? findNodeToMergeTo(e.getPoint()) : null;
    514517            boolean needsRepaint = removeHighlighting();
    515518            if (p != null) {
    516519                p.setHighlighted(true);
     
    603606                    selectPrims(cycleManager.cyclePrims(), true, false);
    604607
    605608                    // If the user double-clicked a node, change to draw mode
    606                     Collection<OsmPrimitive> c = ds.getSelected();
    607                     if (e.getClickCount() >= 2 && c.size() == 1 && c.iterator().next() instanceof Node) {
     609                    Collection<IPrimitive> c = new ArrayList<>(ds.getSelected());
     610                    if (e.getClickCount() >= 2 && c.size() == 1 && c.iterator().next() instanceof INode) {
    608611                        // We need to do it like this as otherwise drawAction will see a double
    609612                        // click and switch back to SelectMode
    610613                        MainApplication.worker.execute(() -> map.selectDrawTool(true));
     
    698701        // Currently we support only transformations which do not affect relations.
    699702        // So don't add them in the first place to make handling easier
    700703        DataSet ds = getLayerManager().getEditDataSet();
    701         Collection<OsmPrimitive> selection = ds.getSelectedNodesAndWays();
     704        Collection<IPrimitive> selection = new ArrayList<>(ds.getSelectedNodesAndWays());
    702705        if (selection.isEmpty()) { // if nothing was selected to drag, just select nearest node/way to the cursor
    703706            ds.setSelected(mv.getNearestNodeOrWay(mv.getPoint(startEN), mv.isSelectablePredicate, true));
    704707        }
    705708
    706         Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
     709        Collection<INode> affectedNodes = new ArrayList<>(AllNodesVisitor.getAllNodes(selection));
    707710        // for these transformations, having only one node makes no sense - quit silently
    708711        if (affectedNodes.size() < 2 && (mode == Mode.ROTATE || mode == Mode.SCALE)) {
    709712            return false;
     
    721724                    moveCmd = new MoveCommand(selection, startEN, currentEN);
    722725                    UndoRedoHandler.getInstance().add(moveCmd);
    723726                }
    724                 for (Node n : affectedNodes) {
     727                for (INode n : affectedNodes) {
    725728                    if (n.isOutSideWorld()) {
    726729                        // Revert move
    727730                        if (moveCmd != null) {
     
    770773        }
    771774    }
    772775
    773     private static boolean doesImpactStatusLine(Collection<Node> affectedNodes, Collection<Way> selectedWays) {
    774         for (Way w : selectedWays) {
    775             for (Node n : w.getNodes()) {
     776    private static boolean doesImpactStatusLine(Collection<INode> affectedNodes, Collection<IWay<?>> selectedWays) {
     777        for (IWay<?> w : selectedWays) {
     778            for (INode n : w.getNodes()) {
    776779                if (affectedNodes.contains(n)) {
    777780                    return true;
    778781                }
     
    791794            return;
    792795        }
    793796        Command c = getLastCommandInDataset(dataSet);
    794         Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(dataSet.getSelected());
     797        Collection<? extends INode> affectedNodes = AllNodesVisitor.getAllNodes(dataSet.getSelected());
    795798        if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) {
    796799            // old command was created with different base point of movement, we need to recalculate it
    797800            ((MoveCommand) c).changeStartPoint(startEN);
     
    830833            ed.toggleEnable("movedHiddenElements");
    831834            showConfirmMoveDialog(ed);
    832835        }
    833         Set<Node> nodes = new HashSet<>();
     836        Set<INode> nodes = new HashSet<>();
    834837        int max = Config.getPref().getInt("warn.move.maxelements", 20);
    835         for (OsmPrimitive osm : getLayerManager().getEditDataSet().getSelected()) {
    836             if (osm instanceof Way) {
    837                 nodes.addAll(((Way) osm).getNodes());
    838             } else if (osm instanceof Node) {
    839                 nodes.add((Node) osm);
     838        for (IPrimitive osm : getLayerManager().getEditDataSet().getSelected()) {
     839            if (osm instanceof IWay) {
     840                nodes.addAll(((IWay<?>) osm).getNodes());
     841            } else if (osm instanceof INode) {
     842                nodes.add((INode) osm);
    840843            }
    841844            if (nodes.size() > max) {
    842845                break;
     
    929932     * @param nodes the collection of nodes. Ignored if null
    930933     * @param targetLocationNode this node's location will be used for the target node
    931934     */
    932     public void mergeNodes(OsmDataLayer layer, Collection<Node> nodes,
    933                            Node targetLocationNode) {
     935    public void mergeNodes(OsmDataLayer layer, Collection<INode> nodes,
     936                           INode targetLocationNode) {
    934937        MergeNodesAction.doMergeNodes(layer, nodes, targetLocationNode);
    935938    }
    936939
     
    940943     * @param p mouse position
    941944     * @return node to merge to, or null
    942945     */
    943     private Node findNodeToMergeTo(Point p) {
    944         Collection<Node> target = mv.getNearestNodes(p,
    945                 getLayerManager().getEditDataSet().getSelectedNodes(),
     946    private INode findNodeToMergeTo(Point p) {
     947        Collection<INode> target = mv.getNearestNodes(p,
     948                new ArrayList<>(getLayerManager().getEditDataSet().getSelectedNodes()),
    946949                mv.isSelectablePredicate);
    947950        return target.isEmpty() ? null : target.iterator().next();
    948951    }
    949952
    950     private void selectPrims(Collection<OsmPrimitive> prims, boolean released, boolean area) {
    951         DataSet ds = getLayerManager().getActiveDataSet();
     953    private void selectPrims(Collection<IPrimitive> prims, boolean released, boolean area) {
     954        OsmData<?, ?, ?, ?> ds = getLayerManager().getActiveData();
    952955
    953956        // not allowed together: do not change dataset selection, return early
    954957        // Virtual Ways: if non-empty the cursor is above a virtual node. So don't highlight
     
    10291032
    10301033    private class CycleManager {
    10311034
    1032         private Collection<OsmPrimitive> cycleList = Collections.emptyList();
     1035        private Collection<IPrimitive> cycleList = Collections.emptyList();
    10331036        private boolean cyclePrims;
    1034         private OsmPrimitive cycleStart;
     1037        private IPrimitive cycleStart;
    10351038        private boolean waitForMouseUpParameter;
    10361039        private boolean multipleMatchesParameter;
    10371040        /**
     
    11051108         * <code>cycleList</code> field
    11061109         * @return the next element of cycle list
    11071110         */
    1108         private Collection<OsmPrimitive> cyclePrims() {
     1111        private Collection<IPrimitive> cyclePrims() {
    11091112            if (cycleList.size() <= 1) {
    11101113                // no real cycling, just return one-element collection with nearest primitive in it
    11111114                return cycleList;
  • src/org/openstreetmap/josm/command/DeleteCommand.java

     
    478478            cmds.add(new DeleteCommand(primitivesToDelete.iterator().next().getDataSet(), primitivesToDelete));
    479479        }
    480480
    481         return new SequenceCommand(tr("Delete"), cmds);
     481        return SequenceCommand.createSimplifiedSequenceCommand(tr("Delete"), cmds);
    482482    }
    483483
    484484    /**
  • src/org/openstreetmap/josm/command/SequenceCommand.java

     
    7474        this(name, Arrays.asList(sequenz));
    7575    }
    7676
     77    /**
     78     * Convenient constructor, if the commands are known at compile time.
     79     * @param name The description text to be used for the sequence command, if one is created.
     80     * @param sequenz The sequence that should be executed.
     81     * @return Either a SequenceCommand, or the only command in the potential sequence
     82     * @since xxx
     83     */
     84    public static Command createSimplifiedSequenceCommand(String name, Command... sequenz) {
     85        if (sequenz.length == 1) {
     86            return sequenz[0];
     87        }
     88        return new SequenceCommand(name, sequenz);
     89    }
     90
     91    /**
     92     * Convenient constructor, if the commands are known at compile time.
     93     * @param name The description text to be used for the sequence command, if one is created.
     94     * @param sequenz The sequence that should be executed.
     95     * @return Either a SequenceCommand, or the only command in the potential sequence
     96     * @since xxx
     97     */
     98    public static Command createSimplifiedSequenceCommand(String name, Collection<Command> sequenz) {
     99        if (sequenz.size() == 1) {
     100            return sequenz.iterator().next();
     101        }
     102        return new SequenceCommand(name, sequenz);
     103    }
     104
    77105    @Override public boolean executeCommand() {
    78106        for (int i = 0; i < sequence.length; i++) {
    79107            boolean result = sequence[i].executeCommand();
  • src/org/openstreetmap/josm/data/osm/INode.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.osm;
    33
     4import org.openstreetmap.josm.data.Bounds;
    45import org.openstreetmap.josm.data.coor.EastNorth;
    56import org.openstreetmap.josm.data.coor.ILatLon;
    67import org.openstreetmap.josm.data.coor.LatLon;
     
    7071    default String getDisplayName(NameFormatter formatter) {
    7172        return formatter.format(this);
    7273    }
     74
     75
     76    /**
     77     * Determines if this node is outside of the world. See also #13538.
     78     * @return <code>true</code>, if the coordinate is outside the world, compared by using lat/lon and east/north
     79     * @since 14960 (extracted to INode in xxx)
     80     */
     81    default public boolean isOutSideWorld() {
     82        LatLon ll = getCoor();
     83        if (ll != null) {
     84            Bounds b = ProjectionRegistry.getProjection().getWorldBoundsLatLon();
     85            if (lat() < b.getMinLat() || lat() > b.getMaxLat() || lon() < b.getMinLon() || lon() > b.getMaxLon()) {
     86                return true;
     87            }
     88            if (!ProjectionRegistry.getProjection().latlon2eastNorth(ll).equalsEpsilon(getEastNorth(), 1.0)) {
     89                // we get here if a node was moved or created left from -180 or right from +180
     90                return true;
     91            }
     92        }
     93        return false;
     94    }
    7395}
  • src/org/openstreetmap/josm/data/osm/IWay.java

     
    132132     * @since 13922
    133133     */
    134134    boolean isInnerNode(INode n);
     135
     136    /**
     137     * Adds a node to the end of the list of nodes. Ignored, if n is null.
     138     *
     139     * @param n the node. Ignored, if null
     140     * @throws IllegalStateException if this way is marked as incomplete. We can't add a node
     141     * to an incomplete way
     142     * @since 1313 Way, xxx IWay
     143     */
     144    void addNode(N node);
    135145}
  • src/org/openstreetmap/josm/data/osm/Node.java

     
    1010import java.util.function.Predicate;
    1111import java.util.stream.Collectors;
    1212
    13 import org.openstreetmap.josm.data.Bounds;
    1413import org.openstreetmap.josm.data.coor.EastNorth;
    1514import org.openstreetmap.josm.data.coor.LatLon;
    1615import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor;
     
    405404        return referrers(Way.class).collect(Collectors.toList());
    406405    }
    407406
    408     /**
    409      * Determines if this node is outside of the world. See also #13538.
    410      * @return <code>true</code>, if the coordinate is outside the world, compared by using lat/lon and east/north
    411      * @since 14960
    412      */
    413     public boolean isOutSideWorld() {
    414         LatLon ll = getCoor();
    415         if (ll != null) {
    416             Bounds b = ProjectionRegistry.getProjection().getWorldBoundsLatLon();
    417             if (lat() < b.getMinLat() || lat() > b.getMaxLat() || lon() < b.getMinLon() || lon() > b.getMaxLon()) {
    418                 return true;
    419             }
    420             if (!ProjectionRegistry.getProjection().latlon2eastNorth(ll).equalsEpsilon(getEastNorth(), 1.0)) {
    421                 // we get here if a node was moved or created left from -180 or right from +180
    422                 return true;
    423             }
    424         }
    425         return false;
    426     }
    427 
    428407    @Override
    429408    public UniqueIdGenerator getIdGenerator() {
    430409        return idGenerator;
  • src/org/openstreetmap/josm/data/osm/Way.java

     
    395395        }
    396396    }
    397397
    398     /**
    399      * Adds a node to the end of the list of nodes. Ignored, if n is null.
    400      *
    401      * @param n the node. Ignored, if null
    402      * @throws IllegalStateException if this way is marked as incomplete. We can't add a node
    403      * to an incomplete way
    404      * @since 1313
    405      */
     398    @Override
    406399    public void addNode(Node n) {
    407400        checkDatasetNotReadOnly();
    408401        if (n == null) return;
  • src/org/openstreetmap/josm/data/osm/WaySegment.java

     
    22package org.openstreetmap.josm.data.osm;
    33
    44import java.awt.geom.Line2D;
     5import java.lang.reflect.InvocationTargetException;
    56import java.util.Objects;
    67
     8import org.openstreetmap.josm.tools.Logging;
     9
    710/**
    811 * A segment consisting of 2 consecutive nodes out of a way.
    912 */
    10 public final class WaySegment implements Comparable<WaySegment> {
     13public final class WaySegment<N extends INode, W extends IWay<N>> implements Comparable<WaySegment<N, W>> {
    1114
    1215    /**
    1316     * The way.
    1417     */
    15     public final Way way;
     18    public final W way;
    1619
    1720    /**
    1821     * The index of one of the 2 nodes in the way.  The other node has the
     
    2629     * @param i The node lower index
    2730     * @throws IllegalArgumentException in case of invalid index
    2831     */
    29     public WaySegment(Way w, int i) {
     32    public WaySegment(W w, int i) {
    3033        way = w;
    3134        lowerIndex = i;
    3235        if (i < 0 || i >= w.getNodesCount() - 1) {
     
    3841     * Returns the first node of the way segment.
    3942     * @return the first node
    4043     */
    41     public Node getFirstNode() {
     44    public N getFirstNode() {
    4245        return way.getNode(lowerIndex);
    4346    }
    4447
     
    4649     * Returns the second (last) node of the way segment.
    4750     * @return the second node
    4851     */
    49     public Node getSecondNode() {
     52    public N getSecondNode() {
    5053        return way.getNode(lowerIndex + 1);
    5154    }
    5255
     
    5861     * @return way segment
    5962     * @throws IllegalArgumentException if the node pair is not part of way
    6063     */
    61     public static WaySegment forNodePair(Way way, Node first, Node second) {
     64    public static <N extends INode, W extends IWay<N>> WaySegment<N, W> forNodePair(W way, N first, N second) {
    6265        int endIndex = way.getNodesCount() - 1;
    6366        while (endIndex > 0) {
    6467            final int indexOfFirst = way.getNodes().subList(0, endIndex).lastIndexOf(first);
    6568            if (second.equals(way.getNode(indexOfFirst + 1))) {
    66                 return new WaySegment(way, indexOfFirst);
     69                return new WaySegment<>(way, indexOfFirst);
    6770            }
    6871            endIndex--;
    6972        }
     
    7275
    7376    /**
    7477     * Returns this way segment as complete way.
    75      * @return the way segment as {@code Way}
     78     * @return the way segment as {@code W}
    7679     */
    77     public Way toWay() {
    78         Way w = new Way();
    79         w.addNode(getFirstNode());
    80         w.addNode(getSecondNode());
    81         return w;
     80    public W toWay() {
     81        try {
     82            /** way is of type W, so it should always create a new W */
     83            @SuppressWarnings("unchecked")
     84            W w = (W) way.getClass().getConstructor().newInstance();
     85            w.addNode(getFirstNode());
     86            w.addNode(getSecondNode());
     87            return w;
     88        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
     89                | NoSuchMethodException | SecurityException e) {
     90            Logging.trace(e);
     91            return null;
     92        }
    8293    }
    8394
    8495    @Override
     
    8596    public boolean equals(Object o) {
    8697        if (this == o) return true;
    8798        if (o == null || getClass() != o.getClass()) return false;
    88         WaySegment that = (WaySegment) o;
     99        WaySegment<?, ?> that = (WaySegment<?, ?>) o;
    89100        return lowerIndex == that.lowerIndex &&
    90101                Objects.equals(way, that.way);
    91102    }
     
    96107    }
    97108
    98109    @Override
    99     public int compareTo(WaySegment o) {
     110    public int compareTo(WaySegment<N, W> o) {
    100111        return o == null ? -1 : (equals(o) ? 0 : toWay().compareTo(o.toWay()));
    101112    }
    102113
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

     
    4040import org.openstreetmap.josm.data.coor.LatLon;
    4141import org.openstreetmap.josm.data.osm.BBox;
    4242import org.openstreetmap.josm.data.osm.DataSet;
    43 import org.openstreetmap.josm.data.osm.Node;
    44 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    45 import org.openstreetmap.josm.data.osm.Relation;
    46 import org.openstreetmap.josm.data.osm.Way;
     43import org.openstreetmap.josm.data.osm.INode;
     44import org.openstreetmap.josm.data.osm.IPrimitive;
     45import org.openstreetmap.josm.data.osm.IRelation;
     46import org.openstreetmap.josm.data.osm.IWay;
     47import org.openstreetmap.josm.data.osm.OsmData;
    4748import org.openstreetmap.josm.data.osm.WaySegment;
    4849import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    4950import org.openstreetmap.josm.data.preferences.BooleanProperty;
     
    9091    /**
    9192     * To determine if a primitive is currently selectable.
    9293     */
    93     public transient Predicate<OsmPrimitive> isSelectablePredicate = prim -> {
     94    public transient Predicate<IPrimitive> isSelectablePredicate = prim -> {
    9495        if (!prim.isSelectable()) return false;
    9596        // if it isn't displayed on screen, you cannot click on it
    9697        MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();
     
    549550     * @param n The node, where this geopoint would be drawn.
    550551     * @return The point on screen where "node" would be drawn, relative to the own top/left.
    551552     */
    552     public Point2D getPoint2D(Node n) {
     553    public Point2D getPoint2D(INode n) {
    553554        return getPoint2D(n.getEastNorth());
    554555    }
    555556
     
    590591     * looses precision, may overflow (depends on p and current scale)
    591592     * @param n node
    592593     * @return point
    593      * @see #getPoint2D(Node)
     594     * @see #getPoint2D(INode)
    594595     */
    595     public Point getPoint(Node n) {
     596    public Point getPoint(INode n) {
    596597        Point2D d = getPoint2D(n);
    597598        return new Point((int) d.getX(), (int) d.getY());
    598599    }
     
    982983     *
    983984     * @return a sorted map with the keys representing the distance of their associated nodes to point p.
    984985     */
    985     private Map<Double, List<Node>> getNearestNodesImpl(Point p, Predicate<OsmPrimitive> predicate) {
    986         Map<Double, List<Node>> nearestMap = new TreeMap<>();
    987         DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     986    private Map<Double, List<INode>> getNearestNodesImpl(Point p, Predicate<IPrimitive> predicate) {
     987        Map<Double, List<INode>> nearestMap = new TreeMap<>();
     988        OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
    988989
    989990        if (ds != null) {
    990991            double dist, snapDistanceSq = PROP_SNAP_DISTANCE.get();
    991992            snapDistanceSq *= snapDistanceSq;
    992993
    993             for (Node n : ds.searchNodes(getBBox(p, PROP_SNAP_DISTANCE.get()))) {
     994            for (INode n : ds.searchNodes(getBBox(p, PROP_SNAP_DISTANCE.get()))) {
    994995                if (predicate.test(n)
    995996                        && (dist = getPoint2D(n).distanceSq(p)) < snapDistanceSq) {
    996997                    nearestMap.computeIfAbsent(dist, k -> new LinkedList<>()).add(n);
     
    10141015     *      dist(nearest) to dist(nearest)+4px around p and
    10151016     *      that are not in ignore.
    10161017     */
    1017     public final List<Node> getNearestNodes(Point p,
    1018             Collection<Node> ignore, Predicate<OsmPrimitive> predicate) {
    1019         List<Node> nearestList = Collections.emptyList();
     1018    public final List<INode> getNearestNodes(Point p,
     1019            Collection<INode> ignore, Predicate<IPrimitive> predicate) {
     1020        List<INode> nearestList = Collections.emptyList();
    10201021
    10211022        if (ignore == null) {
    10221023            ignore = Collections.emptySet();
    10231024        }
    10241025
    1025         Map<Double, List<Node>> nlists = getNearestNodesImpl(p, predicate);
     1026        Map<Double, List<INode>> nlists = getNearestNodesImpl(p, predicate);
    10261027        if (!nlists.isEmpty()) {
    10271028            Double minDistSq = null;
    1028             for (Entry<Double, List<Node>> entry : nlists.entrySet()) {
     1029            for (Entry<Double, List<INode>> entry : nlists.entrySet()) {
    10291030                Double distSq = entry.getKey();
    1030                 List<Node> nlist = entry.getValue();
     1031                List<INode> nlist = entry.getValue();
    10311032
    10321033                // filter nodes to be ignored before determining minDistSq..
    10331034                nlist.removeAll(ignore);
     
    10601061     *      dist(nearest) to dist(nearest)+4px around p.
    10611062     * @see #getNearestNodes(Point, Collection, Predicate)
    10621063     */
    1063     public final List<Node> getNearestNodes(Point p, Predicate<OsmPrimitive> predicate) {
     1064    public final List<INode> getNearestNodes(Point p, Predicate<IPrimitive> predicate) {
    10641065        return getNearestNodes(p, null, predicate);
    10651066    }
    10661067
     
    10841085     *
    10851086     * @return A node within snap-distance to point p, that is chosen by the algorithm described.
    10861087     */
    1087     public final Node getNearestNode(Point p, Predicate<OsmPrimitive> predicate, boolean useSelected) {
     1088    public final INode getNearestNode(Point p, Predicate<IPrimitive> predicate, boolean useSelected) {
    10881089        return getNearestNode(p, predicate, useSelected, null);
    10891090    }
    10901091
     
    11121113     * @return A node within snap-distance to point p, that is chosen by the algorithm described.
    11131114     * @since 6065
    11141115     */
    1115     public final Node getNearestNode(Point p, Predicate<OsmPrimitive> predicate,
    1116             boolean useSelected, Collection<OsmPrimitive> preferredRefs) {
     1116    public final INode getNearestNode(Point p, Predicate<IPrimitive> predicate,
     1117            boolean useSelected, Collection<IPrimitive> preferredRefs) {
    11171118
    1118         Map<Double, List<Node>> nlists = getNearestNodesImpl(p, predicate);
     1119        Map<Double, List<INode>> nlists = getNearestNodesImpl(p, predicate);
    11191120        if (nlists.isEmpty()) return null;
    11201121
    11211122        if (preferredRefs != null && preferredRefs.isEmpty()) preferredRefs = null;
    1122         Node ntsel = null, ntnew = null, ntref = null;
     1123        INode ntsel = null, ntnew = null, ntref = null;
    11231124        boolean useNtsel = useSelected;
    11241125        double minDistSq = nlists.keySet().iterator().next();
    11251126
    1126         for (Entry<Double, List<Node>> entry : nlists.entrySet()) {
     1127        for (Entry<Double, List<INode>> entry : nlists.entrySet()) {
    11271128            Double distSq = entry.getKey();
    1128             for (Node nd : entry.getValue()) {
     1129            for (INode nd : entry.getValue()) {
    11291130                // find the nearest selected node
    11301131                if (ntsel == null && nd.isSelected()) {
    11311132                    ntsel = nd;
     
    11361137                    useNtsel |= Utils.equalsEpsilon(distSq, minDistSq);
    11371138                }
    11381139                if (ntref == null && preferredRefs != null && Utils.equalsEpsilon(distSq, minDistSq)) {
    1139                     List<OsmPrimitive> ndRefs = nd.getReferrers();
    1140                     for (OsmPrimitive ref: preferredRefs) {
     1140                    List<? extends IPrimitive> ndRefs = nd.getReferrers();
     1141                    for (IPrimitive ref: preferredRefs) {
    11411142                        if (ndRefs.contains(ref)) {
    11421143                            ntref = nd;
    11431144                            break;
     
    11701171     *
    11711172     * @return The nearest node to point p.
    11721173     */
    1173     public final Node getNearestNode(Point p, Predicate<OsmPrimitive> predicate) {
     1174    public final INode getNearestNode(Point p, Predicate<IPrimitive> predicate) {
    11741175        return getNearestNode(p, predicate, true);
    11751176    }
    11761177
     
    11841185     * @return a sorted map with the keys representing the perpendicular
    11851186     *      distance of their associated way segments to point p.
    11861187     */
    1187     private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p, Predicate<OsmPrimitive> predicate) {
    1188         Map<Double, List<WaySegment>> nearestMap = new TreeMap<>();
     1188    private Map<Double, List<WaySegment<?, ?>>> getNearestWaySegmentsImpl(Point p, Predicate<IPrimitive> predicate) {
     1189        Map<Double, List<WaySegment<?, ?>>> nearestMap = new TreeMap<>();
    11891190        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    11901191
    11911192        if (ds != null) {
     
    11921193            double snapDistanceSq = Config.getPref().getInt("mappaint.segment.snap-distance", 10);
    11931194            snapDistanceSq *= snapDistanceSq;
    11941195
    1195             for (Way w : ds.searchWays(getBBox(p, Config.getPref().getInt("mappaint.segment.snap-distance", 10)))) {
     1196            for (IWay<?> w : ds.searchWays(getBBox(p, Config.getPref().getInt("mappaint.segment.snap-distance", 10)))) {
    11961197                if (!predicate.test(w)) {
    11971198                    continue;
    11981199                }
    1199                 Node lastN = null;
     1200                INode lastN = null;
    12001201                int i = -2;
    1201                 for (Node n : w.getNodes()) {
     1202                for (INode n : w.getNodes()) {
    12021203                    i++;
    12031204                    if (n.isDeleted() || n.isIncomplete()) { //FIXME: This shouldn't happen, raise exception?
    12041205                        continue;
     
    12241225                            >> 32 << 32); // resolution in numbers with large exponent not needed here..
    12251226
    12261227                    if (perDistSq < snapDistanceSq && a < c + snapDistanceSq && b < c + snapDistanceSq) {
    1227                         nearestMap.computeIfAbsent(perDistSq, k -> new LinkedList<>()).add(new WaySegment(w, i));
     1228                        nearestMap.computeIfAbsent(perDistSq, k -> new LinkedList<>()).add(new WaySegment<>(w, i));
    12281229                    }
    12291230
    12301231                    lastN = n;
     
    12471248     * @return all segments within 10px of p that are not in ignore,
    12481249     *          sorted by their perpendicular distance.
    12491250     */
    1250     public final List<WaySegment> getNearestWaySegments(Point p,
    1251             Collection<WaySegment> ignore, Predicate<OsmPrimitive> predicate) {
    1252         List<WaySegment> nearestList = new ArrayList<>();
    1253         List<WaySegment> unselected = new LinkedList<>();
     1251    public final List<WaySegment<?, ?>> getNearestWaySegments(Point p,
     1252            Collection<WaySegment<?, ?>> ignore, Predicate<IPrimitive> predicate) {
     1253        List<WaySegment<?, ?>> nearestList = new ArrayList<>();
     1254        List<WaySegment<?, ?>> unselected = new LinkedList<>();
    12541255
    1255         for (List<WaySegment> wss : getNearestWaySegmentsImpl(p, predicate).values()) {
     1256        for (List<WaySegment<?, ?>> wss : getNearestWaySegmentsImpl(p, predicate).values()) {
    12561257            // put selected waysegs within each distance group first
    12571258            // makes the order of nearestList dependent on current selection state
    1258             for (WaySegment ws : wss) {
     1259            for (WaySegment<?, ?> ws : wss) {
    12591260                (ws.way.isSelected() ? nearestList : unselected).add(ws);
    12601261            }
    12611262            nearestList.addAll(unselected);
     
    12771278     * @return all segments within 10px of p, sorted by their perpendicular distance.
    12781279     * @see #getNearestWaySegments(Point, Collection, Predicate)
    12791280     */
    1280     public final List<WaySegment> getNearestWaySegments(Point p, Predicate<OsmPrimitive> predicate) {
     1281    public final List<WaySegment<?, ?>> getNearestWaySegments(Point p, Predicate<IPrimitive> predicate) {
    12811282        return getNearestWaySegments(p, null, predicate);
    12821283    }
    12831284
     
    12921293     *      and, depending on use_selected, prefers a selected way segment, if found.
    12931294     * @see #getNearestWaySegments(Point, Collection, Predicate)
    12941295     */
    1295     public final WaySegment getNearestWaySegment(Point p, Predicate<OsmPrimitive> predicate, boolean useSelected) {
    1296         WaySegment wayseg = null;
    1297         WaySegment ntsel = null;
     1296    public final WaySegment<?, ?> getNearestWaySegment(Point p, Predicate<IPrimitive> predicate, boolean useSelected) {
     1297        WaySegment<?, ?> wayseg = null;
     1298        WaySegment<?, ?> ntsel = null;
    12981299
    1299         for (List<WaySegment> wslist : getNearestWaySegmentsImpl(p, predicate).values()) {
     1300        for (List<WaySegment<?, ?>> wslist : getNearestWaySegmentsImpl(p, predicate).values()) {
    13001301            if (wayseg != null && ntsel != null) {
    13011302                break;
    13021303            }
    1303             for (WaySegment ws : wslist) {
     1304            for (WaySegment<?, ?> ws : wslist) {
    13041305                if (wayseg == null) {
    13051306                    wayseg = ws;
    13061307                }
     
    13281329     * @see #getNearestWaySegments(Point, Collection, Predicate)
    13291330     * @since 6065
    13301331     */
    1331     public final WaySegment getNearestWaySegment(Point p, Predicate<OsmPrimitive> predicate,
    1332             boolean useSelected, Collection<OsmPrimitive> preferredRefs) {
    1333         WaySegment wayseg = null;
     1332    public final WaySegment<? extends INode, ? extends IWay<?>> getNearestWaySegment(Point p, Predicate<IPrimitive> predicate,
     1333            boolean useSelected, Collection<IPrimitive> preferredRefs) {
     1334        WaySegment<?, ?> wayseg = null;
    13341335        if (preferredRefs != null && preferredRefs.isEmpty())
    13351336            preferredRefs = null;
    13361337
    1337         for (List<WaySegment> wslist : getNearestWaySegmentsImpl(p, predicate).values()) {
    1338             for (WaySegment ws : wslist) {
     1338        for (List<WaySegment<?, ?>> wslist : getNearestWaySegmentsImpl(p, predicate).values()) {
     1339            for (WaySegment<?, ?> ws : wslist) {
    13391340                if (wayseg == null) {
    13401341                    wayseg = ws;
    13411342                }
     
    13471348                    if (preferredRefs.contains(ws.getFirstNode()) || preferredRefs.contains(ws.getSecondNode())) {
    13481349                        return ws;
    13491350                    }
    1350                     Collection<OsmPrimitive> wayRefs = ws.way.getReferrers();
     1351                    Collection<? extends IPrimitive> wayRefs = ws.way.getReferrers();
    13511352                    // prefer member of the given relations
    1352                     for (OsmPrimitive ref: preferredRefs) {
    1353                         if (ref instanceof Relation && wayRefs.contains(ref)) {
     1353                    for (IPrimitive ref: preferredRefs) {
     1354                        if (ref instanceof IRelation && wayRefs.contains(ref)) {
    13541355                            return ws;
    13551356                        }
    13561357                    }
     
    13671368     *
    13681369     * @return The nearest way segment to point p.
    13691370     */
    1370     public final WaySegment getNearestWaySegment(Point p, Predicate<OsmPrimitive> predicate) {
     1371    public final WaySegment<?, ?> getNearestWaySegment(Point p, Predicate<IPrimitive> predicate) {
    13711372        return getNearestWaySegment(p, predicate, true);
    13721373    }
    13731374
     
    13831384     * @return all nearest ways to the screen point given that are not in ignore.
    13841385     * @see #getNearestWaySegments(Point, Collection, Predicate)
    13851386     */
    1386     public final List<Way> getNearestWays(Point p,
    1387             Collection<Way> ignore, Predicate<OsmPrimitive> predicate) {
    1388         List<Way> nearestList = new ArrayList<>();
    1389         Set<Way> wset = new HashSet<>();
     1387    public final List<IWay<?>> getNearestWays(Point p,
     1388            Collection<IWay<?>> ignore, Predicate<IPrimitive> predicate) {
     1389        List<IWay<?>> nearestList = new ArrayList<>();
     1390        Set<IWay<?>> wset = new HashSet<>();
    13901391
    1391         for (List<WaySegment> wss : getNearestWaySegmentsImpl(p, predicate).values()) {
    1392             for (WaySegment ws : wss) {
     1392        for (List<WaySegment<?, ?>> wss : getNearestWaySegmentsImpl(p, predicate).values()) {
     1393            for (WaySegment<?, ?> ws : wss) {
    13931394                if (wset.add(ws.way)) {
    13941395                    nearestList.add(ws.way);
    13951396                }
     
    14131414     * @return all nearest ways to the screen point given.
    14141415     * @see #getNearestWays(Point, Collection, Predicate)
    14151416     */
    1416     public final List<Way> getNearestWays(Point p, Predicate<OsmPrimitive> predicate) {
     1417    public final List<IWay<?>> getNearestWays(Point p, Predicate<IPrimitive> predicate) {
    14171418        return getNearestWays(p, null, predicate);
    14181419    }
    14191420
     
    14261427     * @return The nearest way to point p, prefer a selected way if there are multiple nearest.
    14271428     * @see #getNearestWaySegment(Point, Predicate)
    14281429     */
    1429     public final Way getNearestWay(Point p, Predicate<OsmPrimitive> predicate) {
    1430         WaySegment nearestWaySeg = getNearestWaySegment(p, predicate);
     1430    public final IWay<?> getNearestWay(Point p, Predicate<IPrimitive> predicate) {
     1431        WaySegment<?, ?> nearestWaySeg = getNearestWaySegment(p, predicate);
    14311432        return (nearestWaySeg == null) ? null : nearestWaySeg.way;
    14321433    }
    14331434
     
    14521453     * @see #getNearestNodes(Point, Collection, Predicate)
    14531454     * @see #getNearestWays(Point, Collection, Predicate)
    14541455     */
    1455     public final List<OsmPrimitive> getNearestNodesOrWays(Point p,
    1456             Collection<OsmPrimitive> ignore, Predicate<OsmPrimitive> predicate) {
    1457         List<OsmPrimitive> nearestList = Collections.emptyList();
    1458         OsmPrimitive osm = getNearestNodeOrWay(p, predicate, false);
     1456    public final List<IPrimitive> getNearestNodesOrWays(Point p,
     1457            Collection<IPrimitive> ignore, Predicate<IPrimitive> predicate) {
     1458        List<IPrimitive> nearestList = Collections.emptyList();
     1459        IPrimitive osm = getNearestNodeOrWay(p, predicate, false);
    14591460
    14601461        if (osm != null) {
    1461             if (osm instanceof Node) {
     1462            if (osm instanceof INode) {
    14621463                nearestList = new ArrayList<>(getNearestNodes(p, predicate));
    1463             } else if (osm instanceof Way) {
     1464            } else if (osm instanceof IWay) {
    14641465                nearestList = new ArrayList<>(getNearestWays(p, predicate));
    14651466            }
    14661467            if (ignore != null) {
     
    14811482     * @return Primitives nearest to the given screen point.
    14821483     * @see #getNearestNodesOrWays(Point, Collection, Predicate)
    14831484     */
    1484     public final List<OsmPrimitive> getNearestNodesOrWays(Point p, Predicate<OsmPrimitive> predicate) {
     1485    public final List<IPrimitive> getNearestNodesOrWays(Point p, Predicate<IPrimitive> predicate) {
    14851486        return getNearestNodesOrWays(p, null, predicate);
    14861487    }
    14871488
     
    14941495     * @param useSelected whether to prefer selected nodes
    14951496     * @return true, if the node fulfills the properties of the function body
    14961497     */
    1497     private boolean isPrecedenceNode(Node osm, Point p, boolean useSelected) {
     1498    private boolean isPrecedenceNode(INode osm, Point p, boolean useSelected) {
    14981499        if (osm != null) {
    14991500            if (p.distanceSq(getPoint2D(osm)) <= (4*4)) return true;
    15001501            if (osm.isTagged()) return true;
     
    15271528     * @see #getNearestNode(Point, Predicate)
    15281529     * @see #getNearestWay(Point, Predicate)
    15291530     */
    1530     public final OsmPrimitive getNearestNodeOrWay(Point p, Predicate<OsmPrimitive> predicate, boolean useSelected) {
    1531         Collection<OsmPrimitive> sel;
    1532         DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     1531    public final IPrimitive getNearestNodeOrWay(Point p, Predicate<IPrimitive> predicate, boolean useSelected) {
     1532        Collection<IPrimitive> sel;
     1533        OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
    15331534        if (useSelected && ds != null) {
    1534             sel = ds.getSelected();
     1535            sel = new ArrayList<>(ds.getSelected());
    15351536        } else {
    15361537            sel = null;
    15371538        }
    1538         OsmPrimitive osm = getNearestNode(p, predicate, useSelected, sel);
     1539        IPrimitive osm = getNearestNode(p, predicate, useSelected, sel);
    15391540
    1540         if (isPrecedenceNode((Node) osm, p, useSelected)) return osm;
    1541         WaySegment ws;
     1541        if (isPrecedenceNode((INode) osm, p, useSelected)) return osm;
     1542        WaySegment<?, ?> ws;
    15421543        if (useSelected) {
    15431544            ws = getNearestWaySegment(p, predicate, useSelected, sel);
    15441545        } else {
     
    15591560            // is wayseg shorter than maxWaySegLenSq and
    15601561            // is p closer to the middle of wayseg  than  to the nearest node?
    15611562            if (wp1.distanceSq(wp2) < maxWaySegLenSq &&
    1562                     p.distanceSq(project(0.5, wp1, wp2)) < p.distanceSq(getPoint2D((Node) osm))) {
     1563                    p.distanceSq(project(0.5, wp1, wp2)) < p.distanceSq(getPoint2D((INode) osm))) {
    15631564                osm = ws.way;
    15641565            }
    15651566        }
     
    15961597     * @return a list of all objects that are nearest to point p and
    15971598     *          not in ignore or an empty list if nothing was found.
    15981599     */
    1599     public final List<OsmPrimitive> getAllNearest(Point p,
    1600             Collection<OsmPrimitive> ignore, Predicate<OsmPrimitive> predicate) {
    1601         List<OsmPrimitive> nearestList = new ArrayList<>();
    1602         Set<Way> wset = new HashSet<>();
     1600    public final List<IPrimitive> getAllNearest(Point p,
     1601            Collection<IPrimitive> ignore, Predicate<IPrimitive> predicate) {
     1602        List<IPrimitive> nearestList = new ArrayList<>();
     1603        Set<IWay<?>> wset = new HashSet<>();
    16031604
    16041605        // add nearby ways
    1605         for (List<WaySegment> wss : getNearestWaySegmentsImpl(p, predicate).values()) {
    1606             for (WaySegment ws : wss) {
     1606        for (List<WaySegment<?, ?>> wss : getNearestWaySegmentsImpl(p, predicate).values()) {
     1607            for (WaySegment<?, ?> ws : wss) {
    16071608                if (wset.add(ws.way)) {
    16081609                    nearestList.add(ws.way);
    16091610                }
     
    16111612        }
    16121613
    16131614        // add nearby nodes
    1614         for (List<Node> nlist : getNearestNodesImpl(p, predicate).values()) {
     1615        for (List<INode> nlist : getNearestNodesImpl(p, predicate).values()) {
    16151616            nearestList.addAll(nlist);
    16161617        }
    16171618
    16181619        // add parent relations of nearby nodes and ways
    1619         Set<OsmPrimitive> parentRelations = new HashSet<>();
    1620         for (OsmPrimitive o : nearestList) {
    1621             for (OsmPrimitive r : o.getReferrers()) {
    1622                 if (r instanceof Relation && predicate.test(r)) {
     1620        Set<IPrimitive> parentRelations = new HashSet<>();
     1621        for (IPrimitive o : nearestList) {
     1622            for (IPrimitive r : o.getReferrers()) {
     1623                if (r instanceof IRelation && predicate.test(r)) {
    16231624                    parentRelations.add(r);
    16241625                }
    16251626            }
     
    16441645     *          or an empty list if nothing was found.
    16451646     * @see #getAllNearest(Point, Collection, Predicate)
    16461647     */
    1647     public final List<OsmPrimitive> getAllNearest(Point p, Predicate<OsmPrimitive> predicate) {
     1648    public final List<IPrimitive> getAllNearest(Point p, Predicate<IPrimitive> predicate) {
    16481649        return getAllNearest(p, null, predicate);
    16491650    }
    16501651
  • src/org/openstreetmap/josm/gui/SelectionManager.java

     
    1919
    2020import org.openstreetmap.josm.actions.SelectByInternalPointAction;
    2121import org.openstreetmap.josm.data.Bounds;
    22 import org.openstreetmap.josm.data.osm.DataSet;
    23 import org.openstreetmap.josm.data.osm.Node;
    24 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    25 import org.openstreetmap.josm.data.osm.Way;
     22import org.openstreetmap.josm.data.osm.INode;
     23import org.openstreetmap.josm.data.osm.IPrimitive;
     24import org.openstreetmap.josm.data.osm.IWay;
     25import org.openstreetmap.josm.data.osm.OsmData;
    2626import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    2727import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable;
    2828import org.openstreetmap.josm.tools.Utils;
     
    363363     * objects that are touched, instead those which are completely covered.
    364364     * @return The collection of selected objects.
    365365     */
    366     public Collection<OsmPrimitive> getSelectedObjects(boolean alt) {
    367         Collection<OsmPrimitive> selection = new LinkedList<>();
     366    public Collection<IPrimitive> getSelectedObjects(boolean alt) {
     367        Collection<IPrimitive> selection = new LinkedList<>();
    368368
    369369        // whether user only clicked, not dragged.
    370370        boolean clicked = false;
     
    373373            clicked = true;
    374374        }
    375375
    376         DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     376        OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
    377377        if (clicked) {
    378378            Point center = new Point(selectionResult.xpoints[0], selectionResult.ypoints[0]);
    379             OsmPrimitive osm = nc.getNearestNodeOrWay(center, OsmPrimitive::isSelectable, false);
     379            IPrimitive osm = nc.getNearestNodeOrWay(center, IPrimitive::isSelectable, false);
    380380            if (osm != null) {
    381381                selection.add(osm);
    382382            }
    383383        } else if (ds != null) {
    384384            // nodes
    385             for (Node n : ds.getNodes()) {
     385            for (INode n : ds.getNodes()) {
    386386                if (n.isSelectable() && selectionResult.contains(nc.getPoint2D(n))) {
    387387                    selection.add(n);
    388388                }
     
    389389            }
    390390
    391391            // ways
    392             for (Way w : ds.getWays()) {
     392            for (IWay<?> w : ds.getWays()) {
    393393                if (!w.isSelectable() || w.isEmpty()) {
    394394                    continue;
    395395                }
    396396                if (alt) {
    397                     for (Node n : w.getNodes()) {
     397                    for (INode n : w.getNodes()) {
    398398                        if (!n.isIncomplete() && selectionResult.contains(nc.getPoint2D(n))) {
    399399                            selection.add(w);
    400400                            break;
     
    402402                    }
    403403                } else {
    404404                    boolean allIn = true;
    405                     for (Node n : w.getNodes()) {
     405                    for (INode n : w.getNodes()) {
    406406                        if (!n.isIncomplete() && !selectionResult.contains(nc.getPoint(n))) {
    407407                            allIn = false;
    408408                            break;