From: James Ahlborn Date: Mon, 9 Sep 2013 03:31:44 +0000 (+0000) Subject: a little more revamp tostring output X-Git-Tag: jackcess-2.0.1~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c6adc0038b1822dfa77ed5e998bd08dd0519ec89;p=jackcess.git a little more revamp tostring output git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@795 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java b/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java index d909f96..437f176 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/CustomToStringStyle.java @@ -37,7 +37,7 @@ public class CustomToStringStyle extends StandardToStringStyle { private static final long serialVersionUID = 0L; - private static final String FIELD_SEP = SystemUtils.LINE_SEPARATOR + " "; + private static final String ML_FIELD_SEP = SystemUtils.LINE_SEPARATOR + " "; private static final String IMPL_SUFFIX = "Impl"; private static final int MAX_BYTE_DETAIL_LEN = 20; @@ -45,9 +45,10 @@ public class CustomToStringStyle extends StandardToStringStyle private static final long serialVersionUID = 0L; { setContentStart("["); - setFieldSeparator(FIELD_SEP); + setFieldSeparator(ML_FIELD_SEP); setFieldSeparatorAtStart(true); setFieldNameValueSeparator(": "); + setArraySeparator("," + ML_FIELD_SEP); setContentEnd(SystemUtils.LINE_SEPARATOR + "]"); setUseShortClassName(true); } @@ -121,8 +122,7 @@ public class CustomToStringStyle extends StandardToStringStyle appendInternal(sb, fieldName, iter.next(), true); } while(iter.hasNext()) { - sb.append(","); - appendFieldSeparator(sb); + sb.append(getArraySeparator()); appendInternal(sb, fieldName, iter.next(), true); } @@ -154,19 +154,18 @@ public class CustomToStringStyle extends StandardToStringStyle appendInternal(sb, fieldName, e.getValue(), true); } while(iter.hasNext()) { - sb.append(","); - appendFieldSeparator(sb); + sb.append(getArraySeparator()); Map.Entry e = iter.next(); sb.append(e.getKey()).append("="); appendInternal(sb, fieldName, e.getValue(), true); } - if(isFieldSeparatorAtStart()) { - appendFieldSeparator(sb); - } // indent entire map contents another level buffer.append(indent(sb)); + if(isFieldSeparatorAtStart()) { + appendFieldSeparator(buffer); + } buffer.append("}"); } @@ -179,16 +178,15 @@ public class CustomToStringStyle extends StandardToStringStyle private static void appendDetail(StringBuffer buffer, ByteBuffer bb) { int len = bb.remaining(); buffer.append("(").append(len).append(") "); + buffer.append(ByteUtil.toHexString(bb, bb.position(), + Math.min(len, MAX_BYTE_DETAIL_LEN))); if(len > MAX_BYTE_DETAIL_LEN) { - buffer.append(ByteUtil.toHexString(bb, len, MAX_BYTE_DETAIL_LEN)) - .append(" ..."); - } else { - buffer.append(ByteUtil.toHexString(bb, len)); + buffer.append(" ..."); } } private static String indent(Object obj) { return ((obj != null) ? obj.toString().replaceAll( - SystemUtils.LINE_SEPARATOR, FIELD_SEP) : null); + SystemUtils.LINE_SEPARATOR, ML_FIELD_SEP) : null); } } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java index 898508a..31f2c43 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/RowImpl.java @@ -60,6 +60,8 @@ public class RowImpl extends LinkedHashMap implements Row @Override public String toString() { - return "Row[" + _id + "] " + super.toString(); + return CustomToStringStyle.valueBuilder("Row[" + _id + "]") + .append(null, this) + .toString(); } }