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

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

Location:
trunk/src/org/openstreetmap/josm/data
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.