1 4 package com.tc.util.stringification; 5 6 import org.apache.commons.lang.SystemUtils; 7 import org.apache.commons.lang.builder.StandardToStringStyle; 8 import org.apache.commons.lang.builder.ToStringBuilder; 9 import org.apache.commons.lang.builder.ToStringStyle; 10 11 14 public class OurStringBuilder extends ToStringBuilder { 15 16 public static StandardToStringStyle STANDARD_STYLE; 17 public static StandardToStringStyle MULTI_LINE_STYLE; 18 public static StandardToStringStyle COMPACT_STYLE; 19 20 static { 21 STANDARD_STYLE = new StandardToStringStyle(); 22 STANDARD_STYLE.setUseShortClassName(true); 23 STANDARD_STYLE.setArrayContentDetail(true); 24 STANDARD_STYLE.setFieldSeparator(", "); 25 STANDARD_STYLE.setArraySeparator(", "); 26 27 MULTI_LINE_STYLE = new StandardToStringStyle(); 28 MULTI_LINE_STYLE.setUseShortClassName(true); 29 MULTI_LINE_STYLE.setArrayContentDetail(true); 30 MULTI_LINE_STYLE.setContentStart("["); 31 MULTI_LINE_STYLE.setFieldSeparator(SystemUtils.LINE_SEPARATOR + " "); 32 MULTI_LINE_STYLE.setFieldSeparatorAtStart(true); 33 MULTI_LINE_STYLE.setContentEnd(SystemUtils.LINE_SEPARATOR + "]"); 34 MULTI_LINE_STYLE.setArraySeparator(", "); 35 36 COMPACT_STYLE = new StandardToStringStyle() { 37 public void appendStart(StringBuffer buffer, Object object) { 38 buffer.append("<"); 39 appendClassName(buffer, object); 40 appendIdentityHashCode(buffer, object); 41 appendContentStart(buffer); 42 } 43 }; 44 COMPACT_STYLE.setUseShortClassName(true); 45 COMPACT_STYLE.setArrayContentDetail(true); 46 COMPACT_STYLE.setContentStart(": "); 47 COMPACT_STYLE.setContentEnd(">"); 48 COMPACT_STYLE.setFieldNameValueSeparator(" "); 49 COMPACT_STYLE.setFieldSeparator(", "); 50 COMPACT_STYLE.setArraySeparator(", "); 51 } 52 53 public OurStringBuilder(Object arg0, ToStringStyle arg1, StringBuffer arg2) { 54 super(arg0, arg1, arg2); 55 } 56 57 public OurStringBuilder(Object arg0, ToStringStyle arg1) { 58 super(arg0, arg1); 59 } 60 61 public OurStringBuilder(Object arg0) { 62 this(arg0, STANDARD_STYLE); 63 } 64 65 public ToStringBuilder append(String tag, Object []arr, boolean b) { 66 if (arr == null) return super.append(tag, arr, b); 67 if (arr.length == 0) return super.append(tag, arr, b); 68 this.append("{elementCount=" + arr.length + ":"); 69 for (int i = 0; i < arr.length; i++) { 70 Object e = arr[i]; 71 if (e == null) this.append("<null>"); 72 else this.append("[#" + i + "<" + e.getClass().getName() + "=" + e + ">]"); 73 } 74 this.append("]"); 75 return this; 76 } 77 78 } 79 | Popular Tags |