Changeset 1951 in josm


Ignore:
Timestamp:
2009-08-10T20:36:40+02:00 (15 years ago)
Author:
jttt
Message:

Replace some occurrences of RelationMember.member with getters

Location:
trunk
Files:
16 edited

Legend:

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

    r1937 r1951  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
     9import java.util.ArrayList;
    910import java.util.Collection;
    1011import java.util.HashMap;
     
    225226        // modify all relations containing the now-deleted ways
    226227        for (Relation r : relationsUsingWays) {
    227             Relation newRel = new Relation(r);
    228             newRel.members.clear();
     228            List<RelationMember> newMembers = new ArrayList<RelationMember>();
    229229            HashSet<String> rolesToReAdd = new HashSet<String>();
    230230            for (RelationMember rm : r.getMembers()) {
     
    234234                    rolesToReAdd.add(rm.getRole());
    235235                } else {
    236                     newRel.members.add(rm);
     236                    newMembers.add(rm);
    237237                }
    238238            }
    239239            for (String role : rolesToReAdd) {
    240                 newRel.members.add(new RelationMember(role, modifyWay));
    241             }
     240                newMembers.add(new RelationMember(role, modifyWay));
     241            }
     242            Relation newRel = new Relation(r);
     243            newRel.setMembers(newMembers);
    242244            cmds.add(new ChangeCommand(r, newRel));
    243245        }
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r1937 r1951  
    1212import java.util.HashSet;
    1313import java.util.LinkedList;
     14import java.util.List;
    1415import java.util.Map;
    1516import java.util.Set;
     
    275276        // modify all relations containing the now-deleted nodes
    276277        for (Relation r : relationsUsingNodes) {
    277             Relation newRel = new Relation(r);
    278             newRel.members.clear();
     278            List<RelationMember> newMembers = new ArrayList<RelationMember>();
    279279            HashSet<String> rolesToReAdd = new HashSet<String>();
    280280            for (RelationMember rm : r.getMembers()) {
     
    284284                    rolesToReAdd.add(rm.getRole());
    285285                } else {
    286                     newRel.members.add(rm);
     286                    newMembers.add(rm);
    287287                }
    288288            }
    289289            for (String role : rolesToReAdd) {
    290                 newRel.members.add(new RelationMember(role, dest));
    291             }
     290                newMembers.add(new RelationMember(role, dest));
     291            }
     292            Relation newRel = new Relation(r);
     293            newRel.setMembers(newMembers);
    292294            cmds.add(new ChangeCommand(r, newRel));
    293295        }
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r1938 r1951  
    326326                            j++;
    327327                            if (backwards) {
    328                                 c.members.add(i, em);
     328                                c.addMember(i, em);
    329329                            } else {
    330                                 c.members.add(j, em);
     330                                c.addMember(j, em);
    331331                            }
    332332                        }
  • trunk/src/org/openstreetmap/josm/command/RelationMemberConflictResolverCommand.java

    r1750 r1951  
    4040
    4141    /**
    42      * 
     42     *
    4343     * @param my my relation
    4444     * @param their their relation
     
    7272        // nodes
    7373        //
    74         my.members.clear();
    75         for (int i=0; i<mergedMembers.size();i++) {
    76             RelationMember n = mergedMembers.get(i);
    77             my.members.add(n);
    78         }
     74        my.setMembers(mergedMembers);
    7975
    8076        // remember the layer
    81         layer = Main.main.map.mapView.getEditLayer();
     77        layer = Main.map.mapView.getEditLayer();
    8278        return true;
    8379    }
  • trunk/src/org/openstreetmap/josm/command/RemoveRelationMemberCommand.java

    r1814 r1951  
    4444    @Override public boolean executeCommand() {
    4545        super.executeCommand();
    46         int removed_at = relation.members.indexOf(member);
    47         relation.members.remove(member);
    48         if ((location != -1) && (removed_at != location)) {
    49             relation.members.add(removed_at, member);
     46        int removeIndex = relation.getMembers().indexOf(member);
     47        if ((location != -1) && (removeIndex != location)) {
    5048            Main.debug("error removing relation member");
    5149            return false;
     50        } else {
     51            relation.removeMember(removeIndex);
     52            relation.modified = true;
     53            return true;
    5254        }
    53         relation.modified = true;
    54         return true;
    5555    }
    5656
    5757    @Override public void undoCommand() {
    5858        super.undoCommand();
    59         relation.members.add(member);
     59        relation.addMember(member);
    6060        relation.modified = this.getOrig(relation).modified;
    6161    }
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r1926 r1951  
    6363    public RelationMember getMember(int index) {
    6464        return members.get(index);
     65    }
     66
     67    /**
     68     *
     69     * @param member
     70     * @since 1951
     71     */
     72    public void addMember(RelationMember member) {
     73        members.add(member);
     74    }
     75
     76    /**
     77     *
     78     * @param index
     79     * @param member
     80     * @since 1951
     81     */
     82    public void addMember(int index, RelationMember member) {
     83        members.add(index, member);
     84    }
     85
     86    /**
     87     * Replace member at position specified by index.
     88     * @param index
     89     * @param member
     90     * @return Member that was at the position
     91     * @since 1951
     92     */
     93    public RelationMember setMember(int index, RelationMember member) {
     94        return members.set(index, member);
     95    }
     96
     97    /**
     98     * Removes member at specified position.
     99     * @param index
     100     * @return Member that was at the position
     101     * @since 1951
     102     */
     103    public RelationMember removeMember(int index) {
     104        return members.remove(index);
    65105    }
    66106
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeSourceBuildingVisitor.java

    r1937 r1951  
    9090            clone = new Relation(r);
    9191        }
    92         clone.members.clear();
     92
     93        List<RelationMember> newMembers = new ArrayList<RelationMember>();
    9394        for (RelationMember member: r.getMembers()) {
    94             RelationMember cloneMember = new RelationMember(member.getRole(), mappedPrimitives.get(member.getMember()));
    95             clone.members.add(cloneMember);
    96         }
     95            newMembers.add(
     96                new RelationMember(member.getRole(), mappedPrimitives.get(member.getMember())));
     97
     98        }
     99        clone.setMembers(newMembers);
     100
    97101        if (! mappedPrimitives.keySet().contains(r)) {
    98102            mappedPrimitives.put(r, clone);
     
    104108            return;
    105109        Relation clone = new Relation(r);
    106         clone.members.clear();
     110        clone.setMembers(null);
    107111        mappedPrimitives.put(r, clone);
    108112    }
     
    148152            clone = new Relation(r);
    149153        }
    150         clone.members.clear();
     154        clone.setMembers(null);
    151155        clone.incomplete = true;
    152156        if (! isAlreadyRemembered(r)) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r1945 r1951  
    854854            Relation rel = new Relation(cur);
    855855            Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
     856            int index = 0;
    856857            for (RelationMember rm : cur.getMembers()) {
    857858                for (OsmPrimitive osm : sel) {
    858859                    if (rm.getMember() == osm)
    859860                    {
    860                         rel.members.remove(rm);
     861                        rel.removeMember(index);
    861862                        break;
    862863                    }
    863864                }
     865                index++;
    864866            }
    865867            Main.main.undoRedo.add(new ChangeCommand(cur, rel));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r1937 r1951  
    229229        if (relation == null)
    230230            return false;
    231         if (relation.members.size() != members.size())
     231        if (relation.getMembersCount() != members.size())
    232232            return false;
    233         for (int i = 0; i < relation.members.size(); i++) {
    234             if (!relation.members.get(i).equals(members.get(i)))
     233        for (int i = 0; i < relation.getMembersCount(); i++) {
     234            if (!relation.getMember(i).equals(members.get(i)))
    235235                return false;
    236236        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationTreeModel.java

    r1938 r1951  
    5757        if (members == null) return;
    5858        Relation root = new Relation();
    59         root.members.addAll(members);
     59        root.setMembers(members);
    6060        this.root = root;
    6161        listeners = new CopyOnWriteArrayList<TreeModelListener>();
     
    150150        if (members == null) return;
    151151        Relation r = new Relation();
    152         r.members.addAll(members);
     152        r.setMembers(members);
    153153        this.root = r;
    154154        fireRootReplacedEvent();
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r1928 r1951  
    412412            if (en == null) throw new Error("Failed to create relation " + e.getKey().id);
    413413
     414            List<RelationMember> relationMembers = new ArrayList<RelationMember>();
     415
    414416            for (RelationMemberData emd : e.getValue()) {
    415417                OsmPrimitive member;
     
    438440                    throw new SAXException(tr("Unknown relation member type {0}", emd.type));
    439441                }
    440                 en.members.add(new RelationMember(emd.role, member));
    441             }
     442                relationMembers.add(new RelationMember(emd.role, member));
     443            }
     444            en.setMembers(relationMembers);
    442445        }
    443446        hm = null;
  • trunk/test/functional/org/openstreetmap/josm/gui/conflict/relation/RelationMemberMergerTest.java

    r1707 r1951  
    1010import org.openstreetmap.josm.data.osm.RelationMember;
    1111import org.openstreetmap.josm.data.osm.Way;
    12 import org.openstreetmap.josm.gui.conflict.nodes.NodeListMerger;
    13 import org.openstreetmap.josm.gui.conflict.nodes.NodeListMergerTest;
    1412
    1513public class RelationMemberMergerTest extends JFrame {
    16    
     14
    1715    private RelationMemberMerger merger;
    18    
     16
    1917    protected void populate() {
    2018        Relation r1 = new Relation();
    21         r1.members.add(new RelationMember("role1", new Node(1)));
    22         r1.members.add(new RelationMember("role2", new Way(2)));
    23         r1.members.add(new RelationMember("role3", new Relation(3)));
     19        r1.addMember(new RelationMember("role1", new Node(1)));
     20        r1.addMember(new RelationMember("role2", new Way(2)));
     21        r1.addMember(new RelationMember("role3", new Relation(3)));
    2422
    25        
     23
    2624        Relation r2 = new Relation();
    27         r2.members.add(new RelationMember("role1", new Node(1)));
    28         r2.members.add(new RelationMember("role2", new Way(2)));
    29         r2.members.add(new RelationMember("role3", new Relation(3)));
    30        
     25        r2.addMember(new RelationMember("role1", new Node(1)));
     26        r2.addMember(new RelationMember("role2", new Way(2)));
     27        r2.addMember(new RelationMember("role3", new Relation(3)));
     28
    3129        merger.populate(r1, r2);
    3230
    3331    }
    34    
     32
    3533    protected void build() {
    3634        merger = new RelationMemberMerger();
     
    3836        getContentPane().add(merger, BorderLayout.CENTER);
    3937    }
    40    
     38
    4139    public RelationMemberMergerTest() {
    4240        build();
    4341        populate();
    4442    }
    45    
     43
    4644    static public void main(String args[]) {
    4745        RelationMemberMergerTest test = new RelationMemberMergerTest();
  • trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java

    r1928 r1951  
    9595                int idx = (start + j) % 500;
    9696                Node n = nodes.get(idx);
    97                 r.members.add(new RelationMember("role-" + j, n));
     97                r.addMember(new RelationMember("role-" + j, n));
    9898            }
    9999            int numWaysInRelation = (int)Math.round(Math.random() * 10);
     
    102102                int idx = (start + j) % 500;
    103103                Way w = ways.get(idx);
    104                 r.members.add(new RelationMember("role-" + j, w));
     104                r.addMember(new RelationMember("role-" + j, w));
    105105            }
    106106            ds.addPrimitive(r);
     
    288288            Relation r2 = (Relation)ds.getPrimitiveById(r1.id);
    289289            assertNotNull(r2);
    290             assertEquals(r2.members.size(), r1.members.size());
     290            assertEquals(r2.getMembersCount(), r1.getMembersCount());
    291291            assertEquals(r2.get("name"),r2.get("name"));
    292292        }
  • trunk/test/functional/org/openstreetmap/josm/io/OsmServerBackreferenceReaderTest.java

    r1938 r1951  
    8888            for (int j =0; j < 10; j++) {
    8989                RelationMember member = new RelationMember("node-" + j, lookupNode(ds, i + j));
    90                 r.members.add(member);
     90                r.addMember(member);
    9191            }
    9292            for (int j =0; j < 5; j++) {
    9393                RelationMember member = new RelationMember("way-" + j, lookupWay(ds, i + j));
    94                 r.members.add(member);
     94                r.addMember(member);
    9595            }
    9696            if (i > 5) {
     
    9898                    RelationMember member = new RelationMember("relation-" + j, lookupRelation(ds, j));
    9999                    logger.info(MessageFormat.format("adding relation {0} to relation {1}", j, i));
    100                     r.members.add(member);
     100                    r.addMember(member);
    101101                }
    102102            }
  • trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/MergeSourceBuildingVisitorTest.java

    r1926 r1951  
    153153        Relation r1 = new Relation(1);
    154154        Node n20 = new Node(20);
    155         r1.members.add(new RelationMember("node-20",n20));
     155        r1.addMember(new RelationMember("node-20",n20));
    156156        Way w30 = new Way(30);
    157157        Node n21;
     
    159159        Node n22;
    160160        w30.addNode(n22 = new Node(22));
    161         r1.members.add(new RelationMember("way-30",w30));
     161        r1.addMember(new RelationMember("way-30",w30));
    162162        Relation r40 = new Relation(40);
    163         r1.members.add(new RelationMember("relation-40", r40));
     163        r1.addMember(new RelationMember("relation-40", r40));
    164164        source.nodes.add(n20);
    165165        source.nodes.add(n21);
     
    199199        assertEquals(3, r.getMembersCount());
    200200        RelationMember m = new RelationMember("node-20", hull.getPrimitiveById(20));
    201         assertTrue(r.members.contains(m));
     201        assertTrue(r.getMembers().contains(m));
    202202        m = new RelationMember("way-30", hull.getPrimitiveById(30));
    203         assertTrue(r.members.contains(m));
     203        assertTrue(r.getMembers().contains(m));
    204204        m = new RelationMember("relation-40", hull.getPrimitiveById(40));
    205         assertTrue(r.members.contains(m));
     205        assertTrue(r.getMembers().contains(m));
    206206    }
    207207
     
    211211        Relation r1 = new Relation(1);
    212212        Node n20 = new Node(20);
    213         r1.members.add(new RelationMember("node-20",n20));
     213        r1.addMember(new RelationMember("node-20",n20));
    214214        Way w30 = new Way(30);
    215215        Node n21;
     
    217217        Node n22;
    218218        w30.addNode(n22 = new Node(22));
    219         r1.members.add(new RelationMember("way-30",w30));
     219        r1.addMember(new RelationMember("way-30",w30));
    220220        Relation r40 = new Relation(40);
    221         r1.members.add(new RelationMember("relation-40", r40));
     221        r1.addMember(new RelationMember("relation-40", r40));
    222222        source.nodes.add(n20);
    223223        source.nodes.add(n21);
     
    258258        assertEquals(3, r.getMembersCount());
    259259        RelationMember m = new RelationMember("node-20", hull.getPrimitiveById(20));
    260         assertTrue(r.members.contains(m));
     260        assertTrue(r.getMembers().contains(m));
    261261        m = new RelationMember("way-30", hull.getPrimitiveById(30));
    262         assertTrue(r.members.contains(m));
     262        assertTrue(r.getMembers().contains(m));
    263263        m = new RelationMember("relation-40", hull.getPrimitiveById(40));
    264         assertTrue(r.members.contains(m));
     264        assertTrue(r.getMembers().contains(m));
    265265    }
    266266
     
    272272        Node n20 = new Node(new LatLon(20.0,20.0));
    273273        n20.put("name", "n20");
    274         r1.members.add(new RelationMember("node-20",n20));
     274        r1.getMembers().add(new RelationMember("node-20",n20));
    275275        Way w30 = new Way();
    276276        w30.put("name", "w30");
     
    281281        w30.addNode(n22 = new Node(new LatLon(22.0,22.0)));
    282282        n22.put("name","n22");
    283         r1.members.add(new RelationMember("way-30",w30));
     283        r1.addMember(new RelationMember("way-30",w30));
    284284        Relation r40 = new Relation();
    285285        r40.put("name", "r40");
    286         r1.members.add(new RelationMember("relation-40", r40));
     286        r1.addMember(new RelationMember("relation-40", r40));
    287287        source.nodes.add(n20);
    288288        source.nodes.add(n21);
     
    323323        assertEquals(3, r.getMembersCount());
    324324        RelationMember m = new RelationMember("node-20", lookupByName(hull.nodes, "n20"));
    325         assertTrue(r.members.contains(m));
     325        assertTrue(r.getMembers().contains(m));
    326326        m = new RelationMember("way-30", lookupByName(hull.ways, "w30"));
    327         assertTrue(r.members.contains(m));
     327        assertTrue(r.getMembers().contains(m));
    328328        m = new RelationMember("relation-40", lookupByName(hull.relations, "r40"));
    329         assertTrue(r.members.contains(m));
     329        assertTrue(r.getMembers().contains(m));
    330330    }
    331331
     
    334334        DataSet source = new DataSet();
    335335        Relation r1 = new Relation(1);
    336         r1.members.add(new RelationMember("relation-1",r1));
     336        r1.addMember(new RelationMember("relation-1",r1));
    337337        source.relations.add(r1);
    338338        source.setSelected(r1);
     
    346346        assertNotNull(r);
    347347        assertEquals(1, r.getMembersCount());
    348         assertTrue(r.members.contains(new RelationMember("relation-1",r)));
     348        assertTrue(r.getMembers().contains(new RelationMember("relation-1",r)));
    349349    }
    350350
     
    354354        Relation r1 = new Relation();
    355355        r1.put("name", "r1");
    356         r1.members.add(new RelationMember("relation-1",r1));
     356        r1.addMember(new RelationMember("relation-1",r1));
    357357        source.relations.add(r1);
    358358        source.setSelected(r1);
     
    366366        assertNotNull(r);
    367367        assertEquals(1, r.getMembersCount());
    368         assertTrue(r.members.contains(new RelationMember("relation-1",r)));
     368        assertTrue(r.getMembers().contains(new RelationMember("relation-1",r)));
    369369    }
    370370
     
    374374        Relation r1 = new Relation(1);
    375375        Relation r2 = new Relation(2);
    376         r1.members.add(new RelationMember("relation-2",r2));
    377         r2.members.add(new RelationMember("relation-1",r1));
     376        r1.addMember(new RelationMember("relation-2",r2));
     377        r2.addMember(new RelationMember("relation-1",r1));
    378378        source.relations.add(r1);
    379379        source.relations.add(r2);
     
    390390        assertNotNull(r2);
    391391        assertEquals(1, r1.getMembersCount());
    392         assertTrue(r1.members.contains(new RelationMember("relation-2",r2)));
     392        assertTrue(r1.getMembers().contains(new RelationMember("relation-2",r2)));
    393393        assertEquals(1, r2.getMembersCount());
    394         assertTrue(r2.members.contains(new RelationMember("relation-1",r1)));
     394        assertTrue(r2.getMembers().contains(new RelationMember("relation-1",r1)));
    395395    }
    396396}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/MergeVisitorTest.java

    r1948 r1951  
    965965        theirRelation.id = 4;
    966966        theirRelation.version = 1;
    967         theirRelation.members.add(new RelationMember("", n3));
    968         theirRelation.members.add(new RelationMember("", n4));
    969         theirRelation.members.add(new RelationMember("", n5));
     967        theirRelation.addMember(new RelationMember("", n3));
     968        theirRelation.addMember(new RelationMember("", n4));
     969        theirRelation.addMember(new RelationMember("", n5));
    970970        their.addPrimitive(theirRelation);
    971971
Note: See TracChangeset for help on using the changeset viewer.