Ignore:
Timestamp:
2009-07-27T21:09:44+02:00 (17 years ago)
Author:
jttt
Message:

Way refactoring - added method that will in future replace public field nodes

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

Legend:

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

    r1762 r1862  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55import static org.openstreetmap.josm.tools.I18n.trn;
    6 
    7 import java.util.HashSet;
    86
    97import java.util.ArrayList;
    108import java.util.Arrays;
    119import java.util.Collection;
     10import java.util.HashSet;
    1211import java.util.List;
    1312
    1413import org.openstreetmap.josm.data.osm.visitor.Visitor;
     14import org.openstreetmap.josm.tools.CopyList;
    1515import org.openstreetmap.josm.tools.Pair;
    1616
     
    2626     */
    2727    public final List<Node> nodes = new ArrayList<Node>();
     28
     29    /**
     30     *
     31     * You can modify returned list but changes will not be propagated back
     32     * to the Way. Use {@link #setNodes(List)} to update this way
     33     * @return Nodes composing the way
     34     * @since 1862
     35     */
     36    public List<Node> getNodes() {
     37        return new CopyList<Node>(nodes.toArray(new Node[nodes.size()]));
     38    }
     39
     40    /**
     41     * @param nodes
     42     * @since 1862
     43     */
     44    public void setNodes(List<Node> nodes) {
     45        this.nodes.clear();
     46        this.nodes.addAll(nodes);
     47    }
     48
     49    /**
     50     *
     51     * @return
     52     * @since 1862
     53     */
     54    public int getNodesCount() {
     55        return nodes.size();
     56    }
     57
     58    /**
     59     *
     60     * @param index
     61     * @return
     62     * @since 1862
     63     */
     64    public Node getNode(int index) {
     65        return nodes.get(index);
     66    }
    2867
    2968    /* mappaint data */
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java

    r1523 r1862  
    66
    77import org.openstreetmap.josm.data.osm.DataSet;
     8import org.openstreetmap.josm.data.osm.Node;
     9import org.openstreetmap.josm.data.osm.OsmPrimitive;
    810import org.openstreetmap.josm.data.osm.Relation;
    911import org.openstreetmap.josm.data.osm.RelationMember;
    10 import org.openstreetmap.josm.data.osm.Node;
    11 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1212import org.openstreetmap.josm.data.osm.Way;
    1313
     
    4747        for (Way w : ds.ways) {
    4848            if (w.deleted || w.incomplete) continue;
    49             for (Node n2 : w.nodes) {
     49            for (Node n2 : w.getNodes()) {
    5050                if (n == n2) {
    5151                    data.add(w);
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1843 r1862  
    2121import java.util.Iterator;
    2222import java.util.LinkedList;
     23import java.util.List;
    2324
    2425import javax.swing.ImageIcon;
     
    162163     */
    163164    public void visit(Way w) {
    164         if(w.nodes.size() < 2)
     165        if(w.getNodesCount() < 2)
    165166        {
    166167            w.mappaintVisibleCode = viewid;
     
    174175        double maxy = -10000;
    175176
    176         for (Node n : w.nodes)
     177        for (Node n : w.getNodes())
    177178        {
    178179            if(n.getEastNorth().east() > maxx) maxx = n.getEastNorth().east();
     
    293294                {
    294295                    lastN = null;
    295                     for(Node n : w.nodes)
     296                    for(Node n : w.getNodes())
    296297                    {
    297298                        if(lastN != null)
     
    308309        /* draw the way */
    309310        lastN = null;
    310         Iterator<Node> it = w.nodes.iterator();
     311        Iterator<Node> it = w.getNodes().iterator();
    311312        while (it.hasNext())
    312313        {
     
    326327                {
    327328                    lastN = null;
    328                     for(Node n : w.nodes)
     329                    for(Node n : w.getNodes())
    329330                    {
    330331                        if(lastN != null)
     
    365366            Way w = null;
    366367            Boolean selected = false;
    367             ArrayList<Node> n = null;
     368            List<Node> n = null;
    368369            Boolean joined = true;
    369370            while(joined && left != 0)
     
    380381                        {
    381382                            int mode = 0;
    382                             int cl = c.nodes.size()-1;
     383                            int cl = c.getNodesCount()-1;
    383384                            int nl;
    384385                            if(n == null)
    385386                            {
    386                                 nl = w.nodes.size()-1;
    387                                 if(w.nodes.get(nl) == c.nodes.get(0)) mode = 21;
    388                                 else if(w.nodes.get(nl) == c.nodes.get(cl)) mode = 22;
    389                                 else if(w.nodes.get(0) == c.nodes.get(0)) mode = 11;
    390                                 else if(w.nodes.get(0) == c.nodes.get(cl)) mode = 12;
     387                                nl = w.getNodesCount()-1;
     388                                if(w.getNode(nl) == c.getNode(0)) mode = 21;
     389                                else if(w.getNode(nl) == c.getNode(cl)) mode = 22;
     390                                else if(w.getNode(0) == c.getNode(0)) mode = 11;
     391                                else if(w.getNode(0) == c.getNode(cl)) mode = 12;
    391392                            }
    392393                            else
    393394                            {
    394395                                nl = n.size()-1;
    395                                 if(n.get(nl) == c.nodes.get(0)) mode = 21;
    396                                 else if(n.get(0) == c.nodes.get(cl)) mode = 12;
    397                                 else if(n.get(0) == c.nodes.get(0)) mode = 11;
    398                                 else if(n.get(nl) == c.nodes.get(cl)) mode = 22;
     396                                if(n.get(nl) == c.getNode(0)) mode = 21;
     397                                else if(n.get(0) == c.getNode(cl)) mode = 12;
     398                                else if(n.get(0) == c.getNode(0)) mode = 11;
     399                                else if(n.get(nl) == c.getNode(cl)) mode = 22;
    399400                            }
    400401                            if(mode != 0)
     
    404405                                if(c.selected) selected = true;
    405406                                --left;
    406                                 if(n == null) n = new ArrayList<Node>(w.nodes);
     407                                if(n == null) n = w.getNodes();
    407408                                n.remove((mode == 21 || mode == 22) ? nl : 0);
    408409                                if(mode == 21)
    409                                     n.addAll(c.nodes);
     410                                    n.addAll(c.getNodes());
    410411                                else if(mode == 12)
    411                                     n.addAll(0, c.nodes);
     412                                    n.addAll(0, c.getNodes());
    412413                                else if(mode == 22)
    413414                                {
    414                                     for(Node node : c.nodes)
     415                                    for(Node node : c.getNodes())
    415416                                        n.add(nl, node);
    416417                                }
    417418                                else /* mode == 11 */
    418419                                {
    419                                     for(Node node : c.nodes)
     420                                    for(Node node : c.getNodes())
    420421                                        n.add(0, node);
    421422                                }
     
    551552                {
    552553                    Way w = (Way) m.member;
    553                     if(w.nodes.size() < 2)
     554                    if(w.getNodesCount() < 2)
    554555                    {
    555556                        r.putError(tr("Way ''{0}'' with less than two points.",
     
    640641        if(fromWay.firstNode() == via) {
    641642            //System.out.println("From way heading away from via");
    642             fromNode = fromWay.nodes.get(1);
     643            fromNode = fromWay.getNode(1);
    643644        } else {
    644645            //System.out.println("From way heading towards via");
    645             fromNode = fromWay.nodes.get(fromWay.nodes.size()-2);
     646            fromNode = fromWay.getNode(fromWay.nodes.size()-2);
    646647        }
    647648
     
    796797                {
    797798                    Way w = (Way) m.member;
    798                     if(w.nodes.size() < 2)
     799                    if(w.getNodesCount() < 2)
    799800                    {
    800801                        r.putError(tr("Way ''{0}'' with less than two points.",
     
    881882                    {
    882883                        way = w;
    883                         for (Node n : w.nodes)
     884                        for (Node n : w.getNodes())
    884885                        {
    885886                            p = nc.getPoint(n);
     
    10591060        Polygon polygon = new Polygon();
    10601061
    1061         for (Node n : w.nodes)
     1062        for (Node n : w.getNodes())
    10621063        {
    10631064            Point p = nc.getPoint(n);
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r1753 r1862  
    77import java.util.HashMap;
    88import java.util.LinkedList;
     9import java.util.List;
    910import java.util.Map;
    1011import java.util.logging.Logger;
     
    5152    /**
    5253     * constructor
    53      * 
     54     *
    5455     * The visitor will merge <code>theirDataSet</code> onto <code>myDataSet</code>
    55      * 
     56     *
    5657     * @param myDataSet  dataset with my primitives
    5758     * @param theirDataSet dataset with their primitives.
     
    7677    /**
    7778     * Merges a primitive <code>other</code> of type <P> onto my primitives.
    78      * 
     79     *
    7980     * If other.id != 0 it tries to merge it with an corresponding primitive from
    8081     * my dataset with the same id. If this is not possible a conflict is remembered
    8182     * in {@see #conflicts}.
    82      * 
     83     *
    8384     * If other.id == 0 it tries to find a primitive in my dataset with id == 0 which
    8485     * is semantically equal. If it finds one it merges its technical attributes onto
    8586     * my primitive.
    86      * 
     87     *
    8788     * @param <P>  the type of the other primitive
    8889     * @param other  the other primitive
     
    171172    private void fixWay(Way w) {
    172173        boolean replacedSomething = false;
    173         LinkedList<Node> newNodes = new LinkedList<Node>();
    174         for (Node myNode : w.nodes) {
     174        List<Node> newNodes = new LinkedList<Node>();
     175        for (Node myNode : w.getNodes()) {
    175176            Node mergedNode = (Node) merged.get(myNode);
    176177            if (mergedNode != null) {
     
    184185        }
    185186        if (replacedSomething) {
    186             w.nodes.clear();
    187             w.nodes.addAll(newNodes);
     187            w.setNodes(newNodes);
    188188        }
    189189    }
     
    310310     * Runs the merge operation. Successfully merged {@see OsmPrimitive}s are in
    311311     * {@see #getMyDataSet()}.
    312      * 
     312     *
    313313     * See {@see #getConflicts()} for a map of conflicts after the merge operation.
    314314     */
     
    322322    /**
    323323     * replies my dataset
    324      * 
     324     *
    325325     * @return
    326326     */
     
    332332    /**
    333333     * replies the map of conflicts
    334      * 
     334     *
    335335     * @return the map of conflicts
    336336     */
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r1725 r1862  
    2020import org.openstreetmap.josm.Main;
    2121import org.openstreetmap.josm.data.osm.DataSet;
    22 import org.openstreetmap.josm.data.osm.RelationMember;
    2322import org.openstreetmap.josm.data.osm.Node;
    2423import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2524import org.openstreetmap.josm.data.osm.Relation;
     25import org.openstreetmap.josm.data.osm.RelationMember;
    2626import org.openstreetmap.josm.data.osm.Way;
    2727import org.openstreetmap.josm.gui.NavigatableComponent;
     
    269269
    270270    public void visitVirtual(Way w) {
    271         Iterator<Node> it = w.nodes.iterator();
     271        Iterator<Node> it = w.getNodes().iterator();
    272272        if (it.hasNext()) {
    273273            Point lastP = nc.getPoint(it.next());
     
    294294     */
    295295    public void visit(Way w) {
    296         if (w.incomplete || w.nodes.size() < 2)
     296        if (w.incomplete || w.getNodesCount() < 2)
    297297            return;
    298298
     
    361361
    362362                boolean first = true;
    363                 for (Node n : ((Way) m.member).nodes) {
     363                for (Node n : ((Way) m.member).getNodes()) {
    364364                    if (n.incomplete || n.deleted) continue;
    365365                    Point p = nc.getPoint(n);
Note: See TracChangeset for help on using the changeset viewer.