tostringstyle.java
来自「JAVA 文章管理系统源码」· Java 代码 · 共 1,857 行 · 第 1/5 页
JAVA
1,857 行
public void append(StringBuffer buffer, String fieldName, double[] array, Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* <p>Append to the <code>toString</code> the detail of a
* <code>double</code> array.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the <code>toString</code>,
* not <code>null</code>
*/
protected void appendDetail(StringBuffer buffer, String fieldName, double[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* <p>Append to the <code>toString</code> a summary of a
* <code>double</code> array.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the <code>toString</code>,
* not <code>null</code>
*/
protected void appendSummary(StringBuffer buffer, String fieldName, double[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
//----------------------------------------------------------------------------
/**
* <p>Append to the <code>toString</code> a <code>float</code>
* array.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name
* @param array the array to add to the toString
* @param fullDetail <code>true</code> for detail, <code>false</code>
* for summary info, <code>null</code> for style decides
*/
public void append(StringBuffer buffer, String fieldName, float[] array, Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* <p>Append to the <code>toString</code> the detail of a
* <code>float</code> array.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the <code>toString</code>,
* not <code>null</code>
*/
protected void appendDetail(StringBuffer buffer, String fieldName, float[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* <p>Append to the <code>toString</code> a summary of a
* <code>float</code> array.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the <code>toString</code>,
* not <code>null</code>
*/
protected void appendSummary(StringBuffer buffer, String fieldName, float[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
//----------------------------------------------------------------------------
/**
* <p>Append to the <code>toString</code> a <code>boolean</code>
* array.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name
* @param array the array to add to the toString
* @param fullDetail <code>true</code> for detail, <code>false</code>
* for summary info, <code>null</code> for style decides
*/
public void append(StringBuffer buffer, String fieldName, boolean[] array, Boolean fullDetail) {
appendFieldStart(buffer, fieldName);
if (array == null) {
appendNullText(buffer, fieldName);
} else if (isFullDetail(fullDetail)) {
appendDetail(buffer, fieldName, array);
} else {
appendSummary(buffer, fieldName, array);
}
appendFieldEnd(buffer, fieldName);
}
/**
* <p>Append to the <code>toString</code> the detail of a
* <code>boolean</code> array.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the <code>toString</code>,
* not <code>null</code>
*/
protected void appendDetail(StringBuffer buffer, String fieldName, boolean[] array) {
buffer.append(arrayStart);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
buffer.append(arraySeparator);
}
appendDetail(buffer, fieldName, array[i]);
}
buffer.append(arrayEnd);
}
/**
* <p>Append to the <code>toString</code> a summary of a
* <code>boolean</code> array.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
* @param array the array to add to the <code>toString</code>,
* not <code>null</code>
*/
protected void appendSummary(StringBuffer buffer, String fieldName, boolean[] array) {
appendSummarySize(buffer, fieldName, array.length);
}
//----------------------------------------------------------------------------
/**
* <p>Append to the <code>toString</code> the class name.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param object the <code>Object</code> whose name to output
*/
protected void appendClassName(StringBuffer buffer, Object object) {
if (useClassName) {
if (useShortClassName) {
buffer.append(getShortClassName(object.getClass()));
} else {
buffer.append(object.getClass().getName());
}
}
}
/**
* <p>Append the {@link System#identityHashCode(java.lang.Object)}.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param object the <code>Object</code> whose id to output
*/
protected void appendIdentityHashCode(StringBuffer buffer, Object object) {
if (useIdentityHashCode) {
buffer.append('@');
buffer.append(Integer.toHexString(System.identityHashCode(object)));
}
}
/**
* <p>Append to the <code>toString</code> the content start.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
*/
protected void appendContentStart(StringBuffer buffer) {
buffer.append(contentStart);
}
/**
* <p>Append to the <code>toString</code> the content end.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
*/
protected void appendContentEnd(StringBuffer buffer) {
buffer.append(contentEnd);
}
/**
* <p>Append to the <code>toString</code> an indicator for <code>null</code>.</p>
*
* <p>The default indicator is <code>'<null>'</code>.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
*/
protected void appendNullText(StringBuffer buffer, String fieldName) {
buffer.append(nullText);
}
/**
* <p>Append to the <code>toString</code> the field separator.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
*/
protected void appendFieldSeparator(StringBuffer buffer) {
buffer.append(fieldSeparator);
}
/**
* <p>Append to the <code>toString</code> the field start.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name
*/
protected void appendFieldStart(StringBuffer buffer, String fieldName) {
if (useFieldNames && fieldName != null) {
buffer.append(fieldName);
buffer.append(fieldNameValueSeparator);
}
}
/**
* <p>Append to the <code>toString<code> the field end.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
*/
protected void appendFieldEnd(StringBuffer buffer, String fieldName) {
appendFieldSeparator(buffer);
}
/**
* <p>Append to the <code>toString</code> a size summary.</p>
*
* <p>The size summary is used to summarize the contents of
* <code>Collections</code>, <code>Maps</code> and arrays.</p>
*
* <p>The output consists of a prefix, the passed in size
* and a suffix.</p>
*
* <p>The default format is <code>'<size=n>'<code>.</p>
*
* @param buffer the <code>StringBuffer</code> to populate
* @param fieldName the field name, typically not used as already appended
* @param size the size to append
*/
protected void appendSummarySize(StringBuffer buffer, String fieldName, int size) {
buffer.append(sizeStartText);
buffer.append(size);
buffer.append(sizeEndText);
}
/**
* <p>Is this field to be output in full detail.</p>
*
* <p>This method converts a detail request into a detail level.
* The calling code may request full detail (<code>true</code>),
* but a subclass might ignore that and always return
* <code>false</code>. The calling code may pass in
* <code>null</code> indicating that it doesn't care about
* the detail level. In this case the default detail level is
* used.</p>
*
* @param fullDetailRequest the detail level requested
* @return whether full detail is to be shown
*/
protected boolean isFullDetail(Boolean fullDetailRequest) {
if (fullDetailRequest == null) {
return defaultFullDetail;
}
return fullDetailRequest.booleanValue();
}
/**
* <p>Gets the short class name for a class.</p>
*
* <p>The short class name is the classname excluding
* the package name.</p>
*
* @param cls the <code>Class</code> to get the short name of
* @return the short name
*/
protected String getShortClassName(Class cls) {
return ClassUtils.getShortClassName(cls);
}
// Setters and getters for the customizable parts of the style
// These methods are not expected to be overridden, except to make public
// (They are not public so that immutable subclasses can be written)
//---------------------------------------------------------------------
/**
* <p>Gets whether to use the class name.</p>
*
* @return the current useClassName flag
*/
protected boolean isUseClassName() {
return useClassName;
}
/**
* <p>Sets whether to use the class name.</p>
*
* @param useClassName the new useClassName flag
*/
protected void setUseClassName(boolean useClassName) {
this.useClassName = useClassName;
}
//---------------------------------------------------------------------
/**
* <p>Gets whether to output short or long class names.</p>
*
* @return the current useShortClassName flag
* @since 2.0
*/
protected boolean isUseShortClassName() {
return useShortClassName;
}
/**
* <p>Gets whether to output short or long class names.</p>
*
* @return the current shortClassName flag
* @deprecated Use {@link #isUseShortClassName()}
* Method will be removed in Commons Lang 3.0.
*/
protected boolean isShortClassName() {
return useShortClassName;
}
/**
* <p>Sets whether to output short or long class names.</p>
*
* @param useShortClassName the new useShortClassName flag
* @since 2.0
*/
protected void setUseShortClassName(boolean useShortClassName) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?