Changeset 2396 in josm


Ignore:
Timestamp:
2009-11-07T07:26:15+01:00 (10 years ago)
Author:
Gubaer
Message:

Made nodes, ways, and relations in DataSet private. Plugin updates to be checked in shortly.
Also added setter/getter for DataSet version.

Location:
trunk
Files:
9 edited

Legend:

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

    r2390 r2396  
    229229        String lbl = "";
    230230        switch(primitiveType) {
    231             case NODE: lbl =  tr("Synchronize node {0} only", id); break;
    232             case WAY: lbl =  tr("Synchronize way {0} only", id); break;
    233             case RELATION: lbl =  tr("Synchronize relation {0} only", id); break;
     231        case NODE: lbl =  tr("Synchronize node {0} only", id); break;
     232        case WAY: lbl =  tr("Synchronize way {0} only", id); break;
     233        case RELATION: lbl =  tr("Synchronize relation {0} only", id); break;
    234234        }
    235235        ButtonSpec[] spec = new ButtonSpec[] {
     
    275275        );
    276276        switch(ret) {
    277             case 0: synchronizePrimitive(primitiveType, id); break;
    278             case 1: synchronizeDataSet(); break;
    279             default: return;
     277        case 0: synchronizePrimitive(primitiveType, id); break;
     278        case 1: synchronizeDataSet(); break;
     279        default: return;
    280280        }
    281281    }
     
    635635                    try {
    636636                        getProgressMonitor().subTask(tr("Uploading {0} objects ...", toUpload.size()));
    637                         writer.uploadOsm(layer.data.version, toUpload, changeset, getProgressMonitor().createSubTaskMonitor(1, false));
     637                        writer.uploadOsm(layer.data.getVersion(), toUpload, changeset, getProgressMonitor().createSubTaskMonitor(1, false));
    638638                        processedPrimitives.addAll(writer.getProcessedPrimitives());
    639639                        // if we get here we've successfully uploaded the data. Exit the loop.
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2388 r2396  
    5252     * The API version that created this data set, if any.
    5353     */
    54     public String version;
     54    private String version;
     55
     56    /**
     57     * Replies the API version this dataset was created from. May be null.
     58     *
     59     * @return the API version this dataset was created from. May be null.
     60     */
     61    public String getVersion() {
     62        return version;
     63    }
     64
     65    /**
     66     * Sets the API version this dataset was created from.
     67     *
     68     * @param version the API version, i.e. "0.5" or "0.6"
     69     */
     70    public void setVersion(String version) {
     71        this.version = version;
     72    }
    5573
    5674    /**
    5775     * All nodes goes here, even when included in other data (ways etc). This enables the instant
    5876     * conversion of the whole DataSet by iterating over this data structure.
    59      * @deprecated Use getNodes() for read-only operations, addPrimitive() and removePrimitive() for modifications
    60      */
    61     @Deprecated
    62     public QuadBuckets<Node> nodes = new QuadBuckets<Node>();
    63 
     77     */
     78    private QuadBuckets<Node> nodes = new QuadBuckets<Node>();
     79
     80    /**
     81     * Replies an unmodifiable collection of nodes in this dataset
     82     *
     83     * @return an unmodifiable collection of nodes in this dataset
     84     */
    6485    public Collection<Node> getNodes() {
    6586        return Collections.unmodifiableCollection(nodes);
     
    7495     *
    7596     * The way nodes are stored only in the way list.
    76      * @deprecated Use getWays() for read-only operations, addPrimitive() and removePrimitive() for modifications
    77      */
    78     @Deprecated
    79     public QuadBuckets<Way> ways = new QuadBuckets<Way>();
    80 
     97     */
     98    private QuadBuckets<Way> ways = new QuadBuckets<Way>();
     99
     100    /**
     101     * Replies an unmodifiable collection of ways in this dataset
     102     *
     103     * @return an unmodifiable collection of ways in this dataset
     104     */
    81105    public Collection<Way> getWays() {
    82106        return Collections.unmodifiableCollection(ways);
     
    89113    /**
    90114     * All relations/relationships
    91      * @deprecated Use getRelations() for read-only operations, addPrimitive() and removePrimitive() for modifications
    92      */
    93     @Deprecated
    94     public Collection<Relation> relations = new LinkedList<Relation>();
    95 
     115     */
     116    private Collection<Relation> relations = new LinkedList<Relation>();
     117
     118    /**
     119     * Replies an unmodifiable collection of relations in this dataset
     120     *
     121     * @return an unmodifiable collection of relations in this dataset
     122     */
    96123    public Collection<Relation> getRelations() {
    97124        return Collections.unmodifiableCollection(relations);
     
    703730        }
    704731    }
     732
     733    /**
     734     * Removes all primitives from the dataset and resets the currently selected primitives
     735     * to the empty collection. Also notifies selection change listeners if necessary.
     736     *
     737     */
     738    public void clear() {
     739        if (!selectedPrimitives.isEmpty()) {
     740            selectedPrimitives.clear();
     741            fireSelectionChanged();
     742        }
     743        nodes.clear();
     744        ways.clear();
     745        relations.clear();
     746    }
    705747}
  • trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java

    r2348 r2396  
    1010import org.openstreetmap.josm.data.APIDataSet;
    1111import org.openstreetmap.josm.data.osm.Changeset;
    12 import org.openstreetmap.josm.data.osm.DataSet;
    1312import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1413import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    121120                    ProgressMonitor m = monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false);
    122121                    if (isCancelled()) return;
    123                     writer.uploadOsm(layer.data.version, toUpload, changeset, m);
     122                    writer.uploadOsm(layer.data.getVersion(), toUpload, changeset, m);
    124123                    processedPrimitives.addAll(writer.getProcessedPrimitives());
    125124                    break;
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r2388 r2396  
    256256        tool += trn("{0} way", "{0} ways", ways, ways);
    257257
    258         if (data.version != null) {
    259             tool += ", " + tr("version {0}", data.version);
     258        if (data.getVersion() != null) {
     259            tool += ", " + tr("version {0}", data.getVersion());
    260260        }
    261261        File f = getAssociatedFile();
     
    292292
    293293        // copy the merged layer's API version, downgrade if required
    294         if (data.version == null) {
    295             data.version = from.version;
    296         } else if ("0.5".equals(data.version) ^ "0.5".equals(from.version)) {
     294        if (data.getVersion() == null) {
     295            data.setVersion(from.getVersion());
     296        } else if ("0.5".equals(data.getVersion()) ^ "0.5".equals(from.getVersion())) {
    297297            System.err.println(tr("Warning: mixing 0.6 and 0.5 data results in version 0.5"));
    298             data.version = "0.5";
     298            data.setVersion("0.5");
    299299        }
    300300
     
    522522        p.add(new JLabel(wayText, ImageProvider.get("data", "way"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0));
    523523        p.add(new JLabel(relationText, ImageProvider.get("data", "relation"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0));
    524         p.add(new JLabel(tr("API version: {0}", (data.version != null) ? data.version : tr("unset"))));
     524        p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset"))));
    525525
    526526        return p;
  • trunk/src/org/openstreetmap/josm/io/OsmExporter.java

    r2181 r2396  
    6666            Writer writer = new OutputStreamWriter(out, "UTF-8");
    6767
    68             OsmWriter w = new OsmWriter(new PrintWriter(writer), false, layer.data.version);
     68            OsmWriter w = new OsmWriter(new PrintWriter(writer), false, layer.data.getVersion());
    6969            w.header();
    7070            w.writeDataSources(layer.data);
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r2382 r2396  
    184184                // save generator attribute for later use when creating DataSource objects
    185185                generator = atts.getValue("generator");
    186                 ds.version = v;
     186                ds.setVersion(v);
    187187
    188188            } else if (qName.equals("bounds")) {
     
    348348                    throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.id), version));
    349349                }
    350                 if (ds.version.equals("0.6")){
     350                if (ds.getVersion().equals("0.6")){
    351351                    if (current.version <= 0 && current.id > 0) {
    352352                        throwException(tr("Illegal value for attribute ''version'' on OSM primitive with ID {0}. Got {1}.", Long.toString(current.id), version));
     
    355355                        current.version = 0;
    356356                    }
    357                 } else if (ds.version.equals("0.5")) {
     357                } else if (ds.getVersion().equals("0.5")) {
    358358                    if (current.version <= 0 && current.id > 0) {
    359359                        System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.id, current.version, 1, "0.5"));
     
    365365                } else {
    366366                    // should not happen. API version has been checked before
    367                     throwException(tr("Unknown or unsupported API version. Got {0}.", ds.version));
     367                    throwException(tr("Unknown or unsupported API version. Got {0}.", ds.getVersion()));
    368368                }
    369369            } else {
    370370                // version expected for OSM primitives with an id assigned by the server (id > 0), since API 0.6
    371371                //
    372                 if (current.id > 0 && ds.version != null && ds.version.equals("0.6")) {
     372                if (current.id > 0 && ds.getVersion() != null && ds.getVersion().equals("0.6")) {
    373373                    throwException(tr("Missing attribute ''version'' on OSM primitive with ID {0}.", Long.toString(current.id)));
    374                 } else if (current.id > 0 && ds.version != null && ds.version.equals("0.5")) {
     374                } else if (current.id > 0 && ds.getVersion() != null && ds.getVersion().equals("0.5")) {
    375375                    // default version in 0.5 files for existing primitives
    376376                    System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.id, current.version, 1, "0.5"));
    377377                    current.version= 1;
    378                 } else if (current.id <= 0 && ds.version != null && ds.version.equals("0.5")) {
     378                } else if (current.id <= 0 && ds.getVersion() != null && ds.getVersion().equals("0.5")) {
    379379                    // default version in 0.5 files for new primitives
    380380                    System.out.println(tr("WARNING: Normalizing value of attribute ''version'' of element {0} to {2}, API version is ''{3}''. Got {1}.", current.id, current.version, 0, "0.5"));
  • trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java

    r2388 r2396  
    4545    protected static DataSet buildTestDataSet() {
    4646        DataSet ds = new DataSet();
    47         ds.version = "0.6";
     47        ds.setVersion("0.6");
    4848
    4949        int numNodes = 1000;
     
    215215        }
    216216        logger.info(MessageFormat.format("caching test data set in ''{0}'' ...", dataSetCacheOutputFile.toString()));
    217         OsmWriter w = new OsmWriter(pw, false, testDataSet.version);
     217        OsmWriter w = new OsmWriter(pw, false, testDataSet.getVersion());
    218218        w.header();
    219219        w.writeDataSources(testDataSet);
  • trunk/test/functional/org/openstreetmap/josm/io/OsmServerBackreferenceReaderTest.java

    r2381 r2396  
    109109    protected static DataSet buildTestDataSet() {
    110110        DataSet ds = new DataSet();
    111         ds.version = "0.6";
     111        ds.setVersion("0.6");
    112112
    113113        populateTestDataSetWithNodes(ds);
     
    221221        }
    222222        logger.info(MessageFormat.format("caching test data set in ''{0}'' ...", dataSetCacheOutputFile.toString()));
    223         OsmWriter w = new OsmWriter(pw, false, testDataSet.version);
     223        OsmWriter w = new OsmWriter(pw, false, testDataSet.getVersion());
    224224        w.header();
    225225        w.writeDataSources(testDataSet);
  • trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/MergeVisitorTest.java

    r2381 r2396  
    7979    public void nodeSimple_IdenticalNoConflict() {
    8080        DataSet my = new DataSet();
    81         my.version = "0.6";
     81        my.setVersion("0.6");
    8282        Node n = new Node(new LatLon(0,0));
    8383        n.setOsmId(1,1);
     
    8787
    8888        DataSet their = new DataSet();
    89         their.version = "0.6";
     89        their.setVersion("0.6");
    9090        Node n1 = new Node(new LatLon(0,0));
    9191        n1.setOsmId(1,1);
     
    114114    public void nodeSimple_locallyUnmodifiedNoConflict() {
    115115        DataSet my = new DataSet();
    116         my.version = "0.6";
     116        my.setVersion("0.6");
    117117        Node n = new Node(new LatLon(0,0));
    118118        n.setOsmId(1,1);
     
    122122
    123123        DataSet their = new DataSet();
    124         their.version = "0.6";
     124        their.setVersion("0.6");
    125125        Node n1 = new Node(new LatLon(0,0));
    126126        n1.setOsmId(1,2);
     
    153153    public void nodeSimple_TagConflict() {
    154154        DataSet my = new DataSet();
    155         my.version = "0.6";
     155        my.setVersion("0.6");
    156156        Node n = new Node(new LatLon(0,0));
    157157        n.setOsmId(1,1);
     
    162162
    163163        DataSet their = new DataSet();
    164         their.version = "0.6";
     164        their.setVersion("0.6");
    165165        Node n1 = new Node(new LatLon(0,0));
    166166        n1.setOsmId(1,2);
     
    189189    public void nodeSimple_DeleteConflict() {
    190190        DataSet my = new DataSet();
    191         my.version = "0.6";
     191        my.setVersion("0.6");
    192192        Node n = new Node(1);
    193193        n.setCoor(new LatLon(0,0));
     
    198198
    199199        DataSet their = new DataSet();
    200         their.version = "0.6";
     200        their.setVersion("0.6");
    201201        Node n1 = new Node(new LatLon(0,0));
    202202        n1.setOsmId(1,1);
     
    223223    public void nodeSimple_VisibleConflict() {
    224224        DataSet my = new DataSet();
    225         my.version = "0.6";
     225        my.setVersion("0.6");
    226226        Node n = new Node(new LatLon(0,0));
    227227        n.setOsmId(1,1);
     
    231231
    232232        DataSet their = new DataSet();
    233         their.version = "0.6";
     233        their.setVersion("0.6");
    234234        Node n1 = new Node(new LatLon(0,0));
    235235        n1.setOsmId(1,2);
     
    256256    public void nodeSimple_DeleteConflict_2() {
    257257        DataSet my = new DataSet();
    258         my.version = "0.6";
     258        my.setVersion("0.6");
    259259        Node n = new Node(new LatLon(0,0));
    260260        n.setOsmId(1,1);
     
    263263
    264264        DataSet their = new DataSet();
    265         their.version = "0.6";
     265        their.setVersion("0.6");
    266266        Node n1 = new Node(new LatLon(0,0));
    267267        n1.setOsmId(1,1);
     
    286286    public void nodeSimple_DeleteConflict_3() {
    287287        DataSet my = new DataSet();
    288         my.version = "0.6";
     288        my.setVersion("0.6");
    289289        Node n = new Node(new LatLon(1,1));
    290290        n.setDeleted(true);
     
    292292
    293293        DataSet their = new DataSet();
    294         their.version = "0.6";
     294        their.setVersion("0.6");
    295295        Node n1 = new Node(new LatLon(1,1));
    296296        their.addPrimitive(n1);
     
    312312    public void nodeSimple_DeleteConflict_4() {
    313313        DataSet my = new DataSet();
    314         my.version = "0.6";
     314        my.setVersion("0.6");
    315315        Node n = new Node(new LatLon(1,1));
    316316        n.setDeleted(true);
     
    318318
    319319        DataSet their = new DataSet();
    320         their.version = "0.6";
     320        their.setVersion("0.6");
    321321        Node n1 = new Node(new LatLon(1,1));
    322322        n1.setDeleted(true);
     
    338338    public void nodeSimple_InvisibleNodeInTheirDataset() {
    339339        DataSet my = new DataSet();
    340         my.version = "0.6";
     340        my.setVersion("0.6");
    341341        Node n = new Node(new LatLon(0,0));
    342342        n.setOsmId(1,1);
     
    345345
    346346        DataSet their = new DataSet();
    347         their.version = "0.6";
     347        their.setVersion("0.6");
    348348        Node n1 = new Node(new LatLon(0,0));
    349349        n1.setOsmId(2,1);
     
    377377
    378378        DataSet my = new DataSet();
    379         my.version = "0.6";
     379        my.setVersion("0.6");
    380380        Node n = new Node();
    381381        n.setCoor(new LatLon(0,0));
     
    387387
    388388        DataSet their = new DataSet();
    389         their.version = "0.6";
     389        their.setVersion("0.6");
    390390        Node n1 = new Node();
    391391        n1.setCoor(new LatLon(0,0));
     
    418418
    419419        DataSet my = new DataSet();
    420         my.version = "0.6";
     420        my.setVersion("0.6");
    421421        Node n = new Node();
    422422        n.setCoor(new LatLon(0,0));
     
    426426
    427427        DataSet their = new DataSet();
    428         their.version = "0.6";
     428        their.setVersion("0.6");
    429429        Node n1 = new Node();
    430430        n1.setCoor(new LatLon(0,0));
     
    458458
    459459        DataSet my = new DataSet();
    460         my.version = "0.6";
     460        my.setVersion("0.6");
    461461
    462462        Node n1 = new Node();
     
    480480
    481481        DataSet their = new DataSet();
    482         their.version = "0.6";
     482        their.setVersion("0.6");
    483483
    484484        Node n3 = new Node(new LatLon(0,0));
     
    525525
    526526        DataSet my = new DataSet();
    527         my.version = "0.6";
     527        my.setVersion("0.6");
    528528
    529529        Node n1 = new Node(new LatLon(0,0));
     
    542542
    543543        DataSet their = new DataSet();
    544         their.version = "0.6";
     544        their.setVersion("0.6");
    545545
    546546        Node n3 = new Node(new LatLon(0,0));
     
    593593
    594594        DataSet my = new DataSet();
    595         my.version = "0.6";
     595        my.setVersion("0.6");
    596596
    597597        Node n1 = new Node(new LatLon(0,0));
     
    613613
    614614        DataSet their = new DataSet();
    615         their.version = "0.6";
     615        their.setVersion("0.6");
    616616
    617617        Node n3 = new Node(new LatLon(0,0));
     
    664664
    665665        DataSet my = new DataSet();
    666         my.version = "0.6";
     666        my.setVersion("0.6");
    667667
    668668        Node n1 = new Node(new LatLon(0,0));
     
    681681
    682682        DataSet their = new DataSet();
    683         their.version = "0.6";
     683        their.setVersion("0.6");
    684684
    685685        Way theirWay = new Way();
     
    710710
    711711        DataSet my = new DataSet();
    712         my.version = "0.6";
     712        my.setVersion("0.6");
    713713
    714714        Node n1 = new Node(new LatLon(0,0));
     
    726726
    727727        DataSet their = new DataSet();
    728         their.version = "0.6";
     728        their.setVersion("0.6");
    729729
    730730        Node n3 = new Node(new LatLon(0,0));
     
    763763
    764764        DataSet my = new DataSet();
    765         my.version = "0.6";
     765        my.setVersion("0.6");
    766766
    767767        Node n1 = new Node(new LatLon(0,0));
     
    777777
    778778        DataSet their = new DataSet();
    779         their.version = "0.6";
     779        their.setVersion("0.6");
    780780
    781781        Node n3 = new Node(new LatLon(0,0));
     
    815815
    816816        DataSet my = new DataSet();
    817         my.version = "0.6";
     817        my.setVersion("0.6");
    818818
    819819        Node n1 = new Node(new LatLon(0,0));
     
    823823
    824824        DataSet their = new DataSet();
    825         their.version = "0.6";
     825        their.setVersion("0.6");
    826826
    827827        Node n3 = new Node(new LatLon(0,0));
     
    871871
    872872        DataSet my = new DataSet();
    873         my.version = "0.6";
     873        my.setVersion("0.6");
    874874
    875875        Node n1 = new Node(new LatLon(0,0));
     
    879879
    880880        DataSet their = new DataSet();
    881         their.version = "0.6";
     881        their.setVersion("0.6");
    882882
    883883        Node n3 = new Node(new LatLon(0,0));
     
    922922    public void newIncompleteWay() {
    923923        DataSet their = new DataSet();
    924         their.version = "0.6";
     924        their.setVersion("0.6");
    925925
    926926        Node n1 = new Node(1);
     
    936936
    937937        DataSet my = new DataSet();
    938         their.version = "0.6";
     938        their.setVersion("0.6");
    939939
    940940        MergeVisitor visitor = new MergeVisitor(my,their);
     
    969969    public void incompleteWayOntoCompleteWay() {
    970970        DataSet their = new DataSet();
    971         their.version = "0.6";
     971        their.setVersion("0.6");
    972972
    973973        // an incomplete node
     
    986986
    987987        DataSet my = new DataSet();
    988         their.version = "0.6";
     988        their.setVersion("0.6");
    989989
    990990        Node n4 = new Node(new LatLon(0,0));
Note: See TracChangeset for help on using the changeset viewer.