Ignore:
Timestamp:
2018-05-08T14:41:28+02:00 (6 years ago)
Author:
Don-vip
Message:

better API alignment between Way and WayData

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r13670 r13717  
    1010import java.util.Map;
    1111import java.util.Set;
     12import java.util.stream.Collectors;
    1213
    1314import org.openstreetmap.josm.data.coor.LatLon;
     
    2627 * @since 64
    2728 */
    28 public final class Way extends OsmPrimitive implements IWay {
     29public final class Way extends OsmPrimitive implements IWay<Node> {
    2930
    3031    /**
    3132     * All way nodes in this way
    32      *
    3333     */
    3434    private Node[] nodes = new Node[0];
    3535    private BBox bbox;
    3636
    37     /**
    38      *
    39      * You can modify returned list but changes will not be propagated back
    40      * to the Way. Use {@link #setNodes(List)} to update this way
    41      * @return Nodes composing the way
    42      * @since 1862
    43      */
     37    @Override
    4438    public List<Node> getNodes() {
    4539        return new CopyList<>(nodes);
     
    10599    }
    106100
    107     /**
    108      * Replies the node at position <code>index</code>.
    109      *
    110      * @param index the position
    111      * @return  the node at position <code>index</code>
    112      * @throws ArrayIndexOutOfBoundsException if <code>index</code> &lt; 0
    113      * or <code>index</code> &gt;= {@link #getNodesCount()}
    114      * @since 1862
    115      */
     101    @Override
    116102    public Node getNode(int index) {
    117103        return nodes[index];
     
    121107    public long getNodeId(int idx) {
    122108        return nodes[idx].getUniqueId();
     109    }
     110
     111    @Override
     112    public List<Long> getNodeIds() {
     113        return Arrays.stream(nodes).map(Node::getId).collect(Collectors.toList());
    123114    }
    124115
     
    277268
    278269            List<Node> newNodes = new ArrayList<>(wayData.getNodes().size());
    279             for (Long nodeId : wayData.getNodes()) {
     270            for (Long nodeId : wayData.getNodeIds()) {
    280271                Node node = (Node) getDataSet().getPrimitiveById(nodeId, OsmPrimitiveType.NODE);
    281272                if (node != null) {
     
    296287        saveCommonAttributes(data);
    297288        for (Node node:nodes) {
    298             data.getNodes().add(node.getUniqueId());
     289            data.getNodeIds().add(node.getUniqueId());
    299290        }
    300291        return data;
Note: See TracChangeset for help on using the changeset viewer.