Changeset 8848 in josm


Ignore:
Timestamp:
2015-10-10T14:08:30+02:00 (9 years ago)
Author:
Don-vip
Message:

sonar - squid:S2131 - Primitives should not be boxed just for "String" conversion

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r8846 r8848  
    296296        @Override
    297297        public String toString() {
    298             String s = "ImageryPreferenceEntry [name=" + name;
     298            StringBuilder s = new StringBuilder("ImageryPreferenceEntry [name=").append(name);
    299299            if (id != null) {
    300                 s += " id=" + id;
    301             }
    302             s += ']';
    303             return s;
     300                s.append(" id=").append(id);
     301            }
     302            s.append(']');
     303            return s.toString();
    304304        }
    305305    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r8846 r8848  
    131131    protected EditableList sourcesList;
    132132
    133     protected static final Entities entities = new Entities();
    134 
    135133    private static final List<String> DEFAULT_SOURCES = Arrays.asList(/*DATA_FILE, */IGNORE_FILE, SPELL_FILE);
    136134
     
    371369                withErrors.put(p, "SPACE");
    372370            }
    373             if (checkValues && value != null && !value.equals(entities.unescape(value)) && !withErrors.contains(p, "HTML")) {
     371            if (checkValues && value != null && !value.equals(Entities.unescape(value)) && !withErrors.contains(p, "HTML")) {
    374372                errors.add(new TestError(this, Severity.OTHER, tr("Property values contain HTML entity"),
    375373                        tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p));
     
    620618                        commands.add(new ChangePropertyKeyCommand(p, key, Tag.removeWhiteSpaces(key)));
    621619                    } else {
    622                         String evalue = entities.unescape(value);
     620                        String evalue = Entities.unescape(value);
    623621                        if (!evalue.equals(value)) {
    624622                            commands.add(new ChangePropertyCommand(p, key, evalue));
  • trunk/src/org/openstreetmap/josm/data/validation/util/Entities.java

    r8840 r8848  
    3131 * @see <a href="http://www.w3.org/TR/html401/charset.html#code-position">HTML 4.01 Code positions</a>
    3232 */
    33 public class Entities {
     33public final class Entities {
    3434    private static final String[][] ARRAY = {
    3535        /* BASIC */
     
    336336    private static volatile Map<String, String> mapNameToValue;
    337337
    338     public String unescape(String str) {
     338    private Entities() {
     339        // Private constructor for utilities classes
     340    }
     341
     342    public static String unescape(String str) {
    339343        int firstAmp = str.indexOf('&');
    340344        if (firstAmp < 0)
    341345            return str;
    342         String res = str.substring(0, firstAmp);
     346        StringBuilder res = new StringBuilder(str.substring(0, firstAmp));
    343347        int len = str.length();
    344348        for (int i = firstAmp; i < len; i++) {
     
    348352                int semiColonIdx = str.indexOf(';', nextIdx);
    349353                if (semiColonIdx == -1) {
    350                     res += c;
     354                    res.append(c);
    351355                    continue;
    352356                }
     
    354358                if (amphersandIdx != -1 && amphersandIdx < semiColonIdx) {
    355359                    // Then the text looks like &...&...;
    356                     res += c;
     360                    res.append(c);
    357361                    continue;
    358362                }
     
    394398
    395399                if (entityValue == -1) {
    396                     res += '&' + entityContent + ';';
     400                    res.append('&').append(entityContent).append(';');
    397401                } else {
    398                     res += (char) entityValue;
     402                    res.append((char) entityValue);
    399403                }
    400404                i = semiColonIdx; // move index up to the semi-colon
    401405            } else {
    402                 res += c;
     406                res.append(c);
    403407            }
    404408        }
    405         return res;
     409        return res.toString();
    406410    }
    407411}
  • trunk/src/org/openstreetmap/josm/gui/FileDrop.java

    r8540 r8848  
    155155
    156156    // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
    157     private static final String ZERO_CHAR_STRING = "" + (char) 0;
     157    private static final String ZERO_CHAR_STRING = Character.toString((char) 0);
    158158
    159159    private static File[] createFileArray(BufferedReader bReader) {
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

    r8846 r8848  
    9696                });
    9797            }
    98             String names = null;
     98            StringBuilder names = new StringBuilder();
    9999            for (File file : sel) {
    100                 if (names == null) {
    101                     names = " (";
     100                if (names.length() == 0) {
     101                    names.append(" (");
    102102                } else {
    103                     names += ", ";
    104                 }
    105                 names += file.getName();
    106             }
    107             if (names != null) {
    108                 names += ')';
    109             } else {
    110                 names = "";
     103                    names.append(", ");
     104                }
     105                names.append(file.getName());
     106            }
     107            if (names.length() > 0) {
     108                names.append(')');
    111109            }
    112110            MarkerLayer ml = new MarkerLayer(new GpxData(),
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r8846 r8848  
    7171        long minutes_left = ms_left / MSECS_PER_MINUTE;
    7272        long seconds_left = (ms_left / MSECS_PER_SECOND) % SECONDS_PER_MINUTE;
    73         String time_left_str = Long.toString(minutes_left) + ':';
     73        StringBuilder time_left_str = new StringBuilder().append(minutes_left).append(':');
    7474        if (seconds_left < 10) {
    75             time_left_str += '0';
    76         }
    77         return time_left_str + Long.toString(seconds_left);
     75            time_left_str.append('0');
     76        }
     77        return time_left_str.append(seconds_left).toString();
    7878    }
    7979
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r8846 r8848  
    289289            canHtml = false;
    290290        }
    291         String result = "";
     291        StringBuilder result = new StringBuilder();
    292292        if (canHtml) {
    293             result += "<html>";
    294         }
    295         result += name;
     293            result.append("<html>");
     294        }
     295        result.append(name);
    296296        if (sc != null && !sc.getKeyText().isEmpty()) {
    297             result += ' ';
     297            result.append(' ');
    298298            if (canHtml) {
    299                 result += "<font size='-2'>";
    300             }
    301             result += '('+sc.getKeyText()+')';
     299                result.append("<font size='-2'>");
     300            }
     301            result.append('(').append(sc.getKeyText()).append(')');
    302302            if (canHtml) {
    303                 result += "</font>";
     303                result.append("</font>");
    304304            }
    305305        }
    306306        if (canHtml) {
    307             result += "&nbsp;</html>";
    308         }
    309         return result;
     307            result.append("&nbsp;</html>");
     308        }
     309        return result.toString();
    310310    }
    311311
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r8846 r8848  
    149149    @Override
    150150    public String makeTooltip(String name, Shortcut sc) {
    151         String result = "";
    152         result += "<html>";
    153         result += name;
     151        StringBuilder result = new StringBuilder();
     152        result.append("<html>").append(name);
    154153        if (sc != null && !sc.getKeyText().isEmpty()) {
    155             result += ' ';
    156             result += "<font size='-2'>";
    157             result += '('+sc.getKeyText()+')';
    158             result += "</font>";
    159         }
    160         return result + "&nbsp;</html>";
     154            result.append(' ')
     155                  .append("<font size='-2'>")
     156                  .append('(').append(sc.getKeyText()).append(')')
     157                  .append("</font>");
     158        }
     159        return result.append("&nbsp;</html>").toString();
    161160    }
    162161
Note: See TracChangeset for help on using the changeset viewer.