Ignore:
Timestamp:
2009-10-11T16:37:08+02:00 (15 years ago)
Author:
jttt
Message:

Replace testing for id <= 0 with isNew() method

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
10 edited

Legend:

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

    r2256 r2273  
    108108        Iterator<OsmPrimitive> it = primitivesToShow.iterator();
    109109        while(it.hasNext()) {
    110             if (it.next().getId() == 0) {
     110            if (it.next().isNew()) {
    111111                it.remove();
    112112            }
  • trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java

    r2256 r2273  
    8181        for (Way w : combinedWays) {
    8282            targetWay = w;
    83             if (w.getId() != 0) {
     83            if (!w.isNew()) {
    8484                break;
    8585            }
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r2256 r2273  
    8989        Node targetNode = null;
    9090        for (Node n: candidates) {
    91             if (n.getId() > 0) {
     91            if (!n.isNew()) {
    9292                targetNode = n;
    9393                break;
  • trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java

    r2070 r2273  
    3636    public boolean doSave() {
    3737        Layer layer = null;
    38         if (layer == null && Main.map != null && (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer
     38        if (Main.map != null && (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer
    3939                || Main.map.mapView.getActiveLayer() instanceof GpxLayer)) {
    4040            layer = Main.map.mapView.getActiveLayer();
     
    140140    private boolean isDataSetEmpty(OsmDataLayer layer) {
    141141        for (OsmPrimitive osm : layer.data.allNonDeletedPrimitives())
    142             if (!osm.isDeleted() || osm.getId() > 0)
     142            if (!osm.isDeleted() || !osm.isNew())
    143143                return false;
    144144        return true;
  • trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java

    r2256 r2273  
    134134     *
    135135     */
    136     class UpdatePrimitivesTask extends PleaseWaitRunnable {
     136    static class UpdatePrimitivesTask extends PleaseWaitRunnable {
    137137        private DataSet ds;
    138138        private boolean canceled;
     
    170170        protected void initMultiFetchReaderWithNodes(MultiFetchServerObjectReader reader) {
    171171            for (OsmPrimitive primitive : toUpdate) {
    172                 if (primitive instanceof Node && primitive.getId() > 0) {
     172                if (primitive instanceof Node && !primitive.isNew()) {
    173173                    reader.append((Node)primitive);
    174174                } else if (primitive instanceof Way) {
    175175                    Way way = (Way)primitive;
    176176                    for (Node node: way.getNodes()) {
    177                         if (node.getId() > 0) {
     177                        if (!node.isNew()) {
    178178                            reader.append(node);
    179179                        }
     
    185185        protected void initMultiFetchReaderWithWays(MultiFetchServerObjectReader reader) {
    186186            for (OsmPrimitive primitive : toUpdate) {
    187                 if (primitive instanceof Way && primitive.getId() > 0) {
     187                if (primitive instanceof Way && !primitive.isNew()) {
    188188                    reader.append((Way)primitive);
    189189                }
     
    193193        protected void initMultiFetchReaderWithRelations(MultiFetchServerObjectReader reader) {
    194194            for (OsmPrimitive primitive : toUpdate) {
    195                 if (primitive instanceof Relation && primitive.getId() > 0) {
     195                if (primitive instanceof Relation && !primitive.isNew()) {
    196196                    reader.append((Relation)primitive);
    197197                }
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r2255 r2273  
    55
    66import java.awt.event.ActionEvent;
    7 import java.awt.event.ActionListener;
    87import java.awt.event.KeyEvent;
    98import java.io.IOException;
     
    1817import java.util.regex.Pattern;
    1918
    20 import javax.swing.JButton;
    21 import javax.swing.JDialog;
    2219import javax.swing.JOptionPane;
    2320
     
    3835import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    3936import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    40 import org.openstreetmap.josm.gui.help.HelpBrowser;
    41 import org.openstreetmap.josm.gui.help.HelpBuilder;
    4237import org.openstreetmap.josm.gui.io.UploadDialog;
    4338import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    5348import org.openstreetmap.josm.tools.ImageProvider;
    5449import org.openstreetmap.josm.tools.Shortcut;
    55 import org.openstreetmap.josm.tools.WindowGeometry;
    5650import org.xml.sax.SAXException;
    5751
     
    234228        String lbl = "";
    235229        switch(primitiveType) {
    236             case NODE: lbl =  tr("Synchronize node {0} only", id); break;
    237             case WAY: lbl =  tr("Synchronize way {0} only", id); break;
    238             case RELATION: lbl =  tr("Synchronize relation {0} only", id); break;
     230        case NODE: lbl =  tr("Synchronize node {0} only", id); break;
     231        case WAY: lbl =  tr("Synchronize way {0} only", id); break;
     232        case RELATION: lbl =  tr("Synchronize relation {0} only", id); break;
    239233        }
    240234        ButtonSpec[] spec = new ButtonSpec[] {
     
    280274        );
    281275        switch(ret) {
    282             case 0: synchronizePrimitive(primitiveType, id); break;
    283             case 1: synchronizeDataSet(); break;
    284             default: return;
     276        case 0: synchronizePrimitive(primitiveType, id); break;
     277        case 1: synchronizeDataSet(); break;
     278        default: return;
    285279        }
    286280    }
  • trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java

    r2256 r2273  
    6868        HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
    6969        for (OsmPrimitive p : ds.nodes) {
    70             if (p.isDeleted() && p.getId() > 0 && p.isVisible() && p.isModified()) {
     70            if (p.isDeleted() && !p.isNew() && p.isVisible() && p.isModified()) {
    7171                ret.add(p);
    7272            }
    7373        }
    7474        for (OsmPrimitive p : ds.ways) {
    75             if (p.isDeleted() && p.getId() > 0 && p.isVisible() && p.isModified()) {
     75            if (p.isDeleted() && !p.isNew() && p.isVisible() && p.isModified()) {
    7676                ret.add(p);
    7777            }
    7878        }
    7979        for (OsmPrimitive p : ds.relations) {
    80             if (p.isDeleted() && p.getId() > 0 && p.isVisible() && p.isModified()) {
     80            if (p.isDeleted() && !p.isNew() && p.isVisible() && p.isModified()) {
    8181                ret.add(p);
    8282            }
     
    8888        HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
    8989        for (OsmPrimitive p: primitives) {
    90             if (p.getId() == 0) {
     90            if (p.isNew()) {
    9191                ret.add(p);
    9292            } else if (p.isVisible() && p.isModified() && !p.incomplete) {
     
    135135    protected boolean hasPrimitivesToDelete(Collection<OsmPrimitive> primitives) {
    136136        for (OsmPrimitive p: primitives)
    137             if (p.isDeleted() && p.isModified() && p.getId() > 0)
     137            if (p.isDeleted() && p.isModified() && !p.isNew())
    138138                return true;
    139139        return false;
     
    188188
    189189        public void visit(Node n) {
    190             if (n.getId() == 0 || ((n.isModified() || n.isDeleted()) && n.isVisible())) {
     190            if (n.isNew() || ((n.isModified() || n.isDeleted()) && n.isVisible())) {
    191191                // upload new nodes as well as modified and deleted ones
    192192                hull.add(n);
     
    195195
    196196        public void visit(Way w) {
    197             if (w.getId() == 0 || ((w.isModified() || w.isDeleted()) && w.isVisible())) {
     197            if (w.isNew() || ((w.isModified() || w.isDeleted()) && w.isVisible())) {
    198198                // upload new ways as well as modified and deleted ones
    199199                hull.add(w);
     
    207207
    208208        public void visit(Relation r) {
    209             if (r.getId() == 0 || ((r.isModified() || r.isDeleted()) && r.isVisible())) {
     209            if (r.isNew() || ((r.isModified() || r.isDeleted()) && r.isVisible())) {
    210210                hull.add(r);
    211211                for (OsmPrimitive p : r.getMemberPrimitives()) {
     
    214214                    // so wont check here for deleted primitives here
    215215                    //
    216                     if (p.getId() == 0) {
     216                    if (p.isNew()) {
    217217                        p.visit(this);
    218218                    }
     
    297297            HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
    298298            for (OsmPrimitive p: toUpload) {
    299                 if (p.isDeleted() && p.getId() >0) {
     299                if (p.isDeleted() && !p.isNew()) {
    300300                    ret.add(p);
    301301                }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java

    r2253 r2273  
    155155        HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
    156156        for (OsmPrimitive primitive : ds.nodes) {
    157             if (!primitive.incomplete && primitive.getId() == 0) {
     157            if (!primitive.incomplete && primitive.isNew()) {
    158158                ret.add(primitive);
    159159            }
    160160        }
    161161        for (OsmPrimitive primitive : ds.ways) {
    162             if (! primitive.incomplete && primitive.getId() == 0) {
     162            if (! primitive.incomplete && primitive.isNew()) {
    163163                ret.add(primitive);
    164164            }
    165165        }
    166166        for (OsmPrimitive primitive : ds.relations) {
    167             if (! primitive.incomplete && primitive.getId() == 0) {
     167            if (! primitive.incomplete && primitive.isNew()) {
    168168                ret.add(primitive);
    169169            }
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r2264 r2273  
    3333    private String  rxErrorMsg = marktr("The regex \"{0}\" had a parse error at offset {1}, full error:\n\n{2}");
    3434    private PushbackTokenizer tokenizer;
    35     private static CollectBackReferencesVisitor childBackRefs;
     35    private CollectBackReferencesVisitor childBackRefs;
    3636
    3737    public SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer) {
     
    230230
    231231            switch (mode) {
    232                 case NONE:
    233                     return false;
    234                 case MISSING_KEY:
    235                     return osm.get(key) == null;
    236                 case ANY:
    237                     return true;
    238                 case ANY_VALUE:
    239                     return osm.get(key) != null;
    240                 case ANY_KEY:
    241                     for (String v:osm.getKeys().values()) {
    242                         if (v.equals(value))
     232            case NONE:
     233                return false;
     234            case MISSING_KEY:
     235                return osm.get(key) == null;
     236            case ANY:
     237                return true;
     238            case ANY_VALUE:
     239                return osm.get(key) != null;
     240            case ANY_KEY:
     241                for (String v:osm.getKeys().values()) {
     242                    if (v.equals(value))
     243                        return true;
     244                }
     245                return false;
     246            case EXACT:
     247                return value.equals(osm.get(key));
     248            case ANY_KEY_REGEXP:
     249                for (String v:osm.getKeys().values()) {
     250                    if (valuePattern.matcher(v).matches())
     251                        return true;
     252                }
     253                return false;
     254            case ANY_VALUE_REGEXP:
     255            case EXACT_REGEXP:
     256                for (Entry<String, String> entry:osm.entrySet()) {
     257                    if (keyPattern.matcher(entry.getKey()).matches()) {
     258                        if (mode == Mode.ANY_VALUE_REGEXP
     259                                || valuePattern.matcher(entry.getValue()).matches())
    243260                            return true;
    244261                    }
    245                     return false;
    246                 case EXACT:
    247                     return value.equals(osm.get(key));
    248                 case ANY_KEY_REGEXP:
    249                     for (String v:osm.getKeys().values()) {
    250                         if (valuePattern.matcher(v).matches())
    251                             return true;
    252                     }
    253                     return false;
    254                 case ANY_VALUE_REGEXP:
    255                 case EXACT_REGEXP:
    256                     for (Entry<String, String> entry:osm.entrySet()) {
    257                         if (keyPattern.matcher(entry.getKey()).matches()) {
    258                             if (mode == Mode.ANY_VALUE_REGEXP
    259                                     || valuePattern.matcher(entry.getValue()).matches())
    260                                 return true;
    261                         }
    262                     }
    263                     return false;
    264                 case MISSING_KEY_REGEXP:
    265                     for (String k:osm.keySet()) {
    266                         if (keyPattern.matcher(k).matches())
    267                             return false;
    268                     }
    269                     return true;
     262                }
     263                return false;
     264            case MISSING_KEY_REGEXP:
     265                for (String k:osm.keySet()) {
     266                    if (keyPattern.matcher(k).matches())
     267                        return false;
     268                }
     269                return true;
    270270            }
    271271            throw new AssertionError("Missed state");
     
    417417    private static class Modified extends Match {
    418418        @Override public boolean match(OsmPrimitive osm) {
    419             return osm.isModified() || osm.getId() == 0;
     419            return osm.isModified() || osm.isNew();
    420420        }
    421421        @Override public String toString() {return "modified";}
     
    473473
    474474    private static class Child extends Match {
    475         private Match parent;
    476         public Child(Match m) { parent = m; }
    477         @Override public boolean match(OsmPrimitive osm) throws ParseError {
     475        private final Match parent;
     476        private final CollectBackReferencesVisitor childBackRefs;
     477
     478        public Child(Match m, CollectBackReferencesVisitor childBackRefs) {
    478479            // "child" (null) should mean the same as "child()"
    479480            // (Always). I.e. match everything
    480             if (parent == null) {
     481            if (m == null) {
    481482                parent = new Always();
    482             }
    483 
     483            } else {
     484                parent = m;
     485            }
     486            this.childBackRefs = childBackRefs;
     487        }
     488
     489        @Override public boolean match(OsmPrimitive osm) throws ParseError {
    484490            boolean isChild = false;
    485491            childBackRefs.initialize();
     
    592598            return new Selected();
    593599        else if (tok.equals("child"))
    594             return new Child(parseParens());
     600            return new Child(parseParens(), childBackRefs);
    595601        else if (tok.equals("parent"))
    596602            return new Parent(parseParens());
  • trunk/src/org/openstreetmap/josm/actions/upload/CyclicUploadDependencyException.java

    r2168 r2273  
    2222        if (r.getName() != null) {
    2323            sb.append("'").append(r.getName()).append("'");
    24         } else if (r.getId() > 0) {
     24        } else if (!r.isNew()) {
    2525            sb.append(r.getId());
    2626        } else {
Note: See TracChangeset for help on using the changeset viewer.