Merge pull request #357 from DevFactory/release/Consecutive-Appends-Should-Reuse-fix-1
pmd:ConsecutiveAppendsShouldReuse - Consecutive Appends Should Reuse
This commit is contained in:
		| @@ -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(); | ||||
|   | ||||
| @@ -63,12 +63,12 @@ public class CustomerTest { | ||||
|   @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()); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -69,14 +69,14 @@ public class Character { | ||||
|   @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(); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user