Skip to content

Commit

Permalink
pmd:ConsecutiveAppendsShouldReuse - Consecutive Appends Should Reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed Ezzat committed Jan 26, 2016
1 parent 1a55f3a commit d00bfae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
20 changes: 8 additions & 12 deletions builder/src/main/java/com/iluwatar/builder/Hero.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,25 @@ public Weapon getWeapon() {
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();
Expand Down
12 changes: 6 additions & 6 deletions dao/src/test/java/com/iluwatar/dao/CustomerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public void equalsWithSameObjects() {
@Test
public void testToString() {
final StringBuffer buffer = new StringBuffer();
buffer.append("Customer{id=");
buffer.append("" + customer.getId());
buffer.append(", firstName='");
buffer.append(customer.getFirstName());
buffer.append("\', lastName='");
buffer.append(customer.getLastName() + "\'}");
buffer.append("Customer{id=")
.append("" + customer.getId())
.append(", firstName='")
.append(customer.getFirstName())
.append("\', lastName='")
.append(customer.getLastName() + "\'}");
assertEquals(buffer.toString(), customer.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public void setAbilities(List<String> abilities) {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("This is a ");
sb.append(fighterClass != null ? fighterClass : wizardClass);
sb.append(" named ");
sb.append(name);
sb.append(" armed with a ");
sb.append(weapon != null ? weapon : spell != null ? spell : "with nothing");
sb.append(abilities != null ? (" and wielding " + abilities + " abilities") : "");
sb.append(".");
sb.append("This is a ")
.append(fighterClass != null ? fighterClass : wizardClass)
.append(" named ")
.append(name)
.append(" armed with a ")
.append(weapon != null ? weapon : spell != null ? spell : "with nothing")
.append(abilities != null ? (" and wielding " + abilities + " abilities") : "")
.append(".");
return sb.toString();
}
}

0 comments on commit d00bfae

Please sign in to comment.