Merge pull request #357 from DevFactory/release/Consecutive-Appends-Should-Reuse-fix-1

pmd:ConsecutiveAppendsShouldReuse - Consecutive Appends Should Reuse
This commit is contained in:
Ilkka Seppälä
2016-01-30 14:37:18 +02:00
3 changed files with 22 additions and 26 deletions

View File

@@ -42,29 +42,25 @@ public class Hero {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("This is a ");
sb.append(profession);
sb.append(" named ");
sb.append(name);
sb.append("This is a ")
.append(profession)
.append(" named ")
.append(name);
if (hairColor != null || hairType != null) {
sb.append(" with ");
if (hairColor != null) {
sb.append(hairColor);
sb.append(" ");
sb.append(hairColor).append(" ");
}
if (hairType != null) {
sb.append(hairType);
sb.append(" ");
sb.append(hairType).append(" ");
}
sb.append(hairType != HairType.BALD ? "hair" : "head");
}
if (armor != null) {
sb.append(" wearing ");
sb.append(armor);
sb.append(" wearing ").append(armor);
}
if (weapon != null) {
sb.append(" and wielding a ");
sb.append(weapon);
sb.append(" and wielding a ").append(weapon);
}
sb.append(".");
return sb.toString();