-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#33 "source code style rule definition"
- implementation of equals(...), hashCode() and toString()
- Loading branch information
1 parent
63a2d72
commit 3c27d83
Showing
12 changed files
with
354 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
test-gap-analysis/src/main/java/com/scheible/testgapanalysis/common/ToStringBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.scheible.testgapanalysis.common; | ||
|
||
/** | ||
* Simplistic toString() builder backed by a {@code StringBuilder}. | ||
* | ||
* @author sj | ||
*/ | ||
public class ToStringBuilder { | ||
|
||
private final StringBuilder stringBuilder = new StringBuilder(); | ||
|
||
private boolean appended = false; | ||
|
||
public ToStringBuilder(final Class<?> clazz) { | ||
stringBuilder.append(clazz.getSimpleName()).append('['); | ||
|
||
} | ||
|
||
public ToStringBuilder append(final String fieldName, final Object value) { | ||
if (appended) { | ||
stringBuilder.append(", "); | ||
} | ||
appended = true; | ||
|
||
stringBuilder.append(fieldName).append('='); | ||
|
||
if (value instanceof String) { | ||
stringBuilder.append('\''); | ||
} | ||
stringBuilder.append(value); | ||
if (value instanceof String) { | ||
stringBuilder.append('\''); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public String build() { | ||
stringBuilder.append(']'); | ||
return stringBuilder.toString(); | ||
} | ||
|
||
public static String shorten(final String value, final int maxLenght) { | ||
if (value.length() <= maxLenght) { | ||
return value; | ||
} else { | ||
return value.substring(0, maxLenght) + "..."; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.