Changeset 11386 in josm


Ignore:
Timestamp:
2016-12-13T02:16:07+01:00 (7 years ago)
Author:
Don-vip
Message:

sonar - squid:S1066 - Collapsible "if" statements should be merged

Location:
trunk/src/org/openstreetmap/josm
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/IconToggleButton.java

    r10384 r11386  
    7979    String getPreferenceKey() {
    8080        String s = (String) getSafeActionValue("toolbar");
    81         if (s == null) {
    82             if (getAction() != null) {
    83                 s = getAction().getClass().getName();
    84             }
     81        if (s == null && getAction() != null) {
     82            s = getAction().getClass().getName();
    8583        }
    8684        return "sidetoolbar.hidden."+s;
    87 
    8885    }
    8986
  • trunk/src/org/openstreetmap/josm/gui/PopupMenuHandler.java

    r8510 r11386  
    7474            MenuElement[] elements = menu.getSubElements();
    7575            for (int i = 0; i < elements.length; i++) {
    76                 if (elements[i] instanceof JMenuItem) {
    77                     if (((JMenuItem) elements[i]).getAction() == a) {
    78                         menu.remove(i);
    79                         return;
    80                     }
     76                if (elements[i] instanceof JMenuItem && ((JMenuItem) elements[i]).getAction() == a) {
     77                    menu.remove(i);
     78                    return;
    8179                }
    8280            }
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapControler.java

    r10217 r11386  
    118118
    119119    /**
    120      * Start drawing the selection rectangle if it was the 1st button (left
    121      * button)
     120     * Start drawing the selection rectangle if it was the 1st button (left button)
    122121     */
    123122    @Override
     
    132131    public void mouseDragged(MouseEvent e) {
    133132        if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK &&
    134                 !(Main.isPlatformOsx() && e.getModifiersEx() == MAC_MOUSE_BUTTON3_MASK)) {
    135             if (iStartSelectionPoint != null) {
    136                 iEndSelectionPoint = e.getPoint();
    137                 iSlippyMapChooser.setSelection(iStartSelectionPoint, iEndSelectionPoint);
    138                 isSelecting = true;
    139             }
     133                !(Main.isPlatformOsx() && e.getModifiersEx() == MAC_MOUSE_BUTTON3_MASK) && iStartSelectionPoint != null) {
     134            iEndSelectionPoint = e.getPoint();
     135            iSlippyMapChooser.setSelection(iStartSelectionPoint, iEndSelectionPoint);
     136            isSelecting = true;
    140137        }
    141138    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java

    r11032 r11386  
    9898            @Override
    9999            public void mouseClicked(MouseEvent e) {
    100                 if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
    101                     if (noteData != null && noteData.getSelectedNote() != null) {
    102                         Main.map.mapView.zoomTo(noteData.getSelectedNote().getLatLon());
    103                     }
     100                if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2 && noteData != null && noteData.getSelectedNote() != null) {
     101                    Main.map.mapView.zoomTo(noteData.getSelectedNote().getLatLon());
    104102                }
    105103            }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r11365 r11386  
    205205
    206206        //update highlights
    207         if (highlightEnabled && focused == displaylist && Main.isDisplayingMapView()) {
    208             if (highlightHelper.highlightOnly(sel)) {
    209                 Main.map.mapView.repaint();
    210             }
     207        if (highlightEnabled && focused == displaylist && Main.isDisplayingMapView() && highlightHelper.highlightOnly(sel)) {
     208            Main.map.mapView.repaint();
    211209        }
    212210    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r11365 r11386  
    211211                    actEditRelationSelection.actionPerformed(null);
    212212                }
    213             } else if (highlightEnabled && Main.isDisplayingMapView()) {
    214                 if (helper.highlightOnly(model.getElementAt(idx))) {
    215                     Main.map.mapView.repaint();
    216                 }
     213            } else if (highlightEnabled && Main.isDisplayingMapView() && helper.highlightOnly(model.getElementAt(idx))) {
     214                Main.map.mapView.repaint();
    217215            }
    218216        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r11366 r11386  
    385385                if (Main.isDisplayingMapView()) {
    386386                    int row = membershipTable.rowAtPoint(e.getPoint());
    387                     if (row >= 0) {
    388                         if (highlightHelper.highlightOnly((Relation) membershipTable.getValueAt(row, 0))) {
    389                             Main.map.mapView.repaint();
    390                         }
     387                    if (row >= 0 && highlightHelper.highlightOnly((Relation) membershipTable.getValueAt(row, 0))) {
     388                        Main.map.mapView.repaint();
    391389                    }
    392390                }
  • trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java

    r10212 r11386  
    132132                }
    133133            }
    134             if (strategy.isCloseChangesetAfterUpload()) {
    135                 if (changeset != null && changeset.getId() > 0) {
    136                     OsmApi.getOsmApi().closeChangeset(changeset, monitor.createSubTaskMonitor(0, false));
    137                 }
     134            if (strategy.isCloseChangesetAfterUpload() && changeset != null && changeset.getId() > 0) {
     135                OsmApi.getOsmApi().closeChangeset(changeset, monitor.createSubTaskMonitor(0, false));
    138136            }
    139137        } catch (OsmTransferException sxe) {
  • trunk/src/org/openstreetmap/josm/gui/layer/AlignImageryPanel.java

    r10611 r11386  
    8383    public static void addNagPanelIfNeeded(ImageryInfo infoToAdd) {
    8484        BooleanProperty showAgain = new BooleanProperty("message.imagery.nagPanel." + infoToAdd.getUrl(), true);
    85         if (Main.isDisplayingMapView() && showAgain.get() && !infoToAdd.isGeoreferenceValid()) {
    86             if (Main.map.getTopPanel(AlignImageryPanel.class) == null) {
    87                 double w = GuiHelper.getScreenSize().getWidth();
    88                 AlignImageryPanel p = new AlignImageryPanel(w > 1300, showAgain, infoToAdd);
    89                 Main.map.addTopPanel(p);
    90             }
     85        if (Main.isDisplayingMapView() && showAgain.get() && !infoToAdd.isGeoreferenceValid()
     86                && Main.map.getTopPanel(AlignImageryPanel.class) == null) {
     87            double w = GuiHelper.getScreenSize().getWidth();
     88            Main.map.addTopPanel(new AlignImageryPanel(w > 1300, showAgain, infoToAdd));
    9189        }
    9290    }
  • trunk/src/org/openstreetmap/josm/gui/layer/NativeScaleLayer.java

    r10600 r11386  
    174174                for (int i = 0; i < size; i++) {
    175175                    Scale current = this.scales.get(i);
    176                     if (previous != null) {
    177                         if (scale <= previous.scale && scale >= current.scale) {
    178                             if (floor || previous.scale / scale < scale / current.scale) {
    179                                 return new Scale(previous.scale, previous.isNative, i-1);
    180                             } else {
    181                                 return new Scale(current.scale, current.isNative, i);
    182                             }
     176                    if (previous != null && scale <= previous.scale && scale >= current.scale) {
     177                        if (floor || previous.scale / scale < scale / current.scale) {
     178                            return new Scale(previous.scale, previous.isNative, i-1);
     179                        } else {
     180                            return new Scale(current.scale, current.isNative, i);
    183181                        }
    184182                    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r11368 r11386  
    143143                if (!hasNonModifier) {
    144144                    p.a = new StyleElementList(p.a, NodeElement.SIMPLE_NODE_ELEMSTYLE);
    145                     if (!hasText) {
    146                         if (TextLabel.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) {
    147                             p.a = new StyleElementList(p.a, BoxTextElement.SIMPLE_NODE_TEXT_ELEMSTYLE);
    148                         }
     145                    if (!hasText && TextLabel.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) {
     146                        p.a = new StyleElementList(p.a, BoxTextElement.SIMPLE_NODE_TEXT_ELEMSTYLE);
    149147                    }
    150148                }
     
    318316        } else if (osm instanceof Relation) {
    319317            Pair<StyleElementList, Range> p = generateStyles(osm, scale, true);
    320             if (drawMultipolygon && ((Relation) osm).isMultipolygon()) {
    321                 if (!Utils.exists(p.a, AreaElement.class) && Main.pref.getBoolean("multipolygon.deprecated.outerstyle", true)) {
    322                     // look at outer ways to find area style
    323                     Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm);
    324                     for (Way w : multipolygon.getOuterWays()) {
    325                         Pair<StyleElementList, Range> wayStyles = generateStyles(w, scale, false);
    326                         p.b = Range.cut(p.b, wayStyles.b);
    327                         StyleElement area = Utils.find(wayStyles.a, AreaElement.class);
    328                         if (area != null) {
    329                             p.a = new StyleElementList(p.a, area);
    330                             break;
    331                         }
     318            if (drawMultipolygon && ((Relation) osm).isMultipolygon()
     319                    && !Utils.exists(p.a, AreaElement.class) && Main.pref.getBoolean("multipolygon.deprecated.outerstyle", true)) {
     320                // look at outer ways to find area style
     321                Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm);
     322                for (Way w : multipolygon.getOuterWays()) {
     323                    Pair<StyleElementList, Range> wayStyles = generateStyles(w, scale, false);
     324                    p.b = Range.cut(p.b, wayStyles.b);
     325                    StyleElement area = Utils.find(wayStyles.a, AreaElement.class);
     326                    if (area != null) {
     327                        p.a = new StyleElementList(p.a, area);
     328                        break;
    332329                    }
    333330                }
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java

    r10824 r11386  
    277277        for (int i = 0; i < colors.getRowCount(); ++i) {
    278278            String key = (String) colors.getValueAt(i, 0);
    279             if (Main.pref.putColor(key, (Color) colors.getValueAt(i, 1))) {
    280                 if (key.startsWith("mappaint.")) {
    281                     ret = true;
    282                 }
     279            if (Main.pref.putColor(key, (Color) colors.getValueAt(i, 1)) && key.startsWith("mappaint.")) {
     280                ret = true;
    283281            }
    284282        }
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagCellRenderer.java

    r11374 r11386  
    101101
    102102        switch(vColIndex) {
    103         case 0: renderTagName((TagModel) value); break;
    104         case 1: renderTagValue((TagModel) value); break;
    105 
    106         default: throw new JosmRuntimeException("unexpected index in switch statement");
     103            case 0: renderTagName((TagModel) value); break;
     104            case 1: renderTagValue((TagModel) value); break;
     105            default: throw new JosmRuntimeException("unexpected index in switch statement");
    107106        }
    108         if (hasFocus && isSelected) {
    109             if (table.getSelectedColumnCount() == 1 && table.getSelectedRowCount() == 1) {
    110                 if (table.getEditorComponent() != null) {
    111                     table.getEditorComponent().requestFocusInWindow();
    112                 }
    113             }
     107        if (hasFocus && isSelected && table.getSelectedColumnCount() == 1 && table.getSelectedRowCount() == 1
     108                && table.getEditorComponent() != null) {
     109            table.getEditorComponent().requestFocusInWindow();
    114110        }
    115111        return this;
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReader.java

    r10768 r11386  
    280280                        if (o instanceof ComboMultiSelect) {
    281281                            ((ComboMultiSelect) o).addListEntries(listEntries);
    282                         } else if (o instanceof Key) {
    283                             if (((Key) o).value == null) {
    284                                 ((Key) o).value = ""; // Fix #8530
    285                             }
     282                        } else if (o instanceof Key && ((Key) o).value == null) {
     283                            ((Key) o).value = ""; // Fix #8530
    286284                        }
    287285                        listEntries = new LinkedList<>();
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java

    r10657 r11386  
    127127     */
    128128    public static void addTaggingPresets(Collection<TaggingPreset> presets) {
    129         if (presets != null) {
    130             if (taggingPresets.addAll(presets)) {
    131                 for (TaggingPresetListener listener : listeners) {
    132                     listener.taggingPresetsModified();
    133                 }
     129        if (presets != null && taggingPresets.addAll(presets)) {
     130            for (TaggingPresetListener listener : listeners) {
     131                listener.taggingPresetsModified();
    134132            }
    135133        }
  • trunk/src/org/openstreetmap/josm/gui/util/AdvancedKeyPressDetector.java

    r10611 r11386  
    120120            if (timer.isRunning()) {
    121121                timer.stop();
    122             } else if (set.add(e.getKeyCode()) && enabled) {
    123                 if (isFocusInMainWindow()) {
    124                     for (KeyPressReleaseListener q: keyListeners) {
    125                         if (Main.isTraceEnabled()) {
    126                             Main.trace(q+" => doKeyPressed("+e+')');
    127                         }
    128                         q.doKeyPressed(e);
     122            } else if (set.add(e.getKeyCode()) && enabled && isFocusInMainWindow()) {
     123                for (KeyPressReleaseListener q: keyListeners) {
     124                    if (Main.isTraceEnabled()) {
     125                        Main.trace(q+" => doKeyPressed("+e+')');
    129126                    }
     127                    q.doKeyPressed(e);
    130128                }
    131129            }
     
    133131            if (timer.isRunning()) {
    134132                timer.stop();
    135                 if (set.remove(e.getKeyCode()) && enabled) {
    136                     if (isFocusInMainWindow()) {
    137                         for (KeyPressReleaseListener q: keyListeners) {
    138                             if (Main.isTraceEnabled()) {
    139                                 Main.trace(q+" => doKeyReleased("+e+')');
    140                             }
    141                             q.doKeyReleased(e);
     133                if (set.remove(e.getKeyCode()) && enabled && isFocusInMainWindow()) {
     134                    for (KeyPressReleaseListener q: keyListeners) {
     135                        if (Main.isTraceEnabled()) {
     136                            Main.trace(q+" => doKeyReleased("+e+')');
    142137                        }
     138                        q.doKeyReleased(e);
    143139                    }
    144140                }
  • trunk/src/org/openstreetmap/josm/gui/widgets/AbstractTextComponentValidator.java

    r10378 r11386  
    115115            tc.getDocument().addDocumentListener(this);
    116116        }
    117         if (addActionListener) {
    118             if (tc instanceof JosmTextField) {
    119                 JosmTextField tf = (JosmTextField) tc;
    120                 tf.addActionListener(this);
    121             }
     117        if (addActionListener && tc instanceof JosmTextField) {
     118            ((JosmTextField) tc).addActionListener(this);
    122119        }
    123120        tc.addPropertyChangeListener("enabled", this);
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r11288 r11386  
    339339            while (entries.hasMoreElements()) {
    340340                ZipEntry entry = entries.nextElement();
    341                 if (entry.getName().endsWith('.' + extension)) {
    342                     /* choose any file with correct extension. When more than
    343                         one file, prefer the one which matches namepart */
    344                     if (resentry == null || entry.getName().indexOf(namepart) >= 0) {
    345                         resentry = entry;
    346                     }
     341                // choose any file with correct extension. When more than one file, prefer the one which matches namepart
     342                if (entry.getName().endsWith('.' + extension) && (resentry == null || entry.getName().indexOf(namepart) >= 0)) {
     343                    resentry = entry;
    347344                }
    348345            }
  • trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java

    r10755 r11386  
    193193        remember(relation.getPrimitiveId());
    194194        for (RelationMember member : !recursesDown() ? relation.getMembers() : Collections.<RelationMember>emptyList()) {
    195             if (OsmPrimitiveType.from(member.getMember()).equals(OsmPrimitiveType.RELATION)) {
    196                 // avoid infinite recursion in case of cyclic dependencies in relations
    197                 //
    198                 if (relations.contains(member.getMember().getId())) {
    199                     continue;
    200                 }
     195            // avoid infinite recursion in case of cyclic dependencies in relations
     196            if (OsmPrimitiveType.from(member.getMember()).equals(OsmPrimitiveType.RELATION)
     197                    && relations.contains(member.getMember().getId())) {
     198                continue;
    201199            }
    202200            if (!member.getMember().isIncomplete()) {
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r11381 r11386  
    667667                int retCode = response.getResponseCode();
    668668
    669                 if (retCode >= 500) {
    670                     if (retries-- > 0) {
    671                         sleepAndListen(retries, monitor);
    672                         Main.info(tr("Starting retry {0} of {1}.", getMaxRetries() - retries, getMaxRetries()));
    673                         continue;
    674                     }
     669                if (retCode >= 500 && retries-- > 0) {
     670                    sleepAndListen(retries, monitor);
     671                    Main.info(tr("Starting retry {0} of {1}.", getMaxRetries() - retries, getMaxRetries()));
     672                    continue;
    675673                }
    676674
  • trunk/src/org/openstreetmap/josm/io/OsmExporter.java

    r11098 r11386  
    8282        File tmpFile = null;
    8383        try {
    84             // use a tmp file because if something errors out in the
    85             // process of writing the file, we might just end up with
    86             // a truncated file.  That can destroy lots of work.
     84            // use a tmp file because if something errors out in the process of writing the file,
     85            // we might just end up with a truncated file.  That can destroy lots of work.
    8786            if (file.exists()) {
    8887                tmpFile = new File(file.getPath() + '~');
     
    9190
    9291            doSave(file, layer);
    93             if (noBackup || !Main.pref.getBoolean("save.keepbackup", false)) {
    94                 if (tmpFile != null) {
    95                     Utils.deleteFile(tmpFile);
    96                 }
     92            if ((noBackup || !Main.pref.getBoolean("save.keepbackup", false)) && tmpFile != null) {
     93                Utils.deleteFile(tmpFile);
    9794            }
    9895            layer.onPostSaveToFile();
     
    107104
    108105            try {
    109                 // if the file save failed, then the tempfile will not
    110                 // be deleted.  So, restore the backup if we made one.
     106                // if the file save failed, then the tempfile will not be deleted. So, restore the backup if we made one.
    111107                if (tmpFile != null && tmpFile.exists()) {
    112108                    Utils.copyFile(tmpFile, file);
  • trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    r11374 r11386  
    291291                break;
    292292            case MIRROR:
    293                 if ("mirror".equals(qName)) {
    294                     if (mirrorEntry != null) {
    295                         entry.addMirror(mirrorEntry);
    296                         mirrorEntry = null;
    297                     }
     293                if ("mirror".equals(qName) && mirrorEntry != null) {
     294                    entry.addMirror(mirrorEntry);
     295                    mirrorEntry = null;
    298296                }
    299297                break;
Note: See TracChangeset for help on using the changeset viewer.