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

better API alignment between Way and WayData

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
8 edited

Legend:

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

    r13564 r13717  
    140140        if (osm instanceof INode) {
    141141            return format((INode) osm);
    142         } else if (osm instanceof IWay) {
    143             return format((IWay) osm);
     142        } else if (osm instanceof IWay<?>) {
     143            return format((IWay<?>) osm);
    144144        } else if (osm instanceof IRelation) {
    145145            return format((IRelation) osm);
     
    214214
    215215    @Override
    216     public String format(IWay way) {
     216    public String format(IWay<?> way) {
    217217        StringBuilder name = new StringBuilder();
    218218
     
    298298    }
    299299
    300     private final Comparator<IWay> wayComparator = (w1, w2) -> format(w1).compareTo(format(w2));
    301 
    302     @Override
    303     public Comparator<IWay> getWayComparator() {
     300    private final Comparator<IWay<?>> wayComparator = (w1, w2) -> format(w1).compareTo(format(w2));
     301
     302    @Override
     303    public Comparator<IWay<?>> getWayComparator() {
    304304        return wayComparator;
    305305    }
  • trunk/src/org/openstreetmap/josm/data/osm/IWay.java

    r13665 r13717  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.util.List;
     5
    46/**
    57 * IWay captures the common functions of {@link Way} and {@link WayData}.
     8 * @param <N> type of OSM node
    69 * @since 4098
    710 */
    8 public interface IWay extends IPrimitive {
     11public interface IWay<N extends INode> extends IPrimitive {
    912
    1013    /**
     
    3134
    3235    /**
     36     * Replies the node at position <code>index</code>.
     37     *
     38     * @param index the position
     39     * @return  the node at position <code>index</code>
     40     * @throws ArrayIndexOutOfBoundsException if <code>index</code> &lt; 0
     41     * or <code>index</code> &gt;= {@link #getNodesCount()}
     42     * @since 1862
     43     * @since 13717 (IWay)
     44     */
     45    N getNode(int index);
     46
     47    /**
     48     * Returns the list of nodes in this way.
     49     * @return the list of nodes in this way
     50     * @since 1862
     51     * @since 13717 (IWay)
     52     */
     53    List<N> getNodes();
     54
     55    /**
     56     * Returns the list of node ids in this way.
     57     * @return the list of node ids in this way
     58     * @since 13717
     59     */
     60    List<Long> getNodeIds();
     61
     62    /**
    3363     * Returns id of the node at given index.
    3464     * @param idx node index
     
    4777        if (o instanceof IRelation)
    4878            return 1;
    49         return o instanceof IWay ? Long.compare(getUniqueId(), o.getUniqueId()) : -1;
     79        return o instanceof IWay<?> ? Long.compare(getUniqueId(), o.getUniqueId()) : -1;
    5080    }
    5181
  • trunk/src/org/openstreetmap/josm/data/osm/NameFormatter.java

    r13564 r13717  
    2626     * @since 13564 (signature)
    2727     */
    28     String format(IWay way);
     28    String format(IWay<?> way);
    2929
    3030    /**
     
    5757     * @since 13564 (signature)
    5858     */
    59     Comparator<IWay> getWayComparator();
     59    Comparator<IWay<?>> getWayComparator();
    6060
    6161    /**
  • trunk/src/org/openstreetmap/josm/data/osm/NameFormatterHook.java

    r12663 r13717  
    3131     * @return The corrected format if needed, null otherwise.
    3232     */
    33     String checkFormat(IWay way, String defaultName);
     33    String checkFormat(IWay<?> way, String defaultName);
    3434
    3535    /**
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java

    r12018 r13717  
    8686    public static OsmPrimitiveType from(IPrimitive obj) {
    8787        if (obj instanceof INode) return NODE;
    88         if (obj instanceof IWay) return WAY;
     88        if (obj instanceof IWay<?>) return WAY;
    8989        if (obj instanceof IRelation) return RELATION;
    9090        throw new IllegalArgumentException("Unknown type: "+obj);
  • 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;
  • trunk/src/org/openstreetmap/josm/data/osm/WayData.java

    r12193 r13717  
    1010 * The data (tags and node ids) that is stored for a way in the database
    1111 */
    12 public class WayData extends PrimitiveData implements IWay {
     12public class WayData extends PrimitiveData implements IWay<NodeData> {
    1313
    1414    private static final long serialVersionUID = 106944939313286415L;
     
    3737    public WayData(WayData data) {
    3838        super(data);
    39         nodes.addAll(data.getNodes());
     39        nodes.addAll(data.getNodeIds());
    4040    }
    4141
    42     /**
    43      * Gets a list of nodes the way consists of
    44      * @return The ids of the nodes
    45      */
    46     public List<Long> getNodes() {
     42    @Override
     43    public List<NodeData> getNodes() {
     44        throw new UnsupportedOperationException("Use getNodeIds() instead");
     45    }
     46
     47    @Override
     48    public NodeData getNode(int index) {
     49        throw new UnsupportedOperationException("Use getNodeId(int) instead");
     50    }
     51
     52    @Override
     53    public List<Long> getNodeIds() {
    4754        return nodes;
    4855    }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/PrimitiveVisitor.java

    r13623 r13717  
    2222     * @param w The way to inspect.
    2323     */
    24     void visit(IWay w);
     24    void visit(IWay<?> w);
    2525
    2626    /**
Note: See TracChangeset for help on using the changeset viewer.