Ticket #8902: fortoforeach.diff

File fortoforeach.diff, 25.1 KB (added by shinigami, 12 years ago)

for -> for each

  • src/org/openstreetmap/josm/actions/OpenLocationAction.java

     
    132132     */
    133133    public Collection<DownloadTask> findDownloadTasks(final String url) {
    134134        List<DownloadTask> result = new ArrayList<DownloadTask>();
    135         for (int i = 0; i < downloadTasks.size(); i++) {
    136             Class<? extends DownloadTask> taskClass = downloadTasks.get(i);
     135        for (Class<? extends DownloadTask> taskClass : downloadTasks) {
    137136            if (taskClass != null) {
    138137                try {
    139138                    DownloadTask task = taskClass.getConstructor().newInstance();
  • src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

     
    16691669
    16701670        private double getNearestAngle(double angle) {
    16711671            double delta,minDelta=1e5, bestAngle=0.0;
    1672             for (int i=0; i < snapAngles.length; i++) {
    1673                 delta = getAngleDelta(angle,snapAngles[i]);
     1672            for (double snapAngle : snapAngles) {
     1673                delta = getAngleDelta(angle, snapAngle);
    16741674                if (delta < minDelta) {
    1675                     minDelta=delta;
    1676                     bestAngle=snapAngles[i];
     1675                    minDelta = delta;
     1676                    bestAngle = snapAngle;
    16771677                }
    16781678            }
    16791679            if (Math.abs(bestAngle-360) < 1e-3) {
  • src/org/openstreetmap/josm/data/AutosaveTask.java

     
    113113
    114114    private String getFileName(String layerName, int index) {
    115115        String result = layerName;
    116         for (int i=0; i<ILLEGAL_CHARACTERS.length; i++) {
    117             result = result.replaceAll(Pattern.quote(String.valueOf(ILLEGAL_CHARACTERS[i])),
    118                     '&' + String.valueOf((int)ILLEGAL_CHARACTERS[i]) + ';');
     116        for (char illegalCharacter : ILLEGAL_CHARACTERS) {
     117            result = result.replaceAll(Pattern.quote(String.valueOf(illegalCharacter)),
     118                    '&' + String.valueOf((int) illegalCharacter) + ';');
    119119        }
    120120        if (index != 0) {
    121121            result = result + '_' + index;
  • src/org/openstreetmap/josm/data/osm/Way.java

     
    150150        if (node == null) return false;
    151151
    152152        Node[] nodes = this.nodes;
    153         for (int i=0; i<nodes.length; i++) {
    154             if (nodes[i].equals(node))
     153        for (Node n : nodes) {
     154            if (n.equals(node))
    155155                return true;
    156156        }
    157157        return false;
  • src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java

     
    297297                    nodes.addAll(w.getNodes());
    298298                } else {
    299299                    List<Way> waysToJoin = new ArrayList<Way>();
    300                     for (Iterator<Long> it = wayIds.iterator(); it.hasNext(); ) {
    301                         Way w = (Way) ds.getPrimitiveById(it.next(), OsmPrimitiveType.WAY);
     300                    for (Long wayId : wayIds) {
     301                        Way w = (Way) ds.getPrimitiveById(wayId, OsmPrimitiveType.WAY);
    302302                        if (w != null && w.getNodesCount() > 0) { // fix #7173 (empty ways on purge)
    303303                            waysToJoin.add(w);
    304304                        }
  • src/org/openstreetmap/josm/data/projection/CustomProjection.java

     
    159159        if (pref.trim().isEmpty()) {
    160160            parts = new String[0];
    161161        }
    162         for (int i = 0; i < parts.length; i++) {
    163             String part = parts[i];
     162        for (String part : parts) {
    164163            if (part.isEmpty() || part.charAt(0) != '+')
    165164                throw new ProjectionConfigurationException(tr("Parameter must begin with a ''+'' character (found ''{0}'')", part));
    166165            Matcher m = Pattern.compile("\\+([a-zA-Z0-9_]+)(=(.*))?").matcher(part);
     
    287286        if (numStr.length != 3 && numStr.length != 7)
    288287            throw new ProjectionConfigurationException(tr("Unexpected number of arguments for parameter ''towgs84'' (must be 3 or 7)"));
    289288        List<Double> towgs84Param = new ArrayList<Double>();
    290         for (int i = 0; i < numStr.length; i++) {
     289        for (String str : numStr) {
    291290            try {
    292                 towgs84Param.add(Double.parseDouble(numStr[i]));
     291                towgs84Param.add(Double.parseDouble(str));
    293292            } catch (NumberFormatException e) {
    294                 throw new ProjectionConfigurationException(tr("Unable to parse value of parameter ''towgs84'' (''{0}'')", numStr[i]));
     293                throw new ProjectionConfigurationException(tr("Unable to parse value of parameter ''towgs84'' (''{0}'')", str));
    295294            }
    296295        }
    297296        boolean isCentric = true;
    298         for (int i = 0; i<towgs84Param.size(); i++) {
    299             if (towgs84Param.get(i) != 0.0) {
     297        for (Double param : towgs84Param) {
     298            if (param != 0.0) {
    300299                isCentric = false;
    301300                break;
    302301            }
  • src/org/openstreetmap/josm/data/projection/datum/NTV2SubGrid.java

     
    162162            if (subGrid == null)
    163163                return this;
    164164            else {
    165                 for (int i = 0; i < subGrid.length; i++) {
    166                     if (subGrid[i].isCoordWithin(lon, lat))
    167                         return subGrid[i].getSubGridForCoord(lon, lat);
     165                for (NTV2SubGrid aSubGrid : subGrid) {
     166                    if (aSubGrid.isCoordWithin(lon, lat))
     167                        return aSubGrid.getSubGridForCoord(lon, lat);
    168168                }
    169169                return this;
    170170            }
  • src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java

     
    8484                tags = r.getKeys();
    8585                List<Node> wNodes = r.getNodes();
    8686                coor = new ArrayList<LatLon>(wNodes.size());
    87                 for (int i = 0; i < wNodes.size(); i++) {
    88                     coor.add(wNodes.get(i).getCoor());
     87                for (Node wNode : wNodes) {
     88                    coor.add(wNode.getCoor());
    8989                }
    9090            }
    9191            if (src.isRelation()) {
     
    109109         */
    110110        public RelationMembers(List<RelationMember> members) {
    111111            this.members = new ArrayList<RelMember>(members.size());
    112             for (int i = 0; i < members.size(); i++) {
    113                 this.members.add(new RelMember(members.get(i)));
     112            for (RelationMember member : members) {
     113                this.members.add(new RelMember(member));
    114114            }
    115115        }
    116116
  • src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java

     
    192192        }
    193193        // Build the list of lat/lon
    194194        List<LatLon> wLat = new ArrayList<LatLon>(wNodesToUse.size());
    195         for (int i=0; i<wNodesToUse.size(); i++) {
    196             wLat.add(wNodesToUse.get(i).getCoor());
     195        for (Node node : wNodesToUse) {
     196            wLat.add(node.getCoor());
    197197        }
    198198        // If this way has not direction-dependant keys, make sure the list is ordered the same for all ways (fix #8015)
    199199        if (!w.hasDirectionKeys()) {
  • src/org/openstreetmap/josm/data/validation/util/Entities.java

     
    387387                        if(mapNameToValue == null)
    388388                        {
    389389                            mapNameToValue = new HashMap<String, String>();
    390                             for (int in = 0; in < ARRAY.length; ++in)
    391                                 mapNameToValue.put(ARRAY[in][0], ARRAY[in][1]);
     390                            for (String[] pair : ARRAY)
     391                                mapNameToValue.put(pair[0], pair[1]);
    392392                        }
    393393                        String value = mapNameToValue.get(entityContent);
    394394                        entityValue = (value == null ? -1 : Integer.parseInt(value));
  • src/org/openstreetmap/josm/gui/FileDrop.java

     
    22  (public domain) with only very small additions */
    33package org.openstreetmap.josm.gui;
    44
     5import java.awt.*;
    56import java.awt.datatransfer.DataFlavor;
     7import java.awt.dnd.DnDConstants;
    68import java.io.BufferedReader;
    79import java.io.File;
    810import java.io.IOException;
     
    342344                    // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
    343345                    DataFlavor[] flavors = tr.getTransferDataFlavors();
    344346                    boolean handled = false;
    345                     for (int zz = 0; zz < flavors.length; zz++) {
    346                         if (flavors[zz].isRepresentationClassReader()) {
     347                    for (DataFlavor flavor : flavors) {
     348                        if (flavor.isRepresentationClassReader()) {
    347349                            // Say we'll take it.
    348350                            //evt.acceptDrop ( java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE );
    349                             evt.acceptDrop(java.awt.dnd.DnDConstants.ACTION_COPY);
     351                            evt.acceptDrop(DnDConstants.ACTION_COPY);
    350352                            log(out, "FileDrop: reader accepted.");
    351353
    352                             Reader reader = flavors[zz].getReaderForText(tr);
     354                            Reader reader = flavor.getReaderForText(tr);
    353355
    354356                            BufferedReader br = new BufferedReader(reader);
    355357
    356                             if(listener != null) {
     358                            if (listener != null) {
    357359                                listener.filesDropped(createFileArray(br, out));
    358360                            }
    359361
     
    513515            java.awt.Component[] comps = cont.getComponents();
    514516
    515517            // Set it's components as listeners also
    516             for( int i = 0; i < comps.length; i++ ) {
    517                 makeDropTarget( out, comps[i], recursive );
     518            for (Component comp : comps) {
     519                makeDropTarget(out, comp, recursive);
    518520            }
    519521        }   // end if: recursively set components as listener
    520522    }   // end dropListener
     
    593595        c.setDropTarget( null );
    594596        if( recursive && ( c instanceof java.awt.Container ) )
    595597        {   java.awt.Component[] comps = ((java.awt.Container)c).getComponents();
    596         for( int i = 0; i < comps.length; i++ ) {
    597             remove( out, comps[i], recursive );
    598         }
     598            for (Component comp : comps) {
     599                remove(out, comp, recursive);
     600            }
    599601        return true;
    600602        }   // end if: recursive
    601603        else return false;
  • src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

     
    390390     */
    391391    protected void setContentVisible(boolean visible) {
    392392        Component[] comps = getComponents();
    393         for(int i=0; i<comps.length; i++) {
    394             if (comps[i] != titleBar && (!visible || comps[i] != buttonsPanel || buttonHiding != ButtonHiddingType.ALWAYS_HIDDEN)) {
    395                 comps[i].setVisible(visible);
     393        for (Component comp : comps) {
     394            if (comp != titleBar && (!visible || comp != buttonsPanel || buttonHiding != ButtonHiddingType.ALWAYS_HIDDEN)) {
     395                comp.setVisible(visible);
    396396            }
    397397        }
    398398    }
  • src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java

     
    4848
    4949    protected void registerBoundingBoxBuilder() {
    5050        BoundingBoxBuilder bboxbuilder = new BoundingBoxBuilder();
    51         for (int i = 0;i < latlon.length; i++) {
    52             latlon[i].addFocusListener(bboxbuilder);
    53             latlon[i].addActionListener(bboxbuilder);
     51        for (JosmTextField ll : latlon) {
     52            ll.addFocusListener(bboxbuilder);
     53            ll.addActionListener(bboxbuilder);
    5454        }
    5555    }
    5656
  • src/org/openstreetmap/josm/gui/io/ActionFlagsTableCell.java

     
    5454        setLayout(new GridBagLayout());
    5555
    5656        ActionMap am = getActionMap();
    57         for(int i=0; i<checkBoxes.length; i++) {
    58             final JCheckBox b = checkBoxes[i];
     57        for (final JCheckBox b : checkBoxes) {
    5958            add(b, GBC.eol().fill(GBC.HORIZONTAL));
    6059            b.setPreferredSize(new Dimension(b.getPreferredSize().width, 19));
    6160            b.addActionListener(al);
  • src/org/openstreetmap/josm/gui/layer/WMSLayer.java

     
    273273        GeorefImage[][] old = images;
    274274        images = new GeorefImage[dax][day];
    275275        if (old != null) {
    276             for (int i=0; i<old.length; i++) {
    277                 for (int k=0; k<old[i].length; k++) {
    278                     GeorefImage o = old[i][k];
    279                     images[modulo(o.getXIndex(),dax)][modulo(o.getYIndex(),day)] = old[i][k];
     276            for (GeorefImage[] row : old) {
     277                for (GeorefImage image : row) {
     278                    images[modulo(image.getXIndex(), dax)][modulo(image.getYIndex(), day)] = image;
    280279                }
    281280            }
    282281        }
  • src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

     
    9090                });
    9191            }
    9292            String names = null;
    93             for (int i = 0; i < sel.length; i++) {
     93            for (File file : sel) {
    9494                if (names == null) {
    9595                    names = " (";
    9696                } else {
    9797                    names += ", ";
    9898                }
    99                 names += sel[i].getName();
     99                names += file.getName();
    100100            }
    101101            if (names != null) {
    102102                names += ")";
     
    106106            MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", layer.getName()) + names, layer.getAssociatedFile(), layer);
    107107            double firstStartTime = sel[0].lastModified() / 1000.0 - AudioUtil.getCalibratedDuration(sel[0]);
    108108            Markers m = new Markers();
    109             for (int i = 0; i < sel.length; i++) {
    110                 importAudio(sel[i], ml, firstStartTime, m);
     109            for (File file : sel) {
     110                importAudio(file, ml, firstStartTime, m);
    111111            }
    112112            Main.main.addLayer(ml);
    113113            Main.map.repaint();
  • src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

     
    134134            virtualNode.put(tag.getKey(), tag.getValue());
    135135            StyleList styleList = getStyles().generateStyles(virtualNode, 0.5, null, false).a;
    136136            if (styleList != null) {
    137                 for (Iterator<ElemStyle> it = styleList.iterator(); it.hasNext(); ) {
    138                     ElemStyle style = it.next();
     137                for (ElemStyle style : styleList) {
    139138                    if (style instanceof NodeElemStyle) {
    140139                        MapImage mapImage = ((NodeElemStyle) style).mapImage;
    141140                        if (mapImage != null) {
  • src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java

     
    513513
    514514                Set<String> acceptedEulas = new HashSet<String>();
    515515
    516                 outer: for (int i = 0; i < lines.length; i++) {
    517                     ImageryInfo info = defaultModel.getRow(lines[i]);
     516                outer:
     517                for (int line : lines) {
     518                    ImageryInfo info = defaultModel.getRow(line);
    518519
    519520                    // Check if an entry with exactly the same values already
    520521                    // exists
  • src/org/openstreetmap/josm/io/OsmServerChangesetReader.java

     
    131131            monitor.setTicksCount(ids.size());
    132132            List<Changeset> ret = new ArrayList<Changeset>();
    133133            int i=0;
    134             for (Iterator<Integer> it = ids.iterator(); it.hasNext(); ) {
    135                 int id = it.next();
     134            for (int id : ids) {
    136135                if (id <= 0) {
    137136                    continue;
    138137                }
     
    142141                InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true));
    143142                if (in == null)
    144143                    return null;
    145                 monitor.indeterminateSubTask(tr("({0}/{1}) Downloading changeset {2} ...", i,ids.size(), id));
     144                monitor.indeterminateSubTask(tr("({0}/{1}) Downloading changeset {2} ...", i, ids.size(), id));
    146145                List<Changeset> changesets = OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true));
    147146                if (changesets == null || changesets.isEmpty()) {
    148147                    continue;
  • src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java

     
    337337        if (trustedSenders.contains(sender)) {
    338338            if (Main.main.getCurrentDataSet() != null) {
    339339                Collection<OsmPrimitive> s = Main.main.getCurrentDataSet().getSelected();
    340                 for (int j = 0; j < keyValue.length; j++) {
    341                     Main.main.undoRedo.add(new ChangePropertyCommand(s, keyValue[j][0], keyValue[j][1]));
     340                for (String[] row : keyValue) {
     341                    Main.main.undoRedo.add(new ChangePropertyCommand(s, row[0], row[1]));
    342342                }
    343343            }
    344344        } else {
  • src/org/openstreetmap/josm/tools/FallbackDateParser.java

     
    4242    public FallbackDateParser() {
    4343        // Build a list of candidate date parsers.
    4444        dateParsers = new ArrayList<DateFormat>(formats.length);
    45         for (int i = 0; i < formats.length; i++) {
    46             dateParsers.add(new SimpleDateFormat(formats[i]));
     45        for (String format : formats) {
     46            dateParsers.add(new SimpleDateFormat(format));
    4747        }
    4848
    4949        // We haven't selected a date parser yet.
  • src/org/openstreetmap/josm/tools/Utils.java

     
    280280    public static boolean deleteDirectory(File path) {
    281281        if( path.exists() ) {
    282282            File[] files = path.listFiles();
    283             for(int i=0; i<files.length; i++) {
    284                 if(files[i].isDirectory()) {
    285                     deleteDirectory(files[i]);
     283            for (File file : files) {
     284                if (file.isDirectory()) {
     285                    deleteDirectory(file);
     286                } else {
     287                    file.delete();
    286288                }
    287                 else {
    288                     files[i].delete();
    289                 }
    290289            }
    291290        }
    292291        return( path.delete() );
  • src/org/openstreetmap/josm/tools/WindowGeometry.java

     
    295295        GraphicsEnvironment ge = GraphicsEnvironment
    296296                .getLocalGraphicsEnvironment();
    297297        GraphicsDevice[] gs = ge.getScreenDevices();
    298         for (int j = 0; j < gs.length; j++) {
    299             GraphicsDevice gd = gs[j];
     298        for (GraphicsDevice gd : gs) {
    300299            if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
    301300                virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds());
    302301            }
     
    345344        GraphicsDevice[] gs = ge.getScreenDevices();
    346345        int intersect = 0;
    347346        Rectangle bounds = null;
    348         for (int j = 0; j < gs.length; j++) {
    349             GraphicsDevice gd = gs[j];
     347        for (GraphicsDevice gd : gs) {
    350348            if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
    351349                Rectangle b = gd.getDefaultConfiguration().getBounds();
    352                 if (b.height > 0 && b.width/b.height >= 3) /* multiscreen with wrong definition */
    353                 {
     350                if (b.height > 0 && b.width / b.height >= 3) /* multiscreen with wrong definition */ {
    354351                    b.width /= 2;
    355352                    Rectangle is = b.intersection(g);
    356                     int s = is.width*is.height;
    357                     if(bounds == null || intersect < s) {
     353                    int s = is.width * is.height;
     354                    if (bounds == null || intersect < s) {
    358355                        intersect = s;
    359356                        bounds = b;
    360357                    }
    361358                    b = new Rectangle(b);
    362359                    b.x += b.width;
    363360                    is = b.intersection(g);
    364                     s = is.width*is.height;
    365                     if(bounds == null || intersect < s) {
     361                    s = is.width * is.height;
     362                    if (bounds == null || intersect < s) {
    366363                        intersect = s;
    367364                        bounds = b;
    368365                    }
    369                 }
    370                 else
    371                 {
     366                } else {
    372367                    Rectangle is = b.intersection(g);
    373                     int s = is.width*is.height;
    374                     if(bounds == null || intersect < s) {
     368                    int s = is.width * is.height;
     369                    if (bounds == null || intersect < s) {
    375370                        intersect = s;
    376371                        bounds = b;
    377372                    }