Changeset 11893 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2017-04-13T01:08:58+02:00 (7 years ago)
Author:
Don-vip
Message:

sonar - squid:S1126 - Return of boolean expressions should not be wrapped into an "if-then-else" statement

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

Legend:

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

    r11713 r11893  
    866866        boolean prevSegmentParallel = Geometry.segmentsParallel(n1en, prevNode.getEastNorth(), n1en, n2en);
    867867        boolean nextSegmentParallel = Geometry.segmentsParallel(n2en, nextNode.getEastNorth(), n1en, n2en);
    868         if (prevSegmentParallel || nextSegmentParallel) {
    869             return false;
    870         }
    871 
    872         return true;
     868        return !prevSegmentParallel && !nextSegmentParallel;
    873869    }
    874870
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r11535 r11893  
    424424     */
    425425    protected boolean isResponseLoadable(Map<String, List<String>> headerFields, int responseCode, byte[] raw) {
    426         if (raw == null || raw.length == 0 || responseCode >= 400) {
    427             return false;
    428         }
    429         return true;
     426        return raw != null && raw.length != 0 && responseCode < 400;
    430427    }
    431428
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r10906 r11893  
    2626    public int dir;
    2727
     28    /**
     29     * Constructs a new {@code WayPoint} from an existing one.
     30     * @param p existing waypoint
     31     */
    2832    public WayPoint(WayPoint p) {
    2933        attr.putAll(p.attr);
     
    3842    }
    3943
     44    /**
     45     * Constructs a new {@code WayPoint} from lat/lon coordinates.
     46     * @param ll lat/lon coordinates
     47     */
    4048    public WayPoint(LatLon ll) {
    4149        lat = ll.lat();
     
    6472    }
    6573
     74    /**
     75     * Returns the waypoint coordinates.
     76     * @return the waypoint coordinates
     77     */
    6678    public final LatLon getCoor() {
    6779        return new LatLon(lat, lon);
     
    138150    }
    139151
     152    /**
     153     * Returns the waypoint time.
     154     * @return the waypoint time
     155     */
    140156    public Date getTime() {
    141157        return new Date((long) (time * 1000));
     
    177193        if (this == obj)
    178194            return true;
    179         if (!super.equals(obj))
    180             return false;
    181         if (getClass() != obj.getClass())
     195        if (obj == null || !super.equals(obj) || getClass() != obj.getClass())
    182196            return false;
    183197        WayPoint other = (WayPoint) obj;
    184         if (Double.doubleToLongBits(lat) != Double.doubleToLongBits(other.lat))
    185             return false;
    186         if (Double.doubleToLongBits(lon) != Double.doubleToLongBits(other.lon))
    187             return false;
    188         if (Double.doubleToLongBits(time) != Double.doubleToLongBits(other.time))
    189             return false;
    190         return true;
     198        return Double.doubleToLongBits(lat) == Double.doubleToLongBits(other.lat)
     199            && Double.doubleToLongBits(lon) == Double.doubleToLongBits(other.lon)
     200            && Double.doubleToLongBits(time) == Double.doubleToLongBits(other.time);
    191201    }
    192202}
  • trunk/src/org/openstreetmap/josm/data/osm/Changeset.java

    r11878 r11893  
    380380        } else if (!user.equals(other.user))
    381381            return false;
    382         if (commentsCount != other.commentsCount) {
    383             return false;
    384         }
    385         return true;
     382        return commentsCount == other.commentsCount;
    386383    }
    387384
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r11608 r11893  
    11521152        if (!isNew() && id != other.id)
    11531153            return false;
    1154         if (isIncomplete() ^ other.isIncomplete()) // exclusive or operator for performance (see #7159)
    1155             return false;
    1156         return true;
     1154        return !(isIncomplete() ^ other.isIncomplete()); // exclusive or operator for performance (see #7159)
    11571155    }
    11581156
  • trunk/src/org/openstreetmap/josm/data/osm/WaySegment.java

    r11397 r11893  
    121121     */
    122122    public boolean isSimilar(WaySegment s2) {
    123         if (getFirstNode().equals(s2.getFirstNode()) && getSecondNode().equals(s2.getSecondNode()))
    124             return true;
    125         if (getFirstNode().equals(s2.getSecondNode()) && getSecondNode().equals(s2.getFirstNode()))
    126             return true;
    127         return false;
     123        return (getFirstNode().equals(s2.getFirstNode()) && getSecondNode().equals(s2.getSecondNode()))
     124            || (getFirstNode().equals(s2.getSecondNode()) && getSecondNode().equals(s2.getFirstNode()));
    128125    }
    129126
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r11870 r11893  
    14541454        if (bounds.isEmpty()) return false;
    14551455        MapViewPoint p = mapState.getPointFor(new EastNorth(bounds.getX(), bounds.getY()));
    1456         if (p.getInViewX() > mapState.getViewWidth()) return false;
    1457         if (p.getInViewY() < 0) return false;
     1456        if (p.getInViewY() < 0 || p.getInViewX() > mapState.getViewWidth()) return false;
    14581457        p = mapState.getPointFor(new EastNorth(bounds.getX() + bounds.getWidth(), bounds.getY() + bounds.getHeight()));
    1459         if (p.getInViewX() < 0) return false;
    1460         if (p.getInViewY() > mapState.getViewHeight()) return false;
    1461         return true;
    1462     }
    1463 
     1458        return p.getInViewX() >= 0 && p.getInViewY() <= mapState.getViewHeight();
     1459    }
     1460
     1461    /**
     1462     * Determines if the paint visitor shall render OSM objects such that they look inactive.
     1463     * @return {@code true} if the paint visitor shall render OSM objects such that they look inactive
     1464     */
    14641465    public boolean isInactiveMode() {
    14651466        return isInactiveMode;
  • trunk/src/org/openstreetmap/josm/data/validation/PaintVisitor.java

    r10378 r11893  
    225225    /**
    226226     * Checks if the given segment is in the visible area.
    227      * NOTE: This will return true for a small number of non-visible
    228      *       segments.
     227     * NOTE: This will return true for a small number of non-visible segments.
    229228     * @param n1 The first point of the segment to check
    230229     * @param n2 The second point of the segment to check
     
    234233        Point p1 = mv.getPoint(n1);
    235234        Point p2 = mv.getPoint(n2);
    236         if ((p1.x < 0) && (p2.x < 0))
    237             return false;
    238         if ((p1.y < 0) && (p2.y < 0))
    239             return false;
    240         if ((p1.x > mv.getWidth()) && (p2.x > mv.getWidth()))
    241             return false;
    242         if ((p1.y > mv.getHeight()) && (p2.y > mv.getHeight()))
    243             return false;
    244         return true;
     235        return (p1.x >= 0 || p2.x >= 0)
     236            && (p1.y >= 0 || p2.y >= 0)
     237            && (p1.x <= mv.getWidth() || p2.x <= mv.getWidth())
     238            && (p1.y <= mv.getHeight() || p2.y <= mv.getHeight());
    245239    }
    246240
  • trunk/src/org/openstreetmap/josm/data/validation/routines/InetAddressValidator.java

    r10338 r11893  
    191191            validOctets++;
    192192        }
    193         if (validOctets < IPV6_MAX_HEX_GROUPS && !containsCompressedZeroes) {
    194             return false;
    195         }
    196         return true;
     193        return validOctets >= IPV6_MAX_HEX_GROUPS || containsCompressedZeroes;
    197194    }
    198195}
  • trunk/src/org/openstreetmap/josm/data/validation/routines/UrlValidator.java

    r11889 r11893  
    373373        }
    374374
    375         if (isOff(ALLOW_ALL_SCHEMES) && !allowedSchemes.contains(scheme.toLowerCase(Locale.ENGLISH))) {
    376             return false;
    377         }
    378 
    379         return true;
     375        return isOn(ALLOW_ALL_SCHEMES) || allowedSchemes.contains(scheme.toLowerCase(Locale.ENGLISH));
    380376    }
    381377
     
    458454        }
    459455
    460         int slash2Count = countToken("//", path);
    461         if (slash2Count > 0 && isOff(ALLOW_2_SLASHES)) {
    462             return false;
    463         }
    464 
    465         return true;
     456        return isOn(ALLOW_2_SLASHES) || countToken("//", path) <= 0;
    466457    }
    467458
  • trunk/src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java

    r11852 r11893  
    8484                return true;
    8585            }
    86             if (isProposedOrAbandoned(w2)) {
    87                 return true;
    88             }
    89             return false;
     86            return isProposedOrAbandoned(w2);
    9087        }
    9188
     
    160157        @Override
    161158        boolean ignoreWaySegmentCombination(Way w1, Way w2) {
    162             if (!Objects.equals(getLayer(w1), getLayer(w2))) {
    163                 return true;
    164             }
    165             return false;
     159            return !Objects.equals(getLayer(w1), getLayer(w2));
    166160        }
    167161
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java

    r11627 r11893  
    343343        // cannot merge nodes outside download area
    344344        final Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator();
    345         if (!it.hasNext() || it.next().isOutsideDownloadArea()) return false;
     345        return it.hasNext() && !it.next().isOutsideDownloadArea();
    346346        // everything else is ok to merge
    347         return true;
    348347    }
    349348}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java

    r11839 r11893  
    768768    @Override
    769769    public boolean isFixable(TestError testError) {
    770         if (testError.getCode() == REPEATED_MEMBER_SAME_ROLE)
    771             return true;
    772         return false;
     770        return testError.getCode() == REPEATED_MEMBER_SAME_ROLE;
    773771    }
    774772
  • trunk/src/org/openstreetmap/josm/gui/bbox/TileSelectionBBoxChooser.java

    r10763 r11893  
    606606                return false;
    607607            }
    608             if (tileIndex < 0 || tileIndex >= Math.pow(2, zoomLevel)) return false;
    609 
    610             return true;
     608            return tileIndex >= 0 && tileIndex < Math.pow(2, zoomLevel);
    611609        }
    612610
  • trunk/src/org/openstreetmap/josm/gui/dialogs/FilterTableModel.java

    r11848 r11893  
    276276    }
    277277
     278    /**
     279     * Determines if a cell is enabled.
     280     * @param row row index
     281     * @param column column index
     282     * @return {@code true} if the cell at (row, column) is enabled
     283     */
    278284    public boolean isCellEnabled(int row, int column) {
    279         if (!filters.get(row).enable && column != 0)
    280             return false;
    281         return true;
     285        return filters.get(row).enable || column == 0;
    282286    }
    283287
    284288    @Override
    285289    public boolean isCellEditable(int row, int column) {
    286         if (!filters.get(row).enable && column != 0)
    287             return false;
    288         if (column < 4)
    289             return true;
    290         return false;
     290        return column < 4 && isCellEnabled(row, column);
    291291    }
    292292
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r11885 r11893  
    985985        @Override
    986986        public boolean isCellEditable(int row, int col) {
    987             if (col == 0 && getActiveLayer() == getLayers().get(row))
    988                 return false;
    989             return true;
     987            return col != 0 || getActiveLayer() != getLayers().get(row);
    990988        }
    991989
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/LayerListTransferHandler.java

    r11881 r11893  
    7474        }
    7575
    76         if (support.getDropAction() == LINK) {
    77             // cannot link yet.
    78             return false;
    79         }
    80 
    81         return true;
     76        // cannot link yet.
     77        return support.getDropAction() != LINK;
    8278    }
    8379
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r11747 r11893  
    334334
    335335    public boolean canRemove(int... rows) {
    336         if (rows == null || rows.length == 0)
    337             return false;
    338         return true;
     336        return rows != null && rows.length != 0;
    339337    }
    340338
  • trunk/src/org/openstreetmap/josm/gui/io/LayerNameAndFilePathTableCell.java

    r10873 r11893  
    124124
    125125    private static boolean canWrite(File f) {
    126         if (f == null) return false;
    127         if (f.isDirectory()) return false;
     126        if (f == null || f.isDirectory()) return false;
    128127        if (f.exists() && f.canWrite()) return true;
    129         if (!f.exists() && f.getParentFile() != null && f.getParentFile().canWrite())
    130             return true;
    131         return false;
     128        return !f.exists() && f.getParentFile() != null && f.getParentFile().canWrite();
    132129    }
    133130
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r11891 r11893  
    10711071            return false;
    10721072        int status = Toolkit.getDefaultToolkit().checkImage(i, -1, -1, this);
    1073         if ((status & ALLBITS) != 0)
    1074             return true;
    1075         return false;
     1073        return (status & ALLBITS) != 0;
    10761074    }
    10771075
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r11747 r11893  
    10261026
    10271027        ConflictCollection conflictsCol = getConflicts();
    1028         if (conflictsCol != null && !conflictsCol.isEmpty() && 1 != GuiHelper.runInEDTAndWaitAndReturn(() -> {
     1028        return conflictsCol == null || conflictsCol.isEmpty() || 1 == GuiHelper.runInEDTAndWaitAndReturn(() -> {
    10291029            ExtendedDialog dialog = new ExtendedDialog(
    10301030                    Main.parent,
     
    10371037            dialog.setButtonIcons(new String[] {"save", "cancel"});
    10381038            return dialog.showDialog().getValue();
    1039         })) {
    1040             return false;
    1041         }
    1042         return true;
     1039        });
    10431040    }
    10441041
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/ReprojectionTile.java

    r11883 r11893  
    5353        if (Utils.equalsEpsilon(nativeScale, currentScale))
    5454            return false;
    55         if (maxZoomReached && currentScale < nativeScale)
    56             // zoomed in even more - max zoom already reached, so no update
    57             return false;
    58         return true;
     55        // zoomed in even more - max zoom already reached, so no update
     56        return !maxZoomReached || currentScale >= nativeScale;
    5957    }
    6058
  • trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java

    r11746 r11893  
    295295        if (this == obj)
    296296            return true;
    297         if (obj == null)
    298             return false;
    299         if (getClass() != obj.getClass())
     297        if (obj == null || getClass() != obj.getClass())
    300298            return false;
    301299        TileSourceDisplaySettings other = (TileSourceDisplaySettings) obj;
    302         if (autoLoad != other.autoLoad)
    303             return false;
    304         if (autoZoom != other.autoZoom)
    305             return false;
    306         if (showErrors != other.showErrors)
    307             return false;
    308         return true;
     300        return autoLoad == other.autoLoad
     301            && autoZoom == other.autoZoom
     302            && showErrors == other.showErrors;
    309303    }
    310304
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java

    r11779 r11893  
    625625            if (e.osm instanceof Way && ((Way) e.osm).isClosed())
    626626                return true;
    627             if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon())
    628                 return true;
    629             return false;
     627            return e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon();
    630628        }
    631629
  • trunk/src/org/openstreetmap/josm/gui/util/RotationAngle.java

    r11731 r11893  
    5757                return true;
    5858            }
    59             if (obj == null) {
    60                 return false;
    61             }
    62             if (getClass() != obj.getClass()) {
    63                 return false;
    64             }
    65             return true;
     59            return obj != null && getClass() == obj.getClass();
    6660        }
    67 
    6861    }
    6962
     
    9285            final int prime = 31;
    9386            int result = 1;
    94             long temp;
    95             temp = Double.doubleToLongBits(angle);
     87            long temp = Double.doubleToLongBits(angle);
    9688            result = prime * result + (int) (temp ^ (temp >>> 32));
    9789            return result;
     
    10395                return true;
    10496            }
    105             if (obj == null) {
    106                 return false;
    107             }
    108             if (getClass() != obj.getClass()) {
     97            if (obj == null || getClass() != obj.getClass()) {
    10998                return false;
    11099            }
    111100            StaticRotationAngle other = (StaticRotationAngle) obj;
    112             if (Double.doubleToLongBits(angle) != Double.doubleToLongBits(other.angle)) {
    113                 return false;
    114             }
    115             return true;
     101            return Double.doubleToLongBits(angle) == Double.doubleToLongBits(other.angle);
    116102        }
    117103    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/BoundingBoxSelectionPanel.java

    r9059 r11893  
    152152        @Override
    153153        public boolean isValid() {
    154             double value = 0;
    155             try {
    156                 value = Double.parseDouble(getComponent().getText());
     154            try {
     155                return LatLon.isValidLat(Double.parseDouble(getComponent().getText()));
    157156            } catch (NumberFormatException ex) {
    158157                return false;
    159158            }
    160             if (!LatLon.isValidLat(value))
    161                 return false;
    162             return true;
    163159        }
    164160    }
     
    192188        @Override
    193189        public boolean isValid() {
    194             double value = 0;
    195             try {
    196                 value = Double.parseDouble(getComponent().getText());
     190            try {
     191                return LatLon.isValidLon(Double.parseDouble(getComponent().getText()));
    197192            } catch (NumberFormatException ex) {
    198193                return false;
    199194            }
    200             if (!LatLon.isValidLon(value))
    201                 return false;
    202             return true;
    203195        }
    204196    }
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r11848 r11893  
    430430        if (this.version == null && referenceVersion != null)
    431431            return true;
    432         if (this.version != null && !this.version.equals(referenceVersion))
    433             return true;
    434         return false;
     432        return this.version != null && !this.version.equals(referenceVersion);
    435433    }
    436434
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r11879 r11893  
    11921192     */
    11931193    public static boolean isLocalUrl(String url) {
    1194         if (url == null || url.startsWith("http://") || url.startsWith("https://") || url.startsWith("resource://"))
    1195             return false;
    1196         return true;
     1194        return url != null && !url.startsWith("http://") && !url.startsWith("https://") && !url.startsWith("resource://");
    11971195    }
    11981196
Note: See TracChangeset for help on using the changeset viewer.