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() { |   public String toString() { | ||||||
|  |  | ||||||
|     StringBuilder sb = new StringBuilder(); |     StringBuilder sb = new StringBuilder(); | ||||||
|     sb.append("This is a "); |     sb.append("This is a ") | ||||||
|     sb.append(profession); |             .append(profession) | ||||||
|     sb.append(" named "); |             .append(" named ") | ||||||
|     sb.append(name); |             .append(name); | ||||||
|     if (hairColor != null || hairType != null) { |     if (hairColor != null || hairType != null) { | ||||||
|       sb.append(" with "); |       sb.append(" with "); | ||||||
|       if (hairColor != null) { |       if (hairColor != null) { | ||||||
|         sb.append(hairColor); |         sb.append(hairColor).append(" "); | ||||||
|         sb.append(" "); |  | ||||||
|       } |       } | ||||||
|       if (hairType != null) { |       if (hairType != null) { | ||||||
|         sb.append(hairType); |         sb.append(hairType).append(" "); | ||||||
|         sb.append(" "); |  | ||||||
|       } |       } | ||||||
|       sb.append(hairType != HairType.BALD ? "hair" : "head"); |       sb.append(hairType != HairType.BALD ? "hair" : "head"); | ||||||
|     } |     } | ||||||
|     if (armor != null) { |     if (armor != null) { | ||||||
|       sb.append(" wearing "); |       sb.append(" wearing ").append(armor); | ||||||
|       sb.append(armor); |  | ||||||
|     } |     } | ||||||
|     if (weapon != null) { |     if (weapon != null) { | ||||||
|       sb.append(" and wielding a "); |       sb.append(" and wielding a ").append(weapon); | ||||||
|       sb.append(weapon); |  | ||||||
|     } |     } | ||||||
|     sb.append("."); |     sb.append("."); | ||||||
|     return sb.toString(); |     return sb.toString(); | ||||||
|   | |||||||
| @@ -63,12 +63,12 @@ public class CustomerTest { | |||||||
|   @Test |   @Test | ||||||
|   public void testToString() { |   public void testToString() { | ||||||
|     final StringBuffer buffer = new StringBuffer(); |     final StringBuffer buffer = new StringBuffer(); | ||||||
|     buffer.append("Customer{id="); |     buffer.append("Customer{id=") | ||||||
|     buffer.append("" + customer.getId()); |             .append("" + customer.getId()) | ||||||
|     buffer.append(", firstName='"); |             .append(", firstName='") | ||||||
|     buffer.append(customer.getFirstName()); |             .append(customer.getFirstName()) | ||||||
|     buffer.append("\', lastName='"); |             .append("\', lastName='") | ||||||
|     buffer.append(customer.getLastName() + "\'}"); |             .append(customer.getLastName() + "\'}"); | ||||||
|     assertEquals(buffer.toString(), customer.toString()); |     assertEquals(buffer.toString(), customer.toString()); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -69,14 +69,14 @@ public class Character { | |||||||
|   @Override |   @Override | ||||||
|   public String toString() { |   public String toString() { | ||||||
|     StringBuilder sb = new StringBuilder(); |     StringBuilder sb = new StringBuilder(); | ||||||
|     sb.append("This is a "); |     sb.append("This is a ") | ||||||
|     sb.append(fighterClass != null ? fighterClass : wizardClass); |             .append(fighterClass != null ? fighterClass : wizardClass) | ||||||
|     sb.append(" named "); |             .append(" named ") | ||||||
|     sb.append(name); |             .append(name) | ||||||
|     sb.append(" armed with a "); |             .append(" armed with a ") | ||||||
|     sb.append(weapon != null ? weapon : spell != null ? spell : "with nothing"); |             .append(weapon != null ? weapon : spell != null ? spell : "with nothing") | ||||||
|     sb.append(abilities != null ? (" and wielding " + abilities + " abilities") : ""); |             .append(abilities != null ? (" and wielding " + abilities + " abilities") : "") | ||||||
|     sb.append("."); |             .append("."); | ||||||
|     return sb.toString(); |     return sb.toString(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user