Skip to content

Commit 62b2f8e

Browse files
committed
Merge pull request iluwatar#357 from DevFactory/release/Consecutive-Appends-Should-Reuse-fix-1
pmd:ConsecutiveAppendsShouldReuse - Consecutive Appends Should Reuse
2 parents ab2aad3 + d00bfae commit 62b2f8e

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

builder/src/main/java/com/iluwatar/builder/Hero.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,25 @@ public Weapon getWeapon() {
4242
public String toString() {
4343

4444
StringBuilder sb = new StringBuilder();
45-
sb.append("This is a ");
46-
sb.append(profession);
47-
sb.append(" named ");
48-
sb.append(name);
45+
sb.append("This is a ")
46+
.append(profession)
47+
.append(" named ")
48+
.append(name);
4949
if (hairColor != null || hairType != null) {
5050
sb.append(" with ");
5151
if (hairColor != null) {
52-
sb.append(hairColor);
53-
sb.append(" ");
52+
sb.append(hairColor).append(" ");
5453
}
5554
if (hairType != null) {
56-
sb.append(hairType);
57-
sb.append(" ");
55+
sb.append(hairType).append(" ");
5856
}
5957
sb.append(hairType != HairType.BALD ? "hair" : "head");
6058
}
6159
if (armor != null) {
62-
sb.append(" wearing ");
63-
sb.append(armor);
60+
sb.append(" wearing ").append(armor);
6461
}
6562
if (weapon != null) {
66-
sb.append(" and wielding a ");
67-
sb.append(weapon);
63+
sb.append(" and wielding a ").append(weapon);
6864
}
6965
sb.append(".");
7066
return sb.toString();

dao/src/test/java/com/iluwatar/dao/CustomerTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public void equalsWithSameObjects() {
6363
@Test
6464
public void testToString() {
6565
final StringBuffer buffer = new StringBuffer();
66-
buffer.append("Customer{id=");
67-
buffer.append("" + customer.getId());
68-
buffer.append(", firstName='");
69-
buffer.append(customer.getFirstName());
70-
buffer.append("\', lastName='");
71-
buffer.append(customer.getLastName() + "\'}");
66+
buffer.append("Customer{id=")
67+
.append("" + customer.getId())
68+
.append(", firstName='")
69+
.append(customer.getFirstName())
70+
.append("\', lastName='")
71+
.append(customer.getLastName() + "\'}");
7272
assertEquals(buffer.toString(), customer.toString());
7373
}
7474
}

step-builder/src/main/java/com/iluwatar/stepbuilder/Character.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ public void setAbilities(List<String> abilities) {
6969
@Override
7070
public String toString() {
7171
StringBuilder sb = new StringBuilder();
72-
sb.append("This is a ");
73-
sb.append(fighterClass != null ? fighterClass : wizardClass);
74-
sb.append(" named ");
75-
sb.append(name);
76-
sb.append(" armed with a ");
77-
sb.append(weapon != null ? weapon : spell != null ? spell : "with nothing");
78-
sb.append(abilities != null ? (" and wielding " + abilities + " abilities") : "");
79-
sb.append(".");
72+
sb.append("This is a ")
73+
.append(fighterClass != null ? fighterClass : wizardClass)
74+
.append(" named ")
75+
.append(name)
76+
.append(" armed with a ")
77+
.append(weapon != null ? weapon : spell != null ? spell : "with nothing")
78+
.append(abilities != null ? (" and wielding " + abilities + " abilities") : "")
79+
.append(".");
8080
return sb.toString();
8181
}
8282
}

0 commit comments

Comments
 (0)