Ignore:
Timestamp:
2013-09-25T02:56:42+02:00 (11 years ago)
Author:
Don-vip
Message:

Sonar/Findbugs - Performance - Inefficient use of keySet iterator instead of entrySet iterator

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

Legend:

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

    r6130 r6258  
    1212import java.util.List;
    1313import java.util.Map;
    14 
     14import java.util.Map.Entry;
    1515import java.util.Set;
    1616import java.util.TreeSet;
     17
    1718import javax.swing.JOptionPane;
    18 
    1919import javax.swing.SwingUtilities;
     20
    2021import org.openstreetmap.josm.Main;
    2122import org.openstreetmap.josm.command.AddCommand;
     
    5152public class CreateMultipolygonAction extends JosmAction {
    5253
     54    /**
     55     * Constructs a new {@code CreateMultipolygonAction}.
     56     */
    5357    public CreateMultipolygonAction() {
    5458        super(tr("Create multipolygon"), "multipoly_create", tr("Create multipolygon."),
     
    258262        boolean moveTags = Main.pref.getBoolean("multipoly.movetags", true);
    259263
    260         for( String key : values.keySet() ) {
     264        for (Entry<String, String> entry : values.entrySet()) {
    261265            List<OsmPrimitive> affectedWays = new ArrayList<OsmPrimitive>();
    262             String value = values.get(key);
    263 
    264             for( Way way : innerWays ) {
    265                 if( way.hasKey(key) && (value.equals(way.get(key))) ) {
     266            String key = entry.getKey();
     267            String value = entry.getValue();
     268
     269            for (Way way : innerWays) {
     270                if (way.hasKey(key) && (value.equals(way.get(key)))) {
    266271                    affectedWays.add(way);
    267272                }
    268273            }
    269274
    270             if( moveTags ) {
     275            if (moveTags) {
    271276                // remove duplicated tags from outer ways
    272277                for( Way way : outerWays ) {
     
    277282            }
    278283
    279             if(!affectedWays.isEmpty()) {
     284            if (!affectedWays.isEmpty()) {
    280285                // reset key tag on affected ways
    281286                commands.add(new ChangePropertyCommand(affectedWays, key, null));
     
    283288        }
    284289
    285         if( moveTags ) {
     290        if (moveTags) {
    286291            // add those tag values to the relation
    287292
    288293            boolean fixed = false;
    289294            Relation r2 = new Relation(relation);
    290             for( String key : values.keySet() ) {
    291                 if( !r2.hasKey(key) && !key.equals("area") ) {
    292                     if( relation.isNew() )
    293                         relation.put(key, values.get(key));
     295            for (Entry<String, String> entry : values.entrySet()) {
     296                String key = entry.getKey();
     297                if (!r2.hasKey(key) && !key.equals("area") ) {
     298                    if (relation.isNew())
     299                        relation.put(key, entry.getValue());
    294300                    else
    295                         r2.put(key, values.get(key));
     301                        r2.put(key, entry.getValue());
    296302                    fixed = true;
    297303                }
    298304            }
    299             if( fixed && !relation.isNew() )
     305            if (fixed && !relation.isNew())
    300306                commands.add(new ChangeCommand(relation, r2));
    301307        }
  • trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java

    r6106 r6258  
    1313import java.util.List;
    1414import java.util.Map;
     15import java.util.Map.Entry;
    1516
    1617import org.openstreetmap.josm.Main;
     
    4041    private static final String help = ht("/Action/PasteTags");
    4142
     43    /**
     44     * Constructs a new {@code PasteTagsAction}.
     45     */
    4246    public PasteTagsAction() {
    4347        super(tr("Paste Tags"), "pastetags",
     
    270274
    271275        List<Command> commands = new ArrayList<Command>(tags.size());
    272         String v;
    273         for (String key: tags.keySet()) {
    274             v = tags.get(key);
    275             commands.add(new ChangePropertyCommand(selection, key, "".equals(v)?null:v));
     276        for (Entry<String, String> entry: tags.entrySet()) {
     277            String v = entry.getValue();
     278            commands.add(new ChangePropertyCommand(selection, entry.getKey(), "".equals(v)?null:v));
    276279        }
    277280        commitCommands(selection, commands);
Note: See TracChangeset for help on using the changeset viewer.