Changeset 6156 in josm for trunk/src


Ignore:
Timestamp:
2013-08-19T15:10:53+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8971 - ArrayIndexOutOfBoundsException when combining single node way + javadoc

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java

    r6130 r6156  
    4242/**
    4343 * Combines multiple ways into one.
    44  *
     44 * @since 213
    4545 */
    4646public class CombineWayAction extends JosmAction {
     
    4848    private static final BooleanProperty PROP_REVERSE_WAY = new BooleanProperty("tag-correction.reverse-way", true);
    4949
     50    /**
     51     * Constructs a new {@code CombineWayAction}.
     52     */
    5053    public CombineWayAction() {
    5154        super(tr("Combine Way"), "combineway", tr("Combine several ways into one."),
     
    123126        List<Way> unreversedWays = new LinkedList<Way>();
    124127        for (Way w: ways) {
    125             if ((path.indexOf(w.getNode(0)) + 1) == path.lastIndexOf(w.getNode(1))) {
     128            // Treat zero or one-node ways as unreversed as Combine action action is a good way to fix them (see #8971)
     129            if (w.getNodesCount() < 2 || (path.indexOf(w.getNode(0)) + 1) == path.lastIndexOf(w.getNode(1))) {
    126130                unreversedWays.add(w);
    127131            } else {
     
    247251    }
    248252
     253    /**
     254     * A pair of nodes.
     255     */
    249256    static public class NodePair {
    250         private Node a;
    251         private Node b;
     257        private final Node a;
     258        private final Node b;
     259       
     260        /**
     261         * Constructs a new {@code NodePair}.
     262         * @param a The first node
     263         * @param b The second node
     264         */
    252265        public NodePair(Node a, Node b) {
    253             this.a =a;
     266            this.a = a;
    254267            this.b = b;
    255268        }
    256269
     270        /**
     271         * Constructs a new {@code NodePair}.
     272         * @param pair An existing {@code Pair} of nodes
     273         */
    257274        public NodePair(Pair<Node,Node> pair) {
    258             this.a = pair.a;
    259             this.b = pair.b;
    260         }
    261 
     275            this(pair.a, pair.b);
     276        }
     277
     278        /**
     279         * Constructs a new {@code NodePair}.
     280         * @param other An existing {@code NodePair}
     281         */
    262282        public NodePair(NodePair other) {
    263             this.a = other.a;
    264             this.b = other.b;
    265         }
    266 
     283            this(other.a, other.b);
     284        }
     285
     286        /**
     287         * Replies the first node.
     288         * @return The first node
     289         */
    267290        public Node getA() {
    268291            return a;
    269292        }
    270293
     294        /**
     295         * Replies the second node
     296         * @return The second node
     297         */
    271298        public Node getB() {
    272299            return b;
     
    304331        }
    305332
     333        /**
     334         * Determines if this pair contains the given node.
     335         * @param n The node to look for
     336         * @return {@code true} if {@code n} is in the pair, {@code false} otherwise
     337         */
    306338        public boolean contains(Node n) {
    307339            return a == n || b == n;
     
    316348            return result;
    317349        }
     350       
    318351        @Override
    319352        public boolean equals(Object obj) {
     
    458491        }
    459492
     493        /**
     494         * Constructs a new {@code NodeGraph}.
     495         */
    460496        public NodeGraph() {
    461497            edges = new LinkedHashSet<NodePair>();
  • trunk/src/org/openstreetmap/josm/tools/Pair.java

    r4272 r6156  
    44
    55/**
    6  * A pair.
     6 * A pair of objects.
     7 * @param <A> Type of first item
     8 * @param <B> Type of second item
     9 * @since 429
    710 */
    811public final class Pair<A,B> {
     12   
     13    /**
     14     * The first item
     15     */
    916    public A a;
     17   
     18    /**
     19     * The second item
     20     */
    1021    public B b;
    1122
     23    /**
     24     * Constructs a new {@code Pair}.
     25     * @param a The first item
     26     * @param b The second item
     27     */
    1228    public Pair(A a, B b) {
    1329        this.a = a;
     
    4864    }
    4965
    50     /* convenience constructor method */
     66    /**
     67     * Convenient constructor method
     68     * @param u The first item
     69     * @param v The second item
     70     * @return The newly created Pair(u,v)
     71     */
    5172    public static <U,V> Pair<U,V> create(U u, V v) {
    5273        return new Pair<U,V>(u,v);
Note: See TracChangeset for help on using the changeset viewer.