Ignore:
Timestamp:
2017-03-15T02:31:32+01:00 (8 years ago)
Author:
donvip
Message:

fix indentation a bit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/DetermineSdsModificationsUploadHook.java

    r32705 r33190  
    5252
    5353        // check modified primitives.
    54            for (OsmPrimitive upd : apiDataSet.getPrimitivesToUpdate()) {
     54        for (OsmPrimitive upd : apiDataSet.getPrimitivesToUpdate()) {
    5555
    56                HashSet<String> allKeys = new HashSet<>();
    57                boolean specialTags = false;
     56           HashSet<String> allKeys = new HashSet<>();
     57           boolean specialTags = false;
    5858
    59                // process tags of new object
    60                for (String key : upd.keySet()) {
    61                    allKeys.add(key);
    62                    if (!specialTags && isSpecialKey(key)) specialTags = true;
     59           // process tags of new object
     60           for (String key : upd.keySet()) {
     61               allKeys.add(key);
     62               if (!specialTags && isSpecialKey(key)) specialTags = true;
     63           }
     64
     65           // process tags of old object
     66           IPrimitive old = plugin.getOriginalPrimitive(upd);
     67           for (String key : old.keySet()) {
     68               allKeys.add(key);
     69              if (!specialTags && isSpecialKey(key)) specialTags = true;
     70           }
     71
     72           // if neither has special tags, done with this object.
     73           if (!specialTags) continue;
     74
     75           // special tags are involved. find out what, exactly, has changed.
     76           boolean changeInSpecialTags = false;
     77           boolean changeInOtherTags = false;
     78           for (String key : allKeys) {
     79               if (old.get(key) == null || upd.get(key) == null || !old.get(key).equals(upd.get(key))) {
     80                   if (isSpecialKey(key)) changeInSpecialTags = true; else changeInOtherTags = true;
     81                   if (changeInSpecialTags && changeInOtherTags) break;
    6382               }
     83           }
    6484
    65                // process tags of old object
    66                IPrimitive old = plugin.getOriginalPrimitive(upd);
    67                for (String key : old.keySet()) {
    68                    allKeys.add(key);
    69                   if (!specialTags && isSpecialKey(key)) specialTags = true;
    70                }
     85           // change *only* in standard tags - done with this object.
     86           if (!changeInSpecialTags) continue;
    7187
    72                // if neither has special tags, done with this object.
    73                if (!specialTags) continue;
     88           // assemble new set of special tags. might turn out to be empty.
     89           HashMap<String, String> newSpecialTags = new HashMap<>();
     90           for (String key : upd.keySet()) {
     91               if (isSpecialKey(key)) newSpecialTags.put(key, upd.get(key));
     92           }
    7493
    75                // special tags are involved. find out what, exactly, has changed.
    76                boolean changeInSpecialTags = false;
    77                boolean changeInOtherTags = false;
    78                for (String key : allKeys) {
    79                    if (old.get(key) == null || upd.get(key) == null || !old.get(key).equals(upd.get(key))) {
    80                        if (isSpecialKey(key)) changeInSpecialTags = true; else changeInOtherTags = true;
    81                        if (changeInSpecialTags && changeInOtherTags) break;
     94           boolean uploadToOsm = changeInOtherTags;
     95
     96           // not done yet: if no changes in standard tags, we need to find out if
     97           // there were changes in the other properties (node: lat/lon, way/relation:
     98           // member list). If the answer is no, then the object must be removed from
     99           // JOSM's normal upload queue, else we would be uploading a non-edit.
     100           if (!changeInOtherTags) {
     101               switch(old.getType()) {
     102               case NODE:
     103                   INode nold = (INode) old;
     104                   INode nupd = (INode) upd;
     105                   uploadToOsm = !(nold.getCoor().equals(nupd.getCoor()));
     106                   break;
     107               case WAY:
     108                   IWay wold = (IWay) old;
     109                   IWay wupd = (IWay) upd;
     110                   if (wold.getNodesCount() != wupd.getNodesCount()) {
     111                       uploadToOsm = true;
     112                       break;
    82113                   }
    83                }
    84 
    85                // change *only* in standard tags - done with this object.
    86                if (!changeInSpecialTags) continue;
    87 
    88                // assemble new set of special tags. might turn out to be empty.
    89                HashMap<String, String> newSpecialTags = new HashMap<>();
    90                for (String key : upd.keySet()) {
    91                    if (isSpecialKey(key)) newSpecialTags.put(key, upd.get(key));
    92                }
    93 
    94                boolean uploadToOsm = changeInOtherTags;
    95 
    96                // not done yet: if no changes in standard tags, we need to find out if
    97                // there were changes in the other properties (node: lat/lon, way/relation:
    98                // member list). If the answer is no, then the object must be removed from
    99                // JOSM's normal upload queue, else we would be uploading a non-edit.
    100                if (!changeInOtherTags) {
    101                    switch(old.getType()) {
    102                    case NODE:
    103                        INode nold = (INode) old;
    104                        INode nupd = (INode) upd;
    105                        uploadToOsm = !(nold.getCoor().equals(nupd.getCoor()));
    106                        break;
    107                    case WAY:
    108                        IWay wold = (IWay) old;
    109                        IWay wupd = (IWay) upd;
    110                        if (wold.getNodesCount() != wupd.getNodesCount()) {
     114                   for (int i = 0; i < wold.getNodesCount(); i++) {
     115                       if (wold.getNodeId(i) != wupd.getNodeId(i)) {
    111116                           uploadToOsm = true;
    112117                           break;
    113118                       }
    114                        for (int i = 0; i < wold.getNodesCount(); i++) {
    115                            if (wold.getNodeId(i) != wupd.getNodeId(i)) {
    116                                uploadToOsm = true;
    117                                break;
    118                            }
    119                        }
     119                   }
     120                   break;
     121               case RELATION:
     122                   IRelation rold = (IRelation) old;
     123                   IRelation rupd = (IRelation) upd;
     124                   if (rold.getMembersCount() != rupd.getMembersCount()) {
     125                       uploadToOsm = true;
    120126                       break;
    121                    case RELATION:
    122                        IRelation rold = (IRelation) old;
    123                        IRelation rupd = (IRelation) upd;
    124                        if (rold.getMembersCount() != rupd.getMembersCount()) {
     127                   }
     128                   for (int i = 0; i < rold.getMembersCount(); i++) {
     129                       if (rold.getMemberType(i) != rupd.getMemberType(i) ||
     130                           rold.getMemberId(i) != rupd.getMemberId(i)) {
    125131                           uploadToOsm = true;
    126132                           break;
    127133                       }
    128                        for (int i = 0; i < rold.getMembersCount(); i++) {
    129                            if (rold.getMemberType(i) != rupd.getMemberType(i) ||
    130                                rold.getMemberId(i) != rupd.getMemberId(i)) {
    131                                uploadToOsm = true;
    132                                break;
    133                            }
    134                        }
    135                        break;
    136                    default: throw new AssertionError("unexpected case: " + old.getType());
    137134                   }
     135                   break;
     136               default: throw new AssertionError("unexpected case: " + old.getType());
    138137               }
     138           }
    139139
    140                // request that new set of special tags be uploaded
    141                plugin.enqueueForUpload(upd, newSpecialTags, !uploadToOsm);
     140           // request that new set of special tags be uploaded
     141           plugin.enqueueForUpload(upd, newSpecialTags, !uploadToOsm);
    142142
    143                // we cannot remove from getPrimitivesToUpdate, this would result in a
    144                // ConcurrentModificationException.
    145                if (!uploadToOsm) droplist.add(upd);
     143           // we cannot remove from getPrimitivesToUpdate, this would result in a
     144           // ConcurrentModificationException.
     145           if (!uploadToOsm) droplist.add(upd);
    146146
    147147        }
     
    149149        apiDataSet.getPrimitivesToUpdate().removeAll(droplist);
    150150
    151            // check added primitives.
    152            for (OsmPrimitive add : apiDataSet.getPrimitivesToAdd()) {
    153                // assemble new set of special tags. might turn out to be empty.
    154                HashMap<String, String> newSpecialTags = new HashMap<>();
    155                for (String key : add.keySet()) {
    156                    if (isSpecialKey(key)) newSpecialTags.put(key, add.get(key));
    157                }
    158                if (!newSpecialTags.isEmpty()) plugin.enqueueForUpload(add, newSpecialTags, false);
     151        // check added primitives.
     152        for (OsmPrimitive add : apiDataSet.getPrimitivesToAdd()) {
     153           // assemble new set of special tags. might turn out to be empty.
     154           HashMap<String, String> newSpecialTags = new HashMap<>();
     155           for (String key : add.keySet()) {
     156               if (isSpecialKey(key)) newSpecialTags.put(key, add.get(key));
     157           }
     158           if (!newSpecialTags.isEmpty()) plugin.enqueueForUpload(add, newSpecialTags, false);
    159159        }
    160160
    161            // FIXME it is possible that the list of OSM edits is totally empty.
     161        // FIXME it is possible that the list of OSM edits is totally empty.
    162162        return true;
    163163
Note: See TracChangeset for help on using the changeset viewer.