Simplified Java code to use StringBuilder method chaining.

pull/39/merge
Project Nayuki 6 years ago
parent f3ba9c0837
commit ea29e58e9c

@ -283,14 +283,13 @@ public final class QrCode {
if (size + border * 2L > Integer.MAX_VALUE)
throw new IllegalArgumentException("Border too large");
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
sb.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
sb.append(String.format(
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 %1$d %1$d\" stroke=\"none\">\n",
size + border * 2));
sb.append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n");
sb.append("\t<path d=\"");
StringBuilder sb = new StringBuilder()
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n")
.append(String.format("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 %1$d %1$d\" stroke=\"none\">\n",
size + border * 2))
.append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n")
.append("\t<path d=\"");
boolean head = true;
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
@ -303,9 +302,10 @@ public final class QrCode {
}
}
}
sb.append("\" fill=\"#000000\"/>\n");
sb.append("</svg>\n");
return sb.toString();
return sb
.append("\" fill=\"#000000\"/>\n")
.append("</svg>\n")
.toString();
}

Loading…
Cancel
Save