Changeset 1926 in josm for trunk


Ignore:
Timestamp:
2009-08-08T09:22:24+02:00 (12 years ago)
Author:
jttt
Message:

Replaced Relation.members with Relation.getMember() or Relation.getMembersCount()

Location:
trunk
Files:
7 edited

Legend:

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

    r1925 r1926  
    100100                }
    101101            }
    102             rnew.members.clear();
    103             rnew.members.addAll(members);
     102            rnew.setMembers(members);
    104103            map.put(r, rnew);
    105104        }
  • trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java

    r1814 r1926  
    4343
    4444    @Override public boolean executeCommand() {
    45         if (position < 0 || position >= relation.members.size()) {
     45        if (position < 0 || position >= relation.getMembersCount()) {
    4646            Main.debug("error changing the role");
    4747            return false;
    4848        }
    4949
    50         oldRole = relation.members.get(position).role;
    51         relation.members.get(position).role = newRole;
     50        oldRole = relation.getMember(position).role;
     51        relation.getMember(position).role = newRole;
    5252
    5353        oldModified = relation.modified;
     
    5757
    5858    @Override public void undoCommand() {
    59         relation.members.get(position).role = oldRole;
     59        relation.getMember(position).role = oldRole;
    6060        relation.modified = oldModified;
    6161    }
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r1925 r1926  
    3737    /**
    3838     *
    39      * @param members
     39     * @param members Can be null, in that case all members are removed
    4040     * @since 1925
    4141     */
    4242    public void setMembers(List<RelationMember> members) {
    4343        this.members.clear();
    44         this.members.addAll(members);
     44        if (members != null) {
     45            this.members.addAll(members);
     46        }
     47    }
     48
     49    /**
     50     *
     51     * @since 1926
     52     */
     53    public int getMembersCount() {
     54        return members.size();
     55    }
     56
     57    /**
     58     *
     59     * @param index
     60     * @return
     61     * @since 1926
     62     */
     63    public RelationMember getMember(int index) {
     64        return members.get(index);
    4565    }
    4666
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r1925 r1926  
    206206        }
    207207        if (replacedSomething) {
    208             r.members.clear();
    209             r.members.addAll(newMembers);
     208            r.setMembers(newMembers);
    210209        }
    211210    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r1925 r1926  
    1818
    1919import org.openstreetmap.josm.Main;
    20 import org.openstreetmap.josm.data.SelectionChangedListener;
    2120import org.openstreetmap.josm.data.osm.DataSet;
    2221import org.openstreetmap.josm.data.osm.Node;
     
    224223
    225224    public void applyToRelation(Relation relation) {
    226         relation.members.clear();
    227         relation.members.addAll(members);
     225        relation.setMembers(members);
    228226    }
    229227
  • trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/MergeSourceBuildingVisitorTest.java

    r1912 r1926  
    22package org.openstreetmap.josm.data.osm.visitor;
    33
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertNotNull;
     6import static org.junit.Assert.assertNull;
     7import static org.junit.Assert.assertTrue;
     8
    49import java.util.Collection;
    510
    6 import org.junit.Ignore;
    711import org.junit.Test;
    812import org.openstreetmap.josm.data.coor.LatLon;
     
    1317import org.openstreetmap.josm.data.osm.RelationMember;
    1418import org.openstreetmap.josm.data.osm.Way;
    15 
    16 import static org.junit.Assert.*;
    1719
    1820public class MergeSourceBuildingVisitorTest {
     
    195197        r = (Relation)hull.getPrimitiveById(1);
    196198        assertNotNull(r);
    197         assertEquals(3, r.members.size());
     199        assertEquals(3, r.getMembersCount());
    198200        RelationMember m = new RelationMember("node-20", hull.getPrimitiveById(20));
    199201        assertTrue(r.members.contains(m));
     
    254256        r = (Relation)hull.getPrimitiveById(1);
    255257        assertNotNull(r);
    256         assertEquals(3, r.members.size());
     258        assertEquals(3, r.getMembersCount());
    257259        RelationMember m = new RelationMember("node-20", hull.getPrimitiveById(20));
    258260        assertTrue(r.members.contains(m));
     
    319321        r = (Relation)lookupByName(hull.relations, "r1");
    320322        assertNotNull(r);
    321         assertEquals(3, r.members.size());
     323        assertEquals(3, r.getMembersCount());
    322324        RelationMember m = new RelationMember("node-20", lookupByName(hull.nodes, "n20"));
    323325        assertTrue(r.members.contains(m));
     
    343345        Relation r = (Relation)hull.getPrimitiveById(1);
    344346        assertNotNull(r);
    345         assertEquals(1, r.members.size());
     347        assertEquals(1, r.getMembersCount());
    346348        assertTrue(r.members.contains(new RelationMember("relation-1",r)));
    347349    }
     
    363365        Relation r = (Relation)lookupByName(hull.relations, "r1");
    364366        assertNotNull(r);
    365         assertEquals(1, r.members.size());
     367        assertEquals(1, r.getMembersCount());
    366368        assertTrue(r.members.contains(new RelationMember("relation-1",r)));
    367369    }
     
    387389        r2 = (Relation)hull.getPrimitiveById(2);
    388390        assertNotNull(r2);
    389         assertEquals(1, r1.members.size());
     391        assertEquals(1, r1.getMembersCount());
    390392        assertTrue(r1.members.contains(new RelationMember("relation-2",r2)));
    391         assertEquals(1, r2.members.size());
     393        assertEquals(1, r2.getMembersCount());
    392394        assertTrue(r2.members.contains(new RelationMember("relation-1",r1)));
    393395    }
  • trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/MergeVisitorTest.java

    r1910 r1926  
    972972
    973973        Relation r = (Relation)my.getPrimitiveById(4);
    974         assertEquals(2, r.members.size());
     974        assertEquals(2, r.getMembersCount());
    975975
    976976        Node n = (Node)my.getPrimitiveById(1);
Note: See TracChangeset for help on using the changeset viewer.