Format source code

This commit is contained in:
Benedikt Ritter 2015-05-01 23:51:03 +02:00
parent 07ec8ad2dd
commit 28656559d2
2 changed files with 17 additions and 22 deletions

View File

@ -2568,32 +2568,29 @@ public abstract class ToStringStyle implements Serializable {
protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
if (value == null) {
appendNullText(buffer, fieldName);
return;
}
if (value instanceof String || value instanceof Character) {
appendValueAsString(buffer, value.toString());
appendValueAsString(buffer, value.toString());
return;
}
if (value instanceof Number || value instanceof Boolean) {
buffer.append(value);
return;
buffer.append(value);
return;
}
final String valueAsString = value.toString();
if (valueAsString.startsWith(getContentStart()) && valueAsString.endsWith(getContentEnd())
|| valueAsString.startsWith(getArrayStart()) && valueAsString.startsWith(getArrayEnd())
) {
buffer.append(value);
return;
if (valueAsString.startsWith(getContentStart())
&& valueAsString.endsWith(getContentEnd())
|| valueAsString.startsWith(getArrayStart())
&& valueAsString.startsWith(getArrayEnd())) {
buffer.append(value);
return;
}
appendDetail(buffer, fieldName, valueAsString);
}

View File

@ -91,34 +91,32 @@ public class JsonToStringStyleTest {
assertEquals("{\"a\":\"hello\",\"b\":\"world\"}", new ToStringBuilder(base)
.appendSuper("{\"a\":\"hello\"}").append("b", "world").toString());
}
@Test
public void testChar() {
try {
new ToStringBuilder(base).append('A').toString();
fail("Should have generated UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
}
assertEquals("{\"a\":\"A\"}", new ToStringBuilder(base).append("a", 'A')
.toString());
assertEquals("{\"a\":\"A\",\"b\":\"B\"}", new ToStringBuilder(base).append("a", 'A').append("b", 'B')
.toString());
}
@Test
public void testDate() {
final Date now = new Date();
final Date afterNow = new Date(System.currentTimeMillis() + 1);
try {
new ToStringBuilder(base).append(now).toString();
fail("Should have generated UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
}
assertEquals("{\"now\":\"" + now.toString() +"\"}", new ToStringBuilder(base).append("now", now)
.toString());
assertEquals("{\"now\":\"" + now.toString() +"\",\"after\":\"" + afterNow.toString() + "\"}", new ToStringBuilder(base).append("now", now).append("after", afterNow)