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


Ignore:
Timestamp:
2013-09-27T01:16:28+02:00 (11 years ago)
Author:
Don-vip
Message:

Sonar/FindBugs - Performance - Method concatenates strings using + in a loop

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

Legend:

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

    r6245 r6264  
    156156     */
    157157    public String findSummaryDocumentation() {
    158         String result = "<table>";
     158        StringBuilder result = new StringBuilder("<table>");
    159159        for (Class<? extends DownloadTask> taskClass : downloadTasks) {
    160160            if (taskClass != null) {
    161161                try {
    162162                    DownloadTask task = taskClass.getConstructor().newInstance();
    163                     result += task.acceptsDocumentationSummary();
     163                    result.append(task.acceptsDocumentationSummary());
    164164                } catch (Exception e) {
    165165                    e.printStackTrace();
     
    167167            }
    168168        }
    169         result += "</table>";
    170         return result;
     169        result.append("</table>");
     170        return result.toString();
    171171    }
    172172
  • trunk/src/org/openstreetmap/josm/corrector/ReverseWayNoTagCorrector.java

    r5732 r6264  
    6464            return tags.iterator().next().toString();
    6565        } else if (tags.size() > 1) {
    66             String s = "<ul>";
     66            StringBuilder s = new StringBuilder("<ul>");
    6767            for (Tag t : tags) {
    68                 s += "<li>" + t.toString() + "</li>";
     68                s.append("<li>").append(t).append("</li>");
    6969            }
    70             s += "</ul>";
    71             return s;
     70            s.append("</ul>");
     71            return s.toString();
    7272        } else {
    7373            return "";
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r6248 r6264  
    144144            if (i.bounds != null) {
    145145                bounds = i.bounds.encodeAsString(",");
    146                 String shapesString = "";
     146                StringBuilder shapesString = new StringBuilder();
    147147                for (Shape s : i.bounds.getShapes()) {
    148                     if (!shapesString.isEmpty()) {
    149                         shapesString += ";";
     148                    if (shapesString.length() > 0) {
     149                        shapesString.append(";");
    150150                    }
    151                     shapesString += s.encodeAsString(",");
    152                 }
    153                 if (!shapesString.isEmpty()) {
    154                     shapes = shapesString;
     151                    shapesString.append(s.encodeAsString(","));
     152                }
     153                if (shapesString.length() > 0) {
     154                    shapes = shapesString.toString();
    155155                }
    156156            }
  • trunk/src/org/openstreetmap/josm/data/osm/TigerUtils.java

    r6231 r6264  
    4444            }
    4545        }
    46         String combined = "";
     46        StringBuilder combined = new StringBuilder();
    4747        for (Object part : resultSet) {
    48             if (combined.length() > 0)
    49                 combined += ":";
    50             combined += part;
     48            if (combined.length() > 0) {
     49                combined.append(":");
     50            }
     51            combined.append(part);
    5152        }
    52         return combined;
     53        return combined.toString();
    5354    }
    5455
  • trunk/src/org/openstreetmap/josm/data/osm/history/History.java

    r6084 r6264  
    241241    @Override
    242242    public String toString() {
    243         String result = "History ["
    244                 + (type != null ? "type=" + type + ", " : "") + "id=" + id;
     243        StringBuilder result = new StringBuilder("History ["
     244                + (type != null ? "type=" + type + ", " : "") + "id=" + id);
    245245        if (versions != null) {
    246             result += ", versions=\n";
     246            result.append(", versions=\n");
    247247            for (HistoryOsmPrimitive v : versions) {
    248                 result += "\t" + v + ",\n";
     248                result.append("\t").append(v).append(",\n");
    249249            }
    250250        }
    251         result += "]";
    252         return result;
     251        result.append("]");
     252        return result.toString();
    253253    }
    254254}
  • trunk/src/org/openstreetmap/josm/data/validation/TestError.java

    r6069 r6264  
    170170    public String getIgnoreState() {
    171171        Collection<String> strings = new TreeSet<String>();
    172         String ignorestring = getIgnoreSubGroup();
     172        StringBuilder ignorestring = new StringBuilder(getIgnoreSubGroup());
    173173        for (OsmPrimitive o : primitives) {
    174174            // ignore data not yet uploaded
     
    186186        }
    187187        for (String o : strings) {
    188             ignorestring += ":" + o;
    189         }
    190         return ignorestring;
     188            ignorestring.append(":").append(o);
     189        }
     190        return ignorestring.toString();
    191191    }
    192192
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r6251 r6264  
    686686        Main.pref.put(PREF_USE_IGNORE_FILE, prefUseIgnoreFile.isSelected());
    687687        Main.pref.put(PREF_USE_SPELL_FILE, prefUseSpellFile.isSelected());
    688         String sources = "";
     688        StringBuilder sources = new StringBuilder();
    689689        if (sourcesList.getModel().getSize() > 0) {
    690             String sb = "";
    691690            for (int i = 0; i < sourcesList.getModel().getSize(); ++i) {
    692                 sb += ";"+sourcesList.getModel().getElementAt(i);
    693             }
    694             sources = sb.substring(1);
    695         }
    696         if (sources.length() == 0) {
    697             sources = null;
    698         }
    699         return Main.pref.put(PREF_SOURCES, sources);
     691                if (sources.length() > 0) {
     692                    sources.append(";");
     693                }
     694                sources.append(sourcesList.getModel().getElementAt(i));
     695            }
     696        }
     697        return Main.pref.put(PREF_SOURCES, sources.length() > 0 ? sources.toString() : null);
    700698    }
    701699
  • trunk/src/org/openstreetmap/josm/data/validation/util/MultipleNameVisitor.java

    r6069 r6264  
    3333     */
    3434    public void visit(Collection<? extends OsmPrimitive> data) {
    35         String multipleName = "";
     35        StringBuilder multipleName = new StringBuilder();
    3636        String multiplePluralClassname = null;
    3737        size = data.size();
     
    4444            }
    4545            if (name != null && !name.isEmpty() && multipleName.length() <= MULTIPLE_NAME_MAX_LENGTH) {
    46                 if (!multipleName.isEmpty()) {
    47                     multipleName += ", ";
     46                if (multipleName.length() > 0) {
     47                    multipleName.append(", ");
    4848                }
    49                 multipleName += name;
     49                multipleName.append(name);
    5050            }
    5151
     
    6464        } else {
    6565            displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size);
    66             if (!multipleName.isEmpty()) {
     66            if (multipleName.length() > 0) {
    6767                if (multipleName.length() <= MULTIPLE_NAME_MAX_LENGTH) {
    6868                    displayName += ": " + multipleName;
  • trunk/src/org/openstreetmap/josm/gui/SplashScreen.java

    r6084 r6264  
    4040    private SwingRenderingProgressMonitor progressMonitor;
    4141
     42    /**
     43     * Constructs a new {@code SplashScreen}.
     44     */
    4245    public SplashScreen() {
    4346        super();
     
    157160        public void setCustomText(String message) {
    158161            if(message.isEmpty())
    159                 message = " "; /* prevent killing of additional line */
     162                message = " "; // prevent killing of additional line
    160163            lblCustomText.setText(message);
    161164            repaint();
     
    198201                messages.add(taskTitle);
    199202            }
    200             String html = "";
     203            StringBuilder html = new StringBuilder();
    201204            int i = 0;
    202205            for (String m : messages) {
    203                 html += "<p class=\"entry" + (++i) + "\">" + m + "</p>";
     206                html.append("<p class=\"entry").append(++i).append("\">").append(m).append("</p>");
    204207            }
    205208
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/properties/PropertiesMerger.java

    r6084 r6264  
    311311        if (referrers.isEmpty())
    312312            return tr("(none)");
    313         String str = "<html>";
     313        StringBuilder str = new StringBuilder("<html>");
    314314        for (OsmPrimitive r: referrers) {
    315             str = str + r.getDisplayName(DefaultNameFormatter.getInstance()) + "<br>";
    316         }
    317         str = str + "</html>";
    318         return str;
     315            str.append(r.getDisplayName(DefaultNameFormatter.getInstance())).append("<br>");
     316        }
     317        str.append("</html>");
     318        return str.toString();
    319319    }
    320320
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/PasteTagsConflictResolverDialog.java

    r6258 r6264  
    451451                setIcon(ImageProvider.get("data", "object"));
    452452            }
    453             String text = "";
     453            StringBuilder text = new StringBuilder();
    454454            for (Entry<OsmPrimitiveType, Integer> entry: stat.entrySet()) {
    455455                OsmPrimitiveType type = entry.getKey();
     
    464464                case RELATION: msg = trn("{0} relation", "{0} relations", numPrimitives, numPrimitives); break;
    465465                }
    466                 text = text.isEmpty() ? msg : text + ", " + msg;
    467             }
    468             setText(text);
     466                if (text.length() > 0) {
     467                    text.append(", ");
     468                }
     469                text.append(msg);
     470            }
     471            setText(text.toString());
    469472        }
    470473
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r6246 r6264  
    12281228                return;
    12291229            String sep = "";
    1230             String s = "";
     1230            StringBuilder s = new StringBuilder();
    12311231            for (OsmPrimitive p : sel) {
    12321232                String val = p.get(key);
     
    12441244                    t = "type:relation ";
    12451245                }
    1246                 s += sep + "(" + t + "\"" +
    1247                         org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(key) + "\"=\"" +
    1248                         org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(val) + "\")";
     1246                s.append(sep).append("(").append(t).append("\"").append(
     1247                        org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(key)).append("\"=\"").append(
     1248                        org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(val)).append("\")");
    12491249                sep = " OR ";
    12501250            }
    12511251
    1252             SearchSetting ss = new SearchSetting(s, SearchMode.replace, true, false, false);
     1252            SearchSetting ss = new SearchSetting(s.toString(), SearchMode.replace, true, false, false);
    12531253            org.openstreetmap.josm.actions.search.SearchAction.searchWithoutHistory(ss);
    12541254        }
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r6246 r6264  
    10311031    @Override
    10321032    public String nameSupportedProjections() {
    1033         String res = "";
    1034         for(String p : info.getServerProjections()) {
    1035             if(!res.isEmpty()) {
    1036                 res += ", ";
    1037             }
    1038             res += p;
     1033        StringBuilder res = new StringBuilder();
     1034        for (String p : info.getServerProjections()) {
     1035            if (res.length() > 0) {
     1036                res.append(", ");
     1037            }
     1038            res.append(p);
    10391039        }
    10401040        return tr("Supported projections are: {0}", res);
  • trunk/src/org/openstreetmap/josm/tools/WikiReader.java

    r6143 r6264  
    2222    }
    2323
     24    /**
     25     * Constructs a new {@code WikiReader}.
     26     */
    2427    public WikiReader() {
    2528        this.baseurl = Main.pref.get("help.baseurl", Main.JOSM_WEBSITE);
     
    8689
    8790    private String readNormal(BufferedReader in) throws IOException {
    88         String b = "";
     91        StringBuilder b = new StringBuilder();
    8992        for (String line = in.readLine(); line != null; line = in.readLine()) {
    9093            if (!line.contains("[[TranslatedPages]]")) {
    91                 b += line.replaceAll(" />", ">") + "\n";
     94                b.append(line.replaceAll(" />", ">")).append("\n");
    9295            }
    9396        }
Note: See TracChangeset for help on using the changeset viewer.