Changeset 7025 in josm for trunk/src/org


Ignore:
Timestamp:
2014-04-29T03:24:57+02:00 (10 years ago)
Author:
Don-vip
Message:

Sonar - fix various issues

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

Legend:

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

    r7005 r7025  
    5252     * InvalidSelection exception has to be raised when action can't be perform
    5353     */
    54     private class InvalidSelection extends Exception {
     54    private static class InvalidSelection extends Exception {
    5555
    5656        /**
  • trunk/src/org/openstreetmap/josm/actions/ExpertToggleAction.java

    r7005 r7025  
    2929
    3030    private static synchronized void fireExpertModeChanged(boolean isExpert) {
    31         {
    32             Iterator<WeakReference<ExpertModeChangeListener>> it = listeners.iterator();
    33             while (it.hasNext()) {
    34                 WeakReference<ExpertModeChangeListener> wr = it.next();
    35                 ExpertModeChangeListener listener = wr.get();
    36                 if (listener == null) {
    37                     it.remove();
    38                     continue;
    39                 }
    40                 listener.expertChanged(isExpert);
     31        Iterator<WeakReference<ExpertModeChangeListener>> it1 = listeners.iterator();
     32        while (it1.hasNext()) {
     33            WeakReference<ExpertModeChangeListener> wr = it1.next();
     34            ExpertModeChangeListener listener = wr.get();
     35            if (listener == null) {
     36                it1.remove();
     37                continue;
    4138            }
     39            listener.expertChanged(isExpert);
    4240        }
    43         {
    44             Iterator<WeakReference<Component>> it = visibilityToggleListeners.iterator();
    45             while (it.hasNext()) {
    46                 WeakReference<Component> wr = it.next();
    47                 Component c = wr.get();
    48                 if (c == null) {
    49                     it.remove();
    50                     continue;
    51                 }
    52                 c.setVisible(isExpert);
     41        Iterator<WeakReference<Component>> it2 = visibilityToggleListeners.iterator();
     42        while (it2.hasNext()) {
     43            WeakReference<Component> wr = it2.next();
     44            Component c = wr.get();
     45            if (c == null) {
     46                it2.remove();
     47                continue;
    5348            }
     49            c.setVisible(isExpert);
    5450        }
    5551    }
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r7005 r7025  
    11721172
    11731173            for (RelationMember rm : r.getMembers()) {
    1174                 if (rm.getRole().equalsIgnoreCase("outer")) {
     1174                if ("outer".equalsIgnoreCase(rm.getRole())) {
    11751175                    outerWays.add(rm.getWay());
    11761176                    hasKnownOuter |= selectedWays.contains(rm.getWay());
    11771177                }
    1178                 else if (rm.getRole().equalsIgnoreCase("inner")) {
     1178                else if ("inner".equalsIgnoreCase(rm.getRole())) {
    11791179                    innerWays.add(rm.getWay());
    11801180                }
     
    13281328
    13291329        for (RelationRole r : rels) {
    1330             if (r.rel.isMultipolygon() && r.role.equalsIgnoreCase("outer")) {
     1330            if (r.rel.isMultipolygon() && "outer".equalsIgnoreCase(r.role)) {
    13311331                multiouters.add(r);
    13321332                continue;
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r6453 r7025  
    149149                for (String arg : args) {
    150150                    int eq = arg.indexOf('=');
    151                     if (eq == -1 || !arg.substring(0, eq).equalsIgnoreCase("zoom")) continue;
     151                    if (eq == -1 || !"zoom".equalsIgnoreCase(arg.substring(0, eq))) continue;
    152152   
    153153                    zoomLvl = Integer.parseInt(arg.substring(eq + 1));
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r7005 r7025  
    104104
    105105        switch (Main.pref.getInteger("merge-nodes.mode", 0)) {
    106         case 0: {
     106        case 0:
    107107            Node targetNode = candidates.get(size - 1);
    108108            for (final Node n : candidates) { // pick last one
     
    110110            }
    111111            return targetNode;
    112         }
    113         case 1: {
    114             double east = 0, north = 0;
     112        case 1:
     113            double east1 = 0, north1 = 0;
    115114            for (final Node n : candidates) {
    116                 east += n.getEastNorth().east();
    117                 north += n.getEastNorth().north();
    118             }
    119 
    120             return new Node(new EastNorth(east / size, north / size));
    121         }
    122         case 2: {
     115                east1 += n.getEastNorth().east();
     116                north1 += n.getEastNorth().north();
     117            }
     118
     119            return new Node(new EastNorth(east1 / size, north1 / size));
     120        case 2:
    123121            final double[] weights = new double[size];
    124122
     
    133131            }
    134132
    135             double east = 0, north = 0, weight = 0;
     133            double east2 = 0, north2 = 0, weight = 0;
    136134            for (int i = 0; i < size; i++) {
    137135                final EastNorth en = candidates.get(i).getEastNorth();
    138136                final double w = weights[i];
    139                 east += en.east() * w;
    140                 north += en.north() * w;
     137                east2 += en.east() * w;
     138                north2 += en.north() * w;
    141139                weight += w;
    142140            }
    143141
    144             return new Node(new EastNorth(east / weight, north / weight));
    145         }
     142            return new Node(new EastNorth(east2 / weight, north2 / weight));
    146143        default:
    147144            throw new RuntimeException("unacceptable merge-nodes.mode");
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java

    r7005 r7025  
    8989
    9090        // Ugly method of ensuring that the offset isn't inverted. I'm sure there is a better and more elegant way, but I'm starting to get sleepy, so I do this for now.
    91         {
    92             Way refWay = ways.get(refWayIndex);
    93             boolean refWayReversed = true;
    94             for (int i = 0; i < sortedNodes.size() - 1; i++) {
    95                 if (sortedNodes.get(i) == refWay.firstNode() && sortedNodes.get(i + 1) == refWay.getNode(1)) {
    96                     refWayReversed = false;
    97                     break;
    98                 }
     91        Way refWay = ways.get(refWayIndex);
     92        boolean refWayReversed = true;
     93        for (int i = 0; i < sortedNodes.size() - 1; i++) {
     94            if (sortedNodes.get(i) == refWay.firstNode() && sortedNodes.get(i + 1) == refWay.getNode(1)) {
     95                refWayReversed = false;
     96                break;
    9997            }
    100             if (refWayReversed) {
    101                 Collections.reverse(sortedNodes); // need to keep the orientation of the reference way.
    102             }
     98        }
     99        if (refWayReversed) {
     100            Collections.reverse(sortedNodes); // need to keep the orientation of the reference way.
    103101        }
    104102
  • trunk/src/org/openstreetmap/josm/data/imagery/GeorefImage.java

    r7005 r7025  
    7272        switch (state) {
    7373        case FAILED:
    74         {
    75             BufferedImage img = createImage();
    76             layer.drawErrorTile(img);
    77             this.image = img;
     74            BufferedImage imgFailed = createImage();
     75            layer.drawErrorTile(imgFailed);
     76            this.image = imgFailed;
    7877            break;
    79         }
    8078        case NOT_IN_CACHE:
    81         {
    8279            BufferedImage img = createImage();
    8380            Graphics g = img.getGraphics();
     
    9390            this.image = img;
    9491            break;
    95         }
    9692        default:
    9793            if (this.image != null) {
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java

    r7005 r7025  
    614614        return ret;
    615615    }
    616 
    617     public void printTree() {
    618         printTreeRecursive(root, 0);
    619     }
    620 
    621     private void printTreeRecursive(QBLevel<T> level, int indent) {
    622         if (level == null) {
    623             printIndented(indent, "<empty child>");
    624             return;
    625         }
    626         printIndented(indent, level);
    627         if (level.hasContent()) {
    628             for (T o : level.content) {
    629                 printIndented(indent, o);
    630             }
    631         }
    632         for (QBLevel<T> child : level.getChildren()) {
    633             printTreeRecursive(child, indent + 2);
    634         }
    635     }
    636 
    637     private void printIndented(int indent, Object msg) {
    638         for (int i = 0; i < indent; i++) {
    639             System.out.print(' ');
    640         }
    641         System.out.println(msg);
    642     }
    643616}
  • trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFile.java

    r7005 r7025  
    127127        in.read(b8);
    128128        in.read(b8);
    129         shiftType = new String(b8);
     129        shiftType = new String(b8, Utils.UTF_8);
    130130        in.read(b8);
    131131        in.read(b8);
  • trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2SubGrid.java

    r6995 r7025  
    186186     */
    187187    private boolean isCoordWithin(double lon, double lat) {
    188         if ((lon >= minLon) && (lon < maxLon) && (lat >= minLat) && (lat < maxLat))
    189             return true;
    190         else
    191             return false;
     188        return (lon >= minLon) && (lon < maxLon) && (lat >= minLat) && (lat < maxLat);
    192189    }
    193190
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java

    r7005 r7025  
    101101     * Class to store relation members
    102102     */
    103     private class RelationMembers {
     103    private static class RelationMembers {
    104104        /** List of member objects of the relation */
    105105        private List<RelMember> members;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r7012 r7025  
    7171
    7272    /** The spell check key substitutions: the key should be substituted by the value */
    73     protected static Map<String, String> spellCheckKeyData;
     73    private static Map<String, String> spellCheckKeyData;
    7474    /** The spell check preset values */
    75     protected static MultiMap<String, String> presetsValueData;
     75    private static MultiMap<String, String> presetsValueData;
    7676    /** The TagChecker data */
    77     protected static final List<CheckerData> checkerData = new ArrayList<>();
    78     protected static final List<String> ignoreDataStartsWith = new ArrayList<>();
    79     protected static final List<String> ignoreDataEquals = new ArrayList<>();
    80     protected static final List<String> ignoreDataEndsWith = new ArrayList<>();
    81     protected static final List<IgnoreKeyPair> ignoreDataKeyPair = new ArrayList<>();
     77    private static final List<CheckerData> checkerData = new ArrayList<>();
     78    private static final List<String> ignoreDataStartsWith = new ArrayList<>();
     79    private static final List<String> ignoreDataEquals = new ArrayList<>();
     80    private static final List<String> ignoreDataEndsWith = new ArrayList<>();
     81    private static final List<IgnoreKeyPair> ignoreDataKeyPair = new ArrayList<>();
    8282
    8383    /** The preferences prefix */
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnclosedWays.java

    r7005 r7025  
    5757         * @param engMessage The English message
    5858         */
    59         @SuppressWarnings("unchecked")
    6059        public UnclosedWaysCheck(int code, String key, String engMessage) {
    61             this(code, key, engMessage, Collections.EMPTY_LIST);
     60            this(code, key, engMessage, Collections.<String>emptyList());
    6261        }
    6362       
  • trunk/src/org/openstreetmap/josm/data/validation/util/Entities.java

    r7005 r7025  
    368368                                switch (isHexChar) {
    369369                                    case 'X' :
    370                                     case 'x' : {
     370                                    case 'x' :
    371371                                        entityValue = Integer.parseInt(entityContent.substring(2), 16);
    372372                                        break;
    373                                     }
    374                                     default : {
     373                                    default :
    375374                                        entityValue = Integer.parseInt(entityContent.substring(1), 10);
    376                                     }
    377375                                }
    378376                                if (entityValue > 0xFFFF) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r7005 r7025  
    1414import java.awt.event.MouseAdapter;
    1515import java.awt.event.MouseEvent;
     16import java.io.UnsupportedEncodingException;
    1617import java.net.HttpURLConnection;
    1718import java.net.URI;
     19import java.net.URISyntaxException;
    1820import java.net.URLEncoder;
    1921import java.util.ArrayList;
     
    11421144                    }
    11431145                });
    1144             } catch (Exception e1) {
     1146            } catch (URISyntaxException | UnsupportedEncodingException e1) {
    11451147                Main.error(e1);
    11461148            }
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java

    r7005 r7025  
    184184                    BugReportExceptionHandler.handleException(e);
    185185                }
    186 
    187186            }
    188187        };
     
    200199                // reload if the history is not in the cache yet
    201200                return true;
    202             else if (!p.isNew() && h.getByVersion(p.getUniqueId()) == null)
     201            else
    203202                // reload if the history object of the selected object is not in the cache yet
    204                 return true;
    205             else
    206                 return false;
     203                return (!p.isNew() && h.getByVersion(p.getUniqueId()) == null);
    207204        }
    208205    };
     
    215212        }
    216213    };
    217 
    218214}
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r7005 r7025  
    427427            case 2:
    428428                return isCurrentPointInTime(row);
    429             case 3: {
    430                 HistoryOsmPrimitive p = getPrimitive(row);
    431                 if (p != null && p.getTimestamp() != null)
    432                     return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(p.getTimestamp());
     429            case 3:
     430                HistoryOsmPrimitive p3 = getPrimitive(row);
     431                if (p3 != null && p3.getTimestamp() != null)
     432                    return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(p3.getTimestamp());
    433433                return null;
    434             }
    435             case 4: {
    436                 HistoryOsmPrimitive p = getPrimitive(row);
    437                 if (p != null) {
    438                     User user = p.getUser();
     434            case 4:
     435                HistoryOsmPrimitive p4 = getPrimitive(row);
     436                if (p4 != null) {
     437                    User user = p4.getUser();
    439438                    if (user != null)
    440439                        return user.getName();
    441440                }
    442441                return null;
    443             }
    444442            }
    445443            return null;
  • trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java

    r7005 r7025  
    297297                OsmApi.getOsmApi().closeChangeset(changeset, progressMonitor.createSubTaskMonitor(0, false));
    298298            }
    299         } catch (Exception e) {
     299        } catch (OsmTransferException e) {
    300300            if (uploadCanceled) {
    301301                Main.info(tr("Ignoring caught exception because upload is canceled. Exception is: {0}", e.toString()));
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r7021 r7025  
    704704                    break;
    705705                case CANCEL:
    706                 {
    707706                    if (yLayer != null) {
    708707                        for (ImageEntry ie : yLayer.data) {
     
    712711                    }
    713712                    break;
    714                 }
    715713                case AGAIN:
    716714                    actionPerformed(null);
    717715                    break;
    718716                case DONE:
    719                 {
    720717                    Main.pref.put("geoimage.timezone", formatTimezone(timezone));
    721718                    Main.pref.put("geoimage.delta", Long.toString(delta * 1000));
     
    751748
    752749                    break;
    753                 }
    754750                default:
    755751                    throw new IllegalStateException();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java

    r6909 r7025  
    9999        switch (type) {
    100100            case NORMAL:
    101             {
    102                 Float widthOnDefault = getWidth(c_def, WIDTH, null);
    103                 width = getWidth(c, WIDTH, widthOnDefault);
    104                 break;
    105             }
     101                width = getWidth(c, WIDTH, getWidth(c_def, WIDTH, null));
     102                break;
    106103            case CASING:
    107             {
    108104                Float casingWidth = c.get(type.prefix + WIDTH, null, Float.class, true);
    109105                if (casingWidth == null) {
     
    115111                if (casingWidth == null)
    116112                    return null;
    117                 Float widthOnDefault = getWidth(c_def, WIDTH, null);
    118                 width = getWidth(c, WIDTH, widthOnDefault);
     113                width = getWidth(c, WIDTH, getWidth(c_def, WIDTH, null));
    119114                if (width == null) {
    120115                    width = 0f;
     
    122117                width += 2 * casingWidth;
    123118                break;
    124             }
    125119            case LEFT_CASING:
    126120            case RIGHT_CASING:
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r7024 r7025  
    13401340                    }
    13411341                }
    1342             } catch (Exception e) {
     1342            } catch (IOException e) {
    13431343                if (canceled)
    13441344                    // ignore the exception and return
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CodeProjectionChoice.java

    r7015 r7025  
    6767         * Comparator that compares the number part of the code numerically.
    6868         */
    69         private class CodeComparator implements Comparator<String> {
     69        private static class CodeComparator implements Comparator<String> {
    7070            final Pattern codePattern = Pattern.compile("([a-zA-Z]+):(\\d+)");
    7171            @Override
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/PuwgProjectionChoice.java

    r6717 r7025  
    1010public class PuwgProjectionChoice extends ListProjectionChoice {
    1111
    12     public static final String[] CODES = {
     12    private static final String[] CODES = {
    1313        "EPSG:2180",
    1414        "EPSG:2176",
     
    1717        "EPSG:2179"
    1818    };
    19     public static final String[] NAMES = {
     19
     20    private static final String[] NAMES = {
    2021        tr("PUWG 1992 (Poland)"),
    2122        tr("PUWG 2000 Zone {0} (Poland)", 5),
  • trunk/src/org/openstreetmap/josm/gui/widgets/MultiSplitLayout.java

    r7012 r7025  
    11561156            throwParseException(st, "expected '=' after " + name);
    11571157        }
    1158         if (name.equalsIgnoreCase("WEIGHT")) {
     1158        if ("WEIGHT".equalsIgnoreCase(name)) {
    11591159            if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
    11601160                node.setWeight(st.nval);
     
    11641164            }
    11651165        }
    1166         else if (name.equalsIgnoreCase("NAME")) {
     1166        else if ("NAME".equalsIgnoreCase(name)) {
    11671167            if (st.nextToken() == StreamTokenizer.TT_WORD) {
    11681168                if (node instanceof Leaf) {
     
    12181218            }
    12191219            else if (token == StreamTokenizer.TT_WORD) {
    1220                 if (st.sval.equalsIgnoreCase("WEIGHT")) {
     1220                if ("WEIGHT".equalsIgnoreCase(st.sval)) {
    12211221                    parseAttribute(st.sval, st, parent);
    12221222                }
  • trunk/src/org/openstreetmap/josm/io/DefaultProxySelector.java

    r7005 r7025  
    2929
    3030    private static final List<Proxy> NO_PROXY_LIST = Collections.singletonList(Proxy.NO_PROXY);
     31   
     32    private static final String IPV4_LOOPBACK = "127.0.0.1";
     33    private static final String IPV6_LOOPBACK = "::1";
    3134
    3235    /**
     
    142145        proxyExceptions = new HashSet<>(
    143146            Main.pref.getCollection(ProxyPreferencesPanel.PROXY_EXCEPTIONS,
    144                     Arrays.asList(new String[]{"localhost", "127.0.0.1"}))
     147                    Arrays.asList(new String[]{"localhost", IPV4_LOOPBACK, IPV6_LOOPBACK}))
    145148        );
    146149    }
  • trunk/src/org/openstreetmap/josm/io/OsmChangeReader.java

    r7012 r7025  
    2222     * List of possible actions.
    2323     */
    24     public static final String[] ACTIONS = {"create", "modify", "delete"};
     24    private static final String[] ACTIONS = {"create", "modify", "delete"};
    2525
    2626    /**
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r7013 r7025  
    5555
    5656    /** Used by plugins to register themselves as data postprocessors. */
    57     public static List<OsmServerReadPostprocessor> postprocessors;
     57    private static List<OsmServerReadPostprocessor> postprocessors;
    5858
    5959    /** register a new postprocessor */
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r7012 r7025  
    185185     * List of unmaintained plugins. Not really up-to-date as the vast majority of plugins are not really maintained after a few months, sadly...
    186186     */
    187     public static final String [] UNMAINTAINED_PLUGINS = new String[] {"gpsbabelgui", "Intersect_way"};
     187    private static final String [] UNMAINTAINED_PLUGINS = new String[] {"gpsbabelgui", "Intersect_way"};
    188188
    189189    /**
  • trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java

    r6830 r7025  
    1111import javax.sound.sampled.AudioSystem;
    1212import javax.sound.sampled.DataLine;
     13import javax.sound.sampled.LineUnavailableException;
    1314import javax.sound.sampled.SourceDataLine;
     15import javax.sound.sampled.UnsupportedAudioFileException;
    1416import javax.swing.JOptionPane;
    1517
     
    339341                    }
    340342                    command.ok(stateChange);
    341                 } catch (Exception startPlayingException) {
     343                } catch (LineUnavailableException | IOException | UnsupportedAudioFileException startPlayingException) {
    342344                    command.failed(startPlayingException); // sets state
    343345                }
  • trunk/src/org/openstreetmap/josm/tools/AudioUtil.java

    r6889 r7025  
    33
    44import java.io.File;
     5import java.io.IOException;
     6import java.net.MalformedURLException;
    57import java.net.URL;
    68
     
    810import javax.sound.sampled.AudioInputStream;
    911import javax.sound.sampled.AudioSystem;
     12import javax.sound.sampled.UnsupportedAudioFileException;
    1013
    1114import org.openstreetmap.josm.Main;
     
    4043            double calibration = Main.pref.getDouble("audio.calibration", 1.0 /* default, ratio */);
    4144            return naturalLength / calibration;
    42         } catch (Exception e) {
     45        } catch (UnsupportedAudioFileException | IOException e) {
    4346            return 0.0;
    4447        }
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r7024 r7025  
    770770                @Override
    771771                public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    772                     if (localName.equalsIgnoreCase("img")) {
     772                    if ("img".equalsIgnoreCase(localName)) {
    773773                        String val = atts.getValue("src");
    774774                        if (val.endsWith(fn))
Note: See TracChangeset for help on using the changeset viewer.