1. /* ====================================================================
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowledgement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowledgement may appear in the software itself,
  24. * if and wherever such third-party acknowledgements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Software Foundation.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package org.apache.commons.lang.builder;
  55. import java.io.Serializable;
  56. import java.lang.reflect.Array;
  57. import java.util.Collection;
  58. import java.util.Map;
  59. import org.apache.commons.lang.ClassUtils;
  60. import org.apache.commons.lang.ObjectUtils;
  61. import org.apache.commons.lang.SystemUtils;
  62. /**
  63. * <p>Controls <code>String</code> formatting for {@link ToStringBuilder}.
  64. * The main public interface is always via <code>ToStringBuilder</code>.</p>
  65. *
  66. * <p>These classes are intended to be used as <code>Singletons</code>.
  67. * There is no need to instantiate a new style each time. A program
  68. * will generally use one of the predefined constants on this class.
  69. * Alternatively, the {@link StandardToStringStyle} class can be used
  70. * to set the individual settings. Thus most styles can be achieved
  71. * without subclassing.</p>
  72. *
  73. * <p>If required, a subclass can override as many or as few of the
  74. * methods as it requires. Each object type (from <code>boolean</code>
  75. * to <code>long</code> to <code>Object</code> to <code>int[]</code>) has
  76. * its own methods to output it. Most have two versions, detail and summary.
  77. *
  78. * <p>For example, the detail version of the array based methods will
  79. * output the whole array, whereas the summary method will just output
  80. * the array length.</p>
  81. *
  82. * @author Stephen Colebourne
  83. * @author Gary Gregory
  84. * @author Pete Gieser
  85. * @since 1.0
  86. * @version $Id: ToStringStyle.java,v 1.27 2003/08/23 00:21:49 ggregory Exp $
  87. */
  88. public abstract class ToStringStyle implements Serializable {
  89. /**
  90. * The default toString style.
  91. */
  92. public static final ToStringStyle DEFAULT_STYLE = new DefaultToStringStyle();
  93. /**
  94. * The multi line toString style.
  95. */
  96. public static final ToStringStyle MULTI_LINE_STYLE = new MultiLineToStringStyle();
  97. /**
  98. * The no field names toString style.
  99. */
  100. public static final ToStringStyle NO_FIELD_NAMES_STYLE = new NoFieldNameToStringStyle();
  101. /**
  102. * The simple toString style.
  103. */
  104. public static final ToStringStyle SIMPLE_STYLE = new SimpleToStringStyle();
  105. /**
  106. * Whether to use the field names, the default is <code>true</code>.
  107. */
  108. private boolean useFieldNames = true;
  109. /**
  110. * Whether to use the class name, the default is <code>true</code>.
  111. */
  112. private boolean useClassName = true;
  113. /**
  114. * Whether to use short class names, the default is <code>false</code>.
  115. */
  116. private boolean useShortClassName = false;
  117. /**
  118. * Whether to use the identity hash code, the default is <code>true</code>.
  119. */
  120. private boolean useIdentityHashCode = true;
  121. /**
  122. * The content start <code>'['</code>.
  123. */
  124. private String contentStart = "[";
  125. /**
  126. * The content end <code>']'</code>.
  127. */
  128. private String contentEnd = "]";
  129. /**
  130. * The field name value separator <code>'='</code>.
  131. */
  132. private String fieldNameValueSeparator = "=";
  133. /**
  134. * Whether the field separator should be added before any other fields.
  135. */
  136. private boolean fieldSeparatorAtStart = false;
  137. /**
  138. * Whether the field separator should be added after any other fields.
  139. */
  140. private boolean fieldSeparatorAtEnd = false;
  141. /**
  142. * The field separator <code>','</code>.
  143. */
  144. private String fieldSeparator = ",";
  145. /**
  146. * The array start <code>'{'</code>.
  147. */
  148. private String arrayStart = "{";
  149. /**
  150. * The array separator <code>','</code>.
  151. */
  152. private String arraySeparator = ",";
  153. /**
  154. * The detail for array content.
  155. */
  156. private boolean arrayContentDetail = true;
  157. /**
  158. * The array end <code>'}'</code>.
  159. */
  160. private String arrayEnd = "}";
  161. /**
  162. * The value to use when fullDetail is <code>null</code>,
  163. * the default value is <code>true</code>.
  164. */
  165. private boolean defaultFullDetail = true;
  166. /**
  167. * The <code>null</code> text <code>'<null>'</code>.
  168. */
  169. private String nullText = "<null>";
  170. /**
  171. * The summary size text start <code>'<size'</code>.
  172. */
  173. private String sizeStartText = "<size=";
  174. /**
  175. * The summary size text start <code>'>'</code>.
  176. */
  177. private String sizeEndText = ">";
  178. /**
  179. * The summary object text start <code>'<'</code>.
  180. */
  181. private String summaryObjectStartText = "<";
  182. /**
  183. * The summary object text start <code>'>'</code>.
  184. */
  185. private String summaryObjectEndText = ">";
  186. //----------------------------------------------------------------------------
  187. /**
  188. * <p>Constructor.</p>
  189. */
  190. protected ToStringStyle() {
  191. super();
  192. }
  193. //----------------------------------------------------------------------------
  194. /**
  195. * <p>Append to the <code>toString</code> the superclass toString.</p>
  196. *
  197. * <p>A <code>null</code> <code>superToString</code> is ignored.</p>
  198. *
  199. * @param buffer the <code>StringBuffer</code> to populate
  200. * @param superToString the <code>super.toString()</code>
  201. * @since 2.0
  202. */
  203. public void appendSuper(StringBuffer buffer, String superToString) {
  204. appendToString(buffer, superToString);
  205. }
  206. /**
  207. * <p>Append to the <code>toString</code> another toString.</p>
  208. *
  209. * <p>A <code>null</code> <code>toString</code> is ignored.</p>
  210. *
  211. * @param buffer the <code>StringBuffer</code> to populate
  212. * @param toString the additional <code>toString</code>
  213. * @since 2.0
  214. */
  215. public void appendToString(StringBuffer buffer, String toString) {
  216. if (toString != null) {
  217. int pos1 = toString.indexOf(contentStart) + contentStart.length();
  218. int pos2 = toString.lastIndexOf(contentEnd);
  219. if (pos1 != pos2 && pos1 >= 0 && pos2 >= 0) {
  220. String data = toString.substring(pos1, pos2);
  221. if (fieldSeparatorAtStart) {
  222. removeLastFieldSeparator(buffer);
  223. }
  224. buffer.append(data);
  225. appendFieldSeparator(buffer);
  226. }
  227. }
  228. }
  229. /**
  230. * <p>Append to the <code>toString</code> the start of data indicator.</p>
  231. *
  232. * @param buffer the <code>StringBuffer</code> to populate
  233. * @param object the <code>Object</code> to build a
  234. * <code>toString</code> for, must not be <code>null</code>
  235. */
  236. public void appendStart(StringBuffer buffer, Object object) {
  237. appendClassName(buffer, object);
  238. appendIdentityHashCode(buffer, object);
  239. appendContentStart(buffer);
  240. if (fieldSeparatorAtStart) {
  241. appendFieldSeparator(buffer);
  242. }
  243. }
  244. /**
  245. * <p>Append to the <code>toString</code> the end of data indicator.</p>
  246. *
  247. * @param buffer the <code>StringBuffer</code> to populate
  248. * @param object the <code>Object</code> to build a
  249. * <code>toString</code> for, must not be <code>null</code>
  250. */
  251. public void appendEnd(StringBuffer buffer, Object object) {
  252. if (fieldSeparatorAtEnd == false) {
  253. removeLastFieldSeparator(buffer);
  254. }
  255. appendContentEnd(buffer);
  256. }
  257. /**
  258. * <p>Remove the last field separator from the buffer.</p>
  259. *
  260. * @param buffer the <code>StringBuffer</code> to populate
  261. * @since 2.0
  262. */
  263. protected void removeLastFieldSeparator(StringBuffer buffer) {
  264. int len = buffer.length();
  265. int sepLen = fieldSeparator.length();
  266. if (len > 0 && sepLen > 0 && len >= sepLen) {
  267. boolean match = true;
  268. for (int i = 0; i < sepLen; i++) {
  269. if (buffer.charAt(len - 1 - i) != fieldSeparator.charAt(sepLen - 1 - i)) {
  270. match = false;
  271. break;
  272. }
  273. }
  274. if (match) {
  275. buffer.setLength(len - sepLen);
  276. }
  277. }
  278. }
  279. //----------------------------------------------------------------------------
  280. /**
  281. * <p>Append to the <code>toString</code> an <code>Object</code>
  282. * value, printing the full <code>toString</code> of the
  283. * <code>Object</code> passed in.</p>
  284. *
  285. * @param buffer the <code>StringBuffer</code> to populate
  286. * @param fieldName the field name
  287. * @param value the value to add to the <code>toString</code>
  288. * @param fullDetail <code>true</code> for detail, <code>false</code>
  289. * for summary info, <code>null</code> for style decides
  290. */
  291. public void append(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail) {
  292. appendFieldStart(buffer, fieldName);
  293. if (value == null) {
  294. appendNullText(buffer, fieldName);
  295. } else {
  296. appendInternal(buffer, fieldName, value, isFullDetail(fullDetail));
  297. }
  298. appendFieldEnd(buffer, fieldName);
  299. }
  300. /**
  301. * <p>Append to the <code>toString</code> an <code>Object</code>,
  302. * correctly interpreting its type.</p>
  303. *
  304. * <p>This method performs the main lookup by Class type to correctly
  305. * route arrays, <code>Collections</code>, <code>Maps</code> and
  306. * <code>Objects</code> to the appropriate method.</p>
  307. *
  308. * <p>Either detail or summary views can be specified.</p>
  309. *
  310. * <p>If a cycle is detected, an object will be appended with the
  311. * <code>Object.toString()</code> format.</p>
  312. *
  313. * @param buffer the <code>StringBuffer</code> to populate
  314. * @param fieldName the field name, typically not used as already appended
  315. * @param value the value to add to the <code>toString</code>,
  316. * not <code>null</code>
  317. * @param detail output detail or not
  318. */
  319. protected void appendInternal(StringBuffer buffer, String fieldName, Object value, boolean detail) {
  320. if (ReflectionToStringBuilder.isRegistered(value)
  321. && !(value instanceof Number || value instanceof Boolean || value instanceof Character)) {
  322. ObjectUtils.appendIdentityToString(buffer, value);
  323. } else if (value instanceof Collection) {
  324. if (detail) {
  325. appendDetail(buffer, fieldName, (Collection) value);
  326. } else {
  327. appendSummarySize(buffer, fieldName, ((Collection) value).size());
  328. }
  329. } else if (value instanceof Map) {
  330. if (detail) {
  331. appendDetail(buffer, fieldName, (Map) value);
  332. } else {
  333. appendSummarySize(buffer, fieldName, ((Map) value).size());
  334. }
  335. } else if (value instanceof long[]) {
  336. if (detail) {
  337. appendDetail(buffer, fieldName, (long[]) value);
  338. } else {
  339. appendSummary(buffer, fieldName, (long[]) value);
  340. }
  341. } else if (value instanceof int[]) {
  342. if (detail) {
  343. appendDetail(buffer, fieldName, (int[]) value);
  344. } else {
  345. appendSummary(buffer, fieldName, (int[]) value);
  346. }
  347. } else if (value instanceof short[]) {
  348. if (detail) {
  349. appendDetail(buffer, fieldName, (short[]) value);
  350. } else {
  351. appendSummary(buffer, fieldName, (short[]) value);
  352. }
  353. } else if (value instanceof byte[]) {
  354. if (detail) {
  355. appendDetail(buffer, fieldName, (byte[]) value);
  356. } else {
  357. appendSummary(buffer, fieldName, (byte[]) value);
  358. }
  359. } else if (value instanceof char[]) {
  360. if (detail) {
  361. appendDetail(buffer, fieldName, (char[]) value);
  362. } else {
  363. appendSummary(buffer, fieldName, (char[]) value);
  364. }
  365. } else if (value instanceof double[]) {
  366. if (detail) {
  367. appendDetail(buffer, fieldName, (double[]) value);
  368. } else {
  369. appendSummary(buffer, fieldName, (double[]) value);
  370. }
  371. } else if (value instanceof float[]) {
  372. if (detail) {
  373. appendDetail(buffer, fieldName, (float[]) value);
  374. } else {
  375. appendSummary(buffer, fieldName, (float[]) value);
  376. }
  377. } else if (value instanceof boolean[]) {
  378. if (detail) {
  379. appendDetail(buffer, fieldName, (boolean[]) value);
  380. } else {
  381. appendSummary(buffer, fieldName, (boolean[]) value);
  382. }
  383. } else if (value.getClass().isArray()) {
  384. if (detail) {
  385. appendDetail(buffer, fieldName, (Object[]) value);
  386. } else {
  387. appendSummary(buffer, fieldName, (Object[]) value);
  388. }
  389. } else {
  390. if (detail) {
  391. appendDetail(buffer, fieldName, value);
  392. } else {
  393. appendSummary(buffer, fieldName, value);
  394. }
  395. }
  396. }
  397. /**
  398. * <p>Append to the <code>toString</code> an <code>Object</code>
  399. * value, printing the full detail of the <code>Object</code>.</p>
  400. *
  401. * @param buffer the <code>StringBuffer</code> to populate
  402. * @param fieldName the field name, typically not used as already appended
  403. * @param value the value to add to the <code>toString</code>,
  404. * not <code>null</code>
  405. */
  406. protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
  407. buffer.append(value);
  408. }
  409. /**
  410. * <p>Append to the <code>toString</code> a <code>Collection</code>.</p>
  411. *
  412. * @param buffer the <code>StringBuffer</code> to populate
  413. * @param fieldName the field name, typically not used as already appended
  414. * @param coll the <code>Collection</code> to add to the
  415. * <code>toString</code>, not <code>null</code>
  416. */
  417. protected void appendDetail(StringBuffer buffer, String fieldName, Collection coll) {
  418. buffer.append(coll);
  419. }
  420. /**
  421. * <p>Append to the <code>toString</code> a <code>Map<code>.</p>
  422. *
  423. * @param buffer the <code>StringBuffer</code> to populate
  424. * @param fieldName the field name, typically not used as already appended
  425. * @param map the <code>Map</code> to add to the <code>toString</code>,
  426. * not <code>null</code>
  427. */
  428. protected void appendDetail(StringBuffer buffer, String fieldName, Map map) {
  429. buffer.append(map);
  430. }
  431. /**
  432. * <p>Append to the <code>toString</code> an <code>Object</code>
  433. * value, printing a summary of the <code>Object</code>.</P>
  434. *
  435. * @param buffer the <code>StringBuffer</code> to populate
  436. * @param fieldName the field name, typically not used as already appended
  437. * @param value the value to add to the <code>toString</code>,
  438. * not <code>null</code>
  439. */
  440. protected void appendSummary(StringBuffer buffer, String fieldName, Object value) {
  441. buffer.append(summaryObjectStartText);
  442. buffer.append(getShortClassName(value.getClass()));
  443. buffer.append(summaryObjectEndText);
  444. }
  445. //----------------------------------------------------------------------------
  446. /**
  447. * <p>Append to the <code>toString</code> a <code>long</code>
  448. * value.</p>
  449. *
  450. * @param buffer the <code>StringBuffer</code> to populate
  451. * @param fieldName the field name
  452. * @param value the value to add to the <code>toString</code>
  453. */
  454. public void append(StringBuffer buffer, String fieldName, long value) {
  455. appendFieldStart(buffer, fieldName);
  456. appendDetail(buffer, fieldName, value);
  457. appendFieldEnd(buffer, fieldName);
  458. }
  459. /**
  460. * <p>Append to the <code>toString</code> a <code>long</code>
  461. * value.</p>
  462. *
  463. * @param buffer the <code>StringBuffer</code> to populate
  464. * @param fieldName the field name, typically not used as already appended
  465. * @param value the value to add to the <code>toString</code>
  466. */
  467. protected void appendDetail(StringBuffer buffer, String fieldName, long value) {
  468. buffer.append(value);
  469. }
  470. //----------------------------------------------------------------------------
  471. /**
  472. * <p>Append to the <code>toString</code> an <code>int</code>
  473. * value.</p>
  474. *
  475. * @param buffer the <code>StringBuffer</code> to populate
  476. * @param fieldName the field name
  477. * @param value the value to add to the <code>toString</code>
  478. */
  479. public void append(StringBuffer buffer, String fieldName, int value) {
  480. appendFieldStart(buffer, fieldName);
  481. appendDetail(buffer, fieldName, value);
  482. appendFieldEnd(buffer, fieldName);
  483. }
  484. /**
  485. * <p>Append to the <code>toString</code> an <code>int</code>
  486. * value.</p>
  487. *
  488. * @param buffer the <code>StringBuffer</code> to populate
  489. * @param fieldName the field name, typically not used as already appended
  490. * @param value the value to add to the <code>toString</code>
  491. */
  492. protected void appendDetail(StringBuffer buffer, String fieldName, int value) {
  493. buffer.append(value);
  494. }
  495. //----------------------------------------------------------------------------
  496. /**
  497. * <p>Append to the <code>toString</code> a <code>short</code>
  498. * value.</p>
  499. *
  500. * @param buffer the <code>StringBuffer</code> to populate
  501. * @param fieldName the field name
  502. * @param value the value to add to the <code>toString</code>
  503. */
  504. public void append(StringBuffer buffer, String fieldName, short value) {
  505. appendFieldStart(buffer, fieldName);
  506. appendDetail(buffer, fieldName, value);
  507. appendFieldEnd(buffer, fieldName);
  508. }
  509. /**
  510. * <p>Append to the <code>toString</code> a <code>short</code>
  511. * value.</p>
  512. *
  513. * @param buffer the <code>StringBuffer</code> to populate
  514. * @param fieldName the field name, typically not used as already appended
  515. * @param value the value to add to the <code>toString</code>
  516. */
  517. protected void appendDetail(StringBuffer buffer, String fieldName, short value) {
  518. buffer.append(value);
  519. }
  520. //----------------------------------------------------------------------------
  521. /**
  522. * <p>Append to the <code>toString</code> a <code>byte</code>
  523. * value.</p>
  524. *
  525. * @param buffer the <code>StringBuffer</code> to populate
  526. * @param fieldName the field name
  527. * @param value the value to add to the <code>toString</code>
  528. */
  529. public void append(StringBuffer buffer, String fieldName, byte value) {
  530. appendFieldStart(buffer, fieldName);
  531. appendDetail(buffer, fieldName, value);
  532. appendFieldEnd(buffer, fieldName);
  533. }
  534. /**
  535. * <p>Append to the <code>toString</code> a <code>byte</code>
  536. * value.</p>
  537. *
  538. * @param buffer the <code>StringBuffer</code> to populate
  539. * @param fieldName the field name, typically not used as already appended
  540. * @param value the value to add to the <code>toString</code>
  541. */
  542. protected void appendDetail(StringBuffer buffer, String fieldName, byte value) {
  543. buffer.append(value);
  544. }
  545. //----------------------------------------------------------------------------
  546. /**
  547. * <p>Append to the <code>toString</code> a <code>char</code>
  548. * value.</p>
  549. *
  550. * @param buffer the <code>StringBuffer</code> to populate
  551. * @param fieldName the field name
  552. * @param value the value to add to the <code>toString</code>
  553. */
  554. public void append(StringBuffer buffer, String fieldName, char value) {
  555. appendFieldStart(buffer, fieldName);
  556. appendDetail(buffer, fieldName, value);
  557. appendFieldEnd(buffer, fieldName);
  558. }
  559. /**
  560. * <p>Append to the <code>toString</code> a <code>char</code>
  561. * value.</p>
  562. *
  563. * @param buffer the <code>StringBuffer</code> to populate
  564. * @param fieldName the field name, typically not used as already appended
  565. * @param value the value to add to the <code>toString</code>
  566. */
  567. protected void appendDetail(StringBuffer buffer, String fieldName, char value) {
  568. buffer.append(value);
  569. }
  570. //----------------------------------------------------------------------------
  571. /**
  572. * <p>Append to the <code>toString</code> a <code>double</code>
  573. * value.</p>
  574. *
  575. * @param buffer the <code>StringBuffer</code> to populate
  576. * @param fieldName the field name
  577. * @param value the value to add to the <code>toString</code>
  578. */
  579. public void append(StringBuffer buffer, String fieldName, double value) {
  580. appendFieldStart(buffer, fieldName);
  581. appendDetail(buffer, fieldName, value);
  582. appendFieldEnd(buffer, fieldName);
  583. }
  584. /**
  585. * <p>Append to the <code>toString</code> a <code>double</code>
  586. * value.</p>
  587. *
  588. * @param buffer the <code>StringBuffer</code> to populate
  589. * @param fieldName the field name, typically not used as already appended
  590. * @param value the value to add to the <code>toString</code>
  591. */
  592. protected void appendDetail(StringBuffer buffer, String fieldName, double value) {
  593. buffer.append(value);
  594. }
  595. //----------------------------------------------------------------------------
  596. /**
  597. * <p>Append to the <code>toString</code> a <code>float</code>
  598. * value.</p>
  599. *
  600. * @param buffer the <code>StringBuffer</code> to populate
  601. * @param fieldName the field name
  602. * @param value the value to add to the <code>toString</code>
  603. */
  604. public void append(StringBuffer buffer, String fieldName, float value) {
  605. appendFieldStart(buffer, fieldName);
  606. appendDetail(buffer, fieldName, value);
  607. appendFieldEnd(buffer, fieldName);
  608. }
  609. /**
  610. * <p>Append to the <code>toString</code> a <code>float</code>
  611. * value.</p>
  612. *
  613. * @param buffer the <code>StringBuffer</code> to populate
  614. * @param fieldName the field name, typically not used as already appended
  615. * @param value the value to add to the <code>toString</code>
  616. */
  617. protected void appendDetail(StringBuffer buffer, String fieldName, float value) {
  618. buffer.append(value);
  619. }
  620. //----------------------------------------------------------------------------
  621. /**
  622. * <p>Append to the <code>toString</code> a <code>boolean</code>
  623. * value.</p>
  624. *
  625. * @param buffer the <code>StringBuffer</code> to populate
  626. * @param fieldName the field name
  627. * @param value the value to add to the <code>toString</code>
  628. */
  629. public void append(StringBuffer buffer, String fieldName, boolean value) {
  630. appendFieldStart(buffer, fieldName);
  631. appendDetail(buffer, fieldName, value);
  632. appendFieldEnd(buffer, fieldName);
  633. }
  634. /**
  635. * <p>Append to the <code>toString</code> a <code>boolean</code>
  636. * value.</p>
  637. *
  638. * @param buffer the <code>StringBuffer</code> to populate
  639. * @param fieldName the field name, typically not used as already appended
  640. * @param value the value to add to the <code>toString</code>
  641. */
  642. protected void appendDetail(StringBuffer buffer, String fieldName, boolean value) {
  643. buffer.append(value);
  644. }
  645. /**
  646. * <p>Append to the <code>toString</code> an <code>Object</code>
  647. * array.</p>
  648. *
  649. * @param buffer the <code>StringBuffer</code> to populate
  650. * @param fieldName the field name
  651. * @param array the array to add to the toString
  652. * @param fullDetail <code>true</code> for detail, <code>false</code>
  653. * for summary info, <code>null</code> for style decides
  654. */
  655. public void append(StringBuffer buffer, String fieldName, Object[] array, Boolean fullDetail) {
  656. appendFieldStart(buffer, fieldName);
  657. if (array == null) {
  658. appendNullText(buffer, fieldName);
  659. } else if (isFullDetail(fullDetail)) {
  660. appendDetail(buffer, fieldName, array);
  661. } else {
  662. appendSummary(buffer, fieldName, array);
  663. }
  664. appendFieldEnd(buffer, fieldName);
  665. }
  666. //----------------------------------------------------------------------------
  667. /**
  668. * <p>Append to the <code>toString</code> the detail of an
  669. * <code>Object</code> array.</p>
  670. *
  671. * @param buffer the <code>StringBuffer</code> to populate
  672. * @param fieldName the field name, typically not used as already appended
  673. * @param array the array to add to the <code>toString</code>,
  674. * not <code>null</code>
  675. */
  676. protected void appendDetail(StringBuffer buffer, String fieldName, Object[] array) {
  677. buffer.append(arrayStart);
  678. for (int i = 0; i < array.length; i++) {
  679. Object item = array[i];
  680. if (i > 0) {
  681. buffer.append(arraySeparator);
  682. }
  683. if (item == null) {
  684. appendNullText(buffer, fieldName);
  685. } else {
  686. appendInternal(buffer, fieldName, item, arrayContentDetail);
  687. }
  688. }
  689. buffer.append(arrayEnd);
  690. }
  691. /**
  692. * <p>Append to the <code>toString</code> the detail of an array type.</p>
  693. *
  694. * @param buffer the <code>StringBuffer</code> to populate
  695. * @param fieldName the field name, typically not used as already appended
  696. * @param array the array to add to the <code>toString</code>,
  697. * not <code>null</code>
  698. * @since 2.0
  699. */
  700. protected void reflectionAppendArrayDetail(StringBuffer buffer, String fieldName, Object array) {
  701. buffer.append(arrayStart);
  702. int length = Array.getLength(array);
  703. for (int i = 0; i < length; i++) {
  704. Object item = Array.get(array, i);
  705. if (i > 0) {
  706. buffer.append(arraySeparator);
  707. }
  708. if (item == null) {
  709. appendNullText(buffer, fieldName);
  710. } else {
  711. appendInternal(buffer, fieldName, item, arrayContentDetail);
  712. }
  713. }
  714. buffer.append(arrayEnd);
  715. }
  716. /**
  717. * <p>Append to the <code>toString</code> a summary of an
  718. * <code>Object</code> array.</p>
  719. *
  720. * @param buffer the <code>StringBuffer</code> to populate
  721. * @param fieldName the field name, typically not used as already appended
  722. * @param array the array to add to the <code>toString</code>,
  723. * not <code>null</code>
  724. */
  725. protected void appendSummary(StringBuffer buffer, String fieldName, Object[] array) {
  726. appendSummarySize(buffer, fieldName, array.length);
  727. }
  728. //----------------------------------------------------------------------------
  729. /**
  730. * <p>Append to the <code>toString</code> a <code>long</code>
  731. * array.</p>
  732. *
  733. * @param buffer the <code>StringBuffer</code> to populate
  734. * @param fieldName the field name
  735. * @param array the array to add to the <code>toString</code>
  736. * @param fullDetail <code>true</code> for detail, <code>false</code>
  737. * for summary info, <code>null</code> for style decides
  738. */
  739. public void append(StringBuffer buffer, String fieldName, long[] array, Boolean fullDetail) {
  740. appendFieldStart(buffer, fieldName);
  741. if (array == null) {
  742. appendNullText(buffer, fieldName);
  743. } else if (isFullDetail(fullDetail)) {
  744. appendDetail(buffer, fieldName, array);
  745. } else {
  746. appendSummary(buffer, fieldName, array);
  747. }
  748. appendFieldEnd(buffer, fieldName);
  749. }
  750. /**
  751. * <p>Append to the <code>toString</code> the detail of a
  752. * <code>long</code> array.</p>
  753. *
  754. * @param buffer the <code>StringBuffer</code> to populate
  755. * @param fieldName the field name, typically not used as already appended
  756. * @param array the array to add to the <code>toString</code>,
  757. * not <code>null</code>
  758. */
  759. protected void appendDetail(StringBuffer buffer, String fieldName, long[] array) {
  760. buffer.append(arrayStart);
  761. for (int i = 0; i < array.length; i++) {
  762. if (i > 0) {
  763. buffer.append(arraySeparator);
  764. }
  765. appendDetail(buffer, fieldName, array[i]);
  766. }
  767. buffer.append(arrayEnd);
  768. }
  769. /**
  770. * <p>Append to the <code>toString</code> a summary of a
  771. * <code>long</code> array.</p>
  772. *
  773. * @param buffer the <code>StringBuffer</code> to populate
  774. * @param fieldName the field name, typically not used as already appended
  775. * @param array the array to add to the <code>toString</code>,
  776. * not <code>null</code>
  777. */
  778. protected void appendSummary(StringBuffer buffer, String fieldName, long[] array) {
  779. appendSummarySize(buffer, fieldName, array.length);
  780. }
  781. //----------------------------------------------------------------------------
  782. /**
  783. * <p>Append to the <code>toString</code> an <code>int</code>
  784. * array.</p>
  785. *
  786. * @param buffer the <code>StringBuffer</code> to populate
  787. * @param fieldName the field name
  788. * @param array the array to add to the <code>toString</code>
  789. * @param fullDetail <code>true</code> for detail, <code>false</code>
  790. * for summary info, <code>null</code> for style decides
  791. */
  792. public void append(StringBuffer buffer, String fieldName, int[] array, Boolean fullDetail) {
  793. appendFieldStart(buffer, fieldName);
  794. if (array == null) {
  795. appendNullText(buffer, fieldName);
  796. } else if (isFullDetail(fullDetail)) {
  797. appendDetail(buffer, fieldName, array);
  798. } else {
  799. appendSummary(buffer, fieldName, array);
  800. }
  801. appendFieldEnd(buffer, fieldName);
  802. }
  803. /**
  804. * <p>Append to the <code>toString</code> the detail of an
  805. * <code>int</code> array.</p>
  806. *
  807. * @param buffer the <code>StringBuffer</code> to populate
  808. * @param fieldName the field name, typically not used as already appended
  809. * @param array the array to add to the <code>toString</code>,
  810. * not <code>null</code>
  811. */
  812. protected void appendDetail(StringBuffer buffer, String fieldName, int[] array) {
  813. buffer.append(arrayStart);
  814. for (int i = 0; i < array.length; i++) {
  815. if (i > 0) {
  816. buffer.append(arraySeparator);
  817. }
  818. appendDetail(buffer, fieldName, array[i]);
  819. }
  820. buffer.append(arrayEnd);
  821. }
  822. /**
  823. * <p>Append to the <code>toString</code> a summary of an
  824. * <code>int</code> array.</p>
  825. *
  826. * @param buffer the <code>StringBuffer</code> to populate
  827. * @param fieldName the field name, typically not used as already appended
  828. * @param array the array to add to the <code>toString</code>,
  829. * not <code>null</code>
  830. */
  831. protected void appendSummary(StringBuffer buffer, String fieldName, int[] array) {
  832. appendSummarySize(buffer, fieldName, array.length);
  833. }
  834. //----------------------------------------------------------------------------
  835. /**
  836. * <p>Append to the <code>toString</code> a <code>short</code>
  837. * array.</p>
  838. *
  839. * @param buffer the <code>StringBuffer</code> to populate
  840. * @param fieldName the field name
  841. * @param array the array to add to the <code>toString</code>
  842. * @param fullDetail <code>true</code> for detail, <code>false</code>
  843. * for summary info, <code>null</code> for style decides
  844. */
  845. public void append(StringBuffer buffer, String fieldName, short[] array, Boolean fullDetail) {
  846. appendFieldStart(buffer, fieldName);
  847. if (array == null) {
  848. appendNullText(buffer, fieldName);
  849. } else if (isFullDetail(fullDetail)) {
  850. appendDetail(buffer, fieldName, array);
  851. } else {
  852. appendSummary(buffer, fieldName, array);
  853. }
  854. appendFieldEnd(buffer, fieldName);
  855. }
  856. /**
  857. * <p>Append to the <code>toString</code> the detail of a
  858. * <code>short</code> array.</p>
  859. *
  860. * @param buffer the <code>StringBuffer</code> to populate
  861. * @param fieldName the field name, typically not used as already appended
  862. * @param array the array to add to the <code>toString</code>,
  863. * not <code>null</code>
  864. */
  865. protected void appendDetail(StringBuffer buffer, String fieldName, short[] array) {
  866. buffer.append(arrayStart);
  867. for (int i = 0; i < array.length; i++) {
  868. if (i > 0) {
  869. buffer.append(arraySeparator);
  870. }
  871. appendDetail(buffer, fieldName, array[i]);
  872. }
  873. buffer.append(arrayEnd);
  874. }
  875. /**
  876. * <p>Append to the <code>toString</code> a summary of a
  877. * <code>short</code> array.</p>
  878. *
  879. * @param buffer the <code>StringBuffer</code> to populate
  880. * @param fieldName the field name, typically not used as already appended
  881. * @param array the array to add to the <code>toString</code>,
  882. * not <code>null</code>
  883. */
  884. protected void appendSummary(StringBuffer buffer, String fieldName, short[] array) {
  885. appendSummarySize(buffer, fieldName, array.length);
  886. }
  887. //----------------------------------------------------------------------------
  888. /**
  889. * <p>Append to the <code>toString</code> a <code>byte</code>
  890. * array.</p>
  891. *
  892. * @param buffer the <code>StringBuffer</code> to populate
  893. * @param fieldName the field name
  894. * @param array the array to add to the <code>toString</code>
  895. * @param fullDetail <code>true</code> for detail, <code>false</code>
  896. * for summary info, <code>null</code> for style decides
  897. */
  898. public void append(StringBuffer buffer, String fieldName, byte[] array, Boolean fullDetail) {
  899. appendFieldStart(buffer, fieldName);
  900. if (array == null) {
  901. appendNullText(buffer, fieldName);
  902. } else if (isFullDetail(fullDetail)) {
  903. appendDetail(buffer, fieldName, array);
  904. } else {
  905. appendSummary(buffer, fieldName, array);
  906. }
  907. appendFieldEnd(buffer, fieldName);
  908. }
  909. /**
  910. * <p>Append to the <code>toString</code> the detail of a
  911. * <code>byte</code> array.</p>
  912. *
  913. * @param buffer the <code>StringBuffer</code> to populate
  914. * @param fieldName the field name, typically not used as already appended
  915. * @param array the array to add to the <code>toString</code>,
  916. * not <code>null</code>
  917. */
  918. protected void appendDetail(StringBuffer buffer, String fieldName, byte[] array) {
  919. buffer.append(arrayStart);
  920. for (int i = 0; i < array.length; i++) {
  921. if (i > 0) {
  922. buffer.append(arraySeparator);
  923. }
  924. appendDetail(buffer, fieldName, array[i]);
  925. }
  926. buffer.append(arrayEnd);
  927. }
  928. /**
  929. * <p>Append to the <code>toString</code> a summary of a
  930. * <code>byte</code> array.</p>
  931. *
  932. * @param buffer the <code>StringBuffer</code> to populate
  933. * @param fieldName the field name, typically not used as already appended
  934. * @param array the array to add to the <code>toString</code>,
  935. * not <code>null</code>
  936. */
  937. protected void appendSummary(StringBuffer buffer, String fieldName, byte[] array) {
  938. appendSummarySize(buffer, fieldName, array.length);
  939. }
  940. //----------------------------------------------------------------------------
  941. /**
  942. * <p>Append to the <code>toString</code> a <code>char</code>
  943. * array.</p>
  944. *
  945. * @param buffer the <code>StringBuffer</code> to populate
  946. * @param fieldName the field name
  947. * @param array the array to add to the <code>toString</code>
  948. * @param fullDetail <code>true</code> for detail, <code>false</code>
  949. * for summary info, <code>null</code> for style decides
  950. */
  951. public void append(StringBuffer buffer, String fieldName, char[] array, Boolean fullDetail) {
  952. appendFieldStart(buffer, fieldName);
  953. if (array == null) {
  954. appendNullText(buffer, fieldName);
  955. } else if (isFullDetail(fullDetail)) {
  956. appendDetail(buffer, fieldName, array);
  957. } else {
  958. appendSummary(buffer, fieldName, array);
  959. }
  960. appendFieldEnd(buffer, fieldName);
  961. }
  962. /**
  963. * <p>Append to the <code>toString</code> the detail of a
  964. * <code>char</code> array.</p>
  965. *
  966. * @param buffer the <code>StringBuffer</code> to populate
  967. * @param fieldName the field name, typically not used as already appended
  968. * @param array the array to add to the <code>toString</code>,
  969. * not <code>null</code>
  970. */
  971. protected void appendDetail(StringBuffer buffer, String fieldName, char[] array) {
  972. buffer.append(arrayStart);
  973. for (int i = 0; i < array.length; i++) {
  974. if (i > 0) {
  975. buffer.append(arraySeparator);
  976. }
  977. appendDetail(buffer, fieldName, array[i]);
  978. }
  979. buffer.append(arrayEnd);
  980. }
  981. /**
  982. * <p>Append to the <code>toString</code> a summary of a
  983. * <code>char</code> array.</p>
  984. *
  985. * @param buffer the <code>StringBuffer</code> to populate
  986. * @param fieldName the field name, typically not used as already appended
  987. * @param array the array to add to the <code>toString</code>,
  988. * not <code>null</code>
  989. */
  990. protected void appendSummary(StringBuffer buffer, String fieldName, char[] array) {
  991. appendSummarySize(buffer, fieldName, array.length);
  992. }
  993. //----------------------------------------------------------------------------
  994. /**
  995. * <p>Append to the <code>toString</code> a <code>double</code>
  996. * array.</p>
  997. *
  998. * @param buffer the <code>StringBuffer</code> to populate
  999. * @param fieldName the field name
  1000. * @param array the array to add to the toString
  1001. * @param fullDetail <code>true</code> for detail, <code>false</code>
  1002. * for summary info, <code>null</code> for style decides
  1003. */
  1004. public void append(StringBuffer buffer, String fieldName, double[] array, Boolean fullDetail) {
  1005. appendFieldStart(buffer, fieldName);
  1006. if (array == null) {
  1007. appendNullText(buffer, fieldName);
  1008. } else if (isFullDetail(fullDetail)) {
  1009. appendDetail(buffer, fieldName, array);
  1010. } else {
  1011. appendSummary(buffer, fieldName, array);
  1012. }
  1013. appendFieldEnd(buffer, fieldName);
  1014. }
  1015. /**
  1016. * <p>Append to the <code>toString</code> the detail of a
  1017. * <code>double</code> array.</p>
  1018. *
  1019. * @param buffer the <code>StringBuffer</code> to populate
  1020. * @param fieldName the field name, typically not used as already appended
  1021. * @param array the array to add to the <code>toString</code>,
  1022. * not <code>null</code>
  1023. */
  1024. protected void appendDetail(StringBuffer buffer, String fieldName, double[] array) {
  1025. buffer.append(arrayStart);
  1026. for (int i = 0; i < array.length; i++) {
  1027. if (i > 0) {
  1028. buffer.append(arraySeparator);
  1029. }
  1030. appendDetail(buffer, fieldName, array[i]);
  1031. }
  1032. buffer.append(arrayEnd);
  1033. }
  1034. /**
  1035. * <p>Append to the <code>toString</code> a summary of a
  1036. * <code>double</code> array.</p>
  1037. *
  1038. * @param buffer the <code>StringBuffer</code> to populate
  1039. * @param fieldName the field name, typically not used as already appended
  1040. * @param array the array to add to the <code>toString</code>,
  1041. * not <code>null</code>
  1042. */
  1043. protected void appendSummary(StringBuffer buffer, String fieldName, double[] array) {
  1044. appendSummarySize(buffer, fieldName, array.length);
  1045. }
  1046. //----------------------------------------------------------------------------
  1047. /**
  1048. * <p>Append to the <code>toString</code> a <code>float</code>
  1049. * array.</p>
  1050. *
  1051. * @param buffer the <code>StringBuffer</code> to populate
  1052. * @param fieldName the field name
  1053. * @param array the array to add to the toString
  1054. * @param fullDetail <code>true</code> for detail, <code>false</code>
  1055. * for summary info, <code>null</code> for style decides
  1056. */
  1057. public void append(StringBuffer buffer, String fieldName, float[] array, Boolean fullDetail) {
  1058. appendFieldStart(buffer, fieldName);
  1059. if (array == null) {
  1060. appendNullText(buffer, fieldName);
  1061. } else if (isFullDetail(fullDetail)) {
  1062. appendDetail(buffer, fieldName, array);
  1063. } else {
  1064. appendSummary(buffer, fieldName, array);
  1065. }
  1066. appendFieldEnd(buffer, fieldName);
  1067. }
  1068. /**
  1069. * <p>Append to the <code>toString</code> the detail of a
  1070. * <code>float</code> array.</p>
  1071. *
  1072. * @param buffer the <code>StringBuffer</code> to populate
  1073. * @param fieldName the field name, typically not used as already appended
  1074. * @param array the array to add to the <code>toString</code>,
  1075. * not <code>null</code>
  1076. */
  1077. protected void appendDetail(StringBuffer buffer, String fieldName, float[] array) {
  1078. buffer.append(arrayStart);
  1079. for (int i = 0; i < array.length; i++) {
  1080. if (i > 0) {
  1081. buffer.append(arraySeparator);
  1082. }
  1083. appendDetail(buffer, fieldName, array[i]);
  1084. }
  1085. buffer.append(arrayEnd);
  1086. }
  1087. /**
  1088. * <p>Append to the <code>toString</code> a summary of a
  1089. * <code>float</code> array.</p>
  1090. *
  1091. * @param buffer the <code>StringBuffer</code> to populate
  1092. * @param fieldName the field name, typically not used as already appended
  1093. * @param array the array to add to the <code>toString</code>,
  1094. * not <code>null</code>
  1095. */
  1096. protected void appendSummary(StringBuffer buffer, String fieldName, float[] array) {
  1097. appendSummarySize(buffer, fieldName, array.length);
  1098. }
  1099. //----------------------------------------------------------------------------
  1100. /**
  1101. * <p>Append to the <code>toString</code> a <code>boolean</code>
  1102. * array.</p>
  1103. *
  1104. * @param buffer the <code>StringBuffer</code> to populate
  1105. * @param fieldName the field name
  1106. * @param array the array to add to the toString
  1107. * @param fullDetail <code>true</code> for detail, <code>false</code>
  1108. * for summary info, <code>null</code> for style decides
  1109. */
  1110. public void append(StringBuffer buffer, String fieldName, boolean[] array, Boolean fullDetail) {
  1111. appendFieldStart(buffer, fieldName);
  1112. if (array == null) {
  1113. appendNullText(buffer, fieldName);
  1114. } else if (isFullDetail(fullDetail)) {
  1115. appendDetail(buffer, fieldName, array);
  1116. } else {
  1117. appendSummary(buffer, fieldName, array);
  1118. }
  1119. appendFieldEnd(buffer, fieldName);
  1120. }
  1121. /**
  1122. * <p>Append to the <code>toString</code> the detail of a
  1123. * <code>boolean</code> array.</p>
  1124. *
  1125. * @param buffer the <code>StringBuffer</code> to populate
  1126. * @param fieldName the field name, typically not used as already appended
  1127. * @param array the array to add to the <code>toString</code>,
  1128. * not <code>null</code>
  1129. */
  1130. protected void appendDetail(StringBuffer buffer, String fieldName, boolean[] array) {
  1131. buffer.append(arrayStart);
  1132. for (int i = 0; i < array.length; i++) {
  1133. if (i > 0) {
  1134. buffer.append(arraySeparator);
  1135. }
  1136. appendDetail(buffer, fieldName, array[i]);
  1137. }
  1138. buffer.append(arrayEnd);
  1139. }
  1140. /**
  1141. * <p>Append to the <code>toString</code> a summary of a
  1142. * <code>boolean</code> array.</p>
  1143. *
  1144. * @param buffer the <code>StringBuffer</code> to populate
  1145. * @param fieldName the field name, typically not used as already appended
  1146. * @param array the array to add to the <code>toString</code>,
  1147. * not <code>null</code>
  1148. */
  1149. protected void appendSummary(StringBuffer buffer, String fieldName, boolean[] array) {
  1150. appendSummarySize(buffer, fieldName, array.length);
  1151. }
  1152. //----------------------------------------------------------------------------
  1153. /**
  1154. * <p>Append to the <code>toString</code> the class name.</p>
  1155. *
  1156. * @param buffer the <code>StringBuffer</code> to populate
  1157. * @param object the <code>Object</code> whose name to output
  1158. */
  1159. protected void appendClassName(StringBuffer buffer, Object object) {
  1160. if (useClassName) {
  1161. if (useShortClassName) {
  1162. buffer.append(getShortClassName(object.getClass()));
  1163. } else {
  1164. buffer.append(object.getClass().getName());
  1165. }
  1166. }
  1167. }
  1168. /**
  1169. * <p>Append the {@link System#identityHashCode(java.lang.Object)}.</p>
  1170. *
  1171. * @param buffer the <code>StringBuffer</code> to populate
  1172. * @param object the <code>Object</code> whose id to output
  1173. */
  1174. protected void appendIdentityHashCode(StringBuffer buffer, Object object) {
  1175. if (useIdentityHashCode) {
  1176. buffer.append('@');
  1177. buffer.append(Integer.toHexString(System.identityHashCode(object)));
  1178. }
  1179. }
  1180. /**
  1181. * <p>Append to the <code>toString</code> the content start.</p>
  1182. *
  1183. * @param buffer the <code>StringBuffer</code> to populate
  1184. */
  1185. protected void appendContentStart(StringBuffer buffer) {
  1186. buffer.append(contentStart);
  1187. }
  1188. /**
  1189. * <p>Append to the <code>toString</code> the content end.</p>
  1190. *
  1191. * @param buffer the <code>StringBuffer</code> to populate
  1192. */
  1193. protected void appendContentEnd(StringBuffer buffer) {
  1194. buffer.append(contentEnd);
  1195. }
  1196. /**
  1197. * <p>Append to the <code>toString</code> an indicator for <code>null</code>.</p>
  1198. *
  1199. * <p>The default indicator is <code>'<null>'</code>.</p>
  1200. *
  1201. * @param buffer the <code>StringBuffer</code> to populate
  1202. * @param fieldName the field name, typically not used as already appended
  1203. */
  1204. protected void appendNullText(StringBuffer buffer, String fieldName) {
  1205. buffer.append(nullText);
  1206. }
  1207. /**
  1208. * <p>Append to the <code>toString</code> the field separator.</p>
  1209. *
  1210. * @param buffer the <code>StringBuffer</code> to populate
  1211. */
  1212. protected void appendFieldSeparator(StringBuffer buffer) {
  1213. buffer.append(fieldSeparator);
  1214. }
  1215. /**
  1216. * <p>Append to the <code>toString</code> the field start.</p>
  1217. *
  1218. * @param buffer the <code>StringBuffer</code> to populate
  1219. * @param fieldName the field name
  1220. */
  1221. protected void appendFieldStart(StringBuffer buffer, String fieldName) {
  1222. if (useFieldNames && fieldName != null) {
  1223. buffer.append(fieldName);
  1224. buffer.append(fieldNameValueSeparator);
  1225. }
  1226. }
  1227. /**
  1228. * <p>Append to the <code>toString<code> the field end.</p>
  1229. *
  1230. * @param buffer the <code>StringBuffer</code> to populate
  1231. * @param fieldName the field name, typically not used as already appended
  1232. */
  1233. protected void appendFieldEnd(StringBuffer buffer, String fieldName) {
  1234. appendFieldSeparator(buffer);
  1235. }
  1236. /**
  1237. * <p>Append to the <code>toString</code> a size summary.</p>
  1238. *
  1239. * <p>The size summary is used to summarize the contents of
  1240. * <code>Collections</code>, <code>Maps</code> and arrays.</p>
  1241. *
  1242. * <p>The output consists of a prefix, the passed in size
  1243. * and a suffix.</p>
  1244. *
  1245. * <p>The default format is <code>'<size=n>'<code>.</p>
  1246. *
  1247. * @param buffer the <code>StringBuffer</code> to populate
  1248. * @param fieldName the field name, typically not used as already appended
  1249. * @param size the size to append
  1250. */
  1251. protected void appendSummarySize(StringBuffer buffer, String fieldName, int size) {
  1252. buffer.append(sizeStartText);
  1253. buffer.append(size);
  1254. buffer.append(sizeEndText);
  1255. }
  1256. /**
  1257. * <p>Is this field to be output in full detail.</p>
  1258. *
  1259. * <p>This method converts a detail request into a detail level.
  1260. * The calling code may request full detail (<code>true</code>),
  1261. * but a subclass might ignore that and always return
  1262. * <code>false</code>. The calling code may pass in
  1263. * <code>null</code> indicating that it doesn't care about
  1264. * the detail level. In this case the default detail level is
  1265. * used.</p>
  1266. *
  1267. * @param fullDetailRequest the detail level requested
  1268. * @return whether full detail is to be shown
  1269. */
  1270. protected boolean isFullDetail(Boolean fullDetailRequest) {
  1271. if (fullDetailRequest == null) {
  1272. return defaultFullDetail;
  1273. }
  1274. return fullDetailRequest.booleanValue();
  1275. }
  1276. /**
  1277. * <p>Gets the short class name for a class.</p>
  1278. *
  1279. * <p>The short class name is the classname excluding
  1280. * the package name.</p>
  1281. *
  1282. * @param cls the <code>Class</code> to get the short name of
  1283. * @return the short name
  1284. */
  1285. protected String getShortClassName(Class cls) {
  1286. return ClassUtils.getShortClassName(cls);
  1287. }
  1288. // Setters and getters for the customizable parts of the style
  1289. // These methods are not expected to be overridden, except to make public
  1290. // (They are not public so that immutable subclasses can be written)
  1291. //---------------------------------------------------------------------
  1292. /**
  1293. * <p>Gets whether to use the class name.</p>
  1294. *
  1295. * @return the current useClassName flag
  1296. */
  1297. protected boolean isUseClassName() {
  1298. return useClassName;
  1299. }
  1300. /**
  1301. * <p>Sets whether to use the class name.</p>
  1302. *
  1303. * @param useClassName the new useClassName flag
  1304. */
  1305. protected void setUseClassName(boolean useClassName) {
  1306. this.useClassName = useClassName;
  1307. }
  1308. //---------------------------------------------------------------------
  1309. /**
  1310. * <p>Gets whether to output short or long class names.</p>
  1311. *
  1312. * @return the current useShortClassName flag
  1313. * @since 2.0
  1314. */
  1315. protected boolean isUseShortClassName() {
  1316. return useShortClassName;
  1317. }
  1318. /**
  1319. * <p>Gets whether to output short or long class names.</p>
  1320. *
  1321. * @return the current shortClassName flag
  1322. * @deprecated Use {@link #isUseShortClassName()}
  1323. * Method will be removed in Commons Lang 3.0.
  1324. */
  1325. protected boolean isShortClassName() {
  1326. return useShortClassName;
  1327. }
  1328. /**
  1329. * <p>Sets whether to output short or long class names.</p>
  1330. *
  1331. * @param useShortClassName the new useShortClassName flag
  1332. * @since 2.0
  1333. */
  1334. protected void setUseShortClassName(boolean useShortClassName) {
  1335. this.useShortClassName = useShortClassName;
  1336. }
  1337. /**
  1338. * <p>Sets whether to output short or long class names.</p>
  1339. *
  1340. * @param shortClassName the new shortClassName flag
  1341. * @deprecated Use {@link #setUseShortClassName(boolean)}
  1342. * Method will be removed in Commons Lang 3.0.
  1343. */
  1344. protected void setShortClassName(boolean shortClassName) {
  1345. this.useShortClassName = shortClassName;
  1346. }
  1347. //---------------------------------------------------------------------
  1348. /**
  1349. * <p>Gets whether to use the identity hash code.</p>
  1350. *
  1351. * @return the current useIdentityHashCode flag
  1352. */
  1353. protected boolean isUseIdentityHashCode() {
  1354. return useIdentityHashCode;
  1355. }
  1356. /**
  1357. * <p>Sets whether to use the identity hash code.</p>
  1358. *
  1359. * @param useIdentityHashCode the new useIdentityHashCode flag
  1360. */
  1361. protected void setUseIdentityHashCode(boolean useIdentityHashCode) {
  1362. this.useIdentityHashCode = useIdentityHashCode;
  1363. }
  1364. //---------------------------------------------------------------------
  1365. /**
  1366. * <p>Gets whether to use the field names passed in.</p>
  1367. *
  1368. * @return the current useFieldNames flag
  1369. */
  1370. protected boolean isUseFieldNames() {
  1371. return useFieldNames;
  1372. }
  1373. /**
  1374. * <p>Sets whether to use the field names passed in.</p>
  1375. *
  1376. * @param useFieldNames the new useFieldNames flag
  1377. */
  1378. protected void setUseFieldNames(boolean useFieldNames) {
  1379. this.useFieldNames = useFieldNames;
  1380. }
  1381. //---------------------------------------------------------------------
  1382. /**
  1383. * <p>Gets whether to use full detail when the caller doesn't
  1384. * specify.</p>
  1385. *
  1386. * @return the current defaultFullDetail flag
  1387. */
  1388. protected boolean isDefaultFullDetail() {
  1389. return defaultFullDetail;
  1390. }
  1391. /**
  1392. * <p>Sets whether to use full detail when the caller doesn't
  1393. * specify.</p>
  1394. *
  1395. * @param defaultFullDetail the new defaultFullDetail flag
  1396. */
  1397. protected void setDefaultFullDetail(boolean defaultFullDetail) {
  1398. this.defaultFullDetail = defaultFullDetail;
  1399. }
  1400. //---------------------------------------------------------------------
  1401. /**
  1402. * <p>Gets whether to output array content detail.</p>
  1403. *
  1404. * @return the current array content detail setting
  1405. */
  1406. protected boolean isArrayContentDetail() {
  1407. return arrayContentDetail;
  1408. }
  1409. /**
  1410. * <p>Sets whether to output array content detail.</p>
  1411. *
  1412. * @param arrayContentDetail the new arrayContentDetail flag
  1413. */
  1414. protected void setArrayContentDetail(boolean arrayContentDetail) {
  1415. this.arrayContentDetail = arrayContentDetail;
  1416. }
  1417. //---------------------------------------------------------------------
  1418. /**
  1419. * <p>Gets the array start text.</p>
  1420. *
  1421. * @return the current array start text
  1422. */
  1423. protected String getArrayStart() {
  1424. return arrayStart;
  1425. }
  1426. /**
  1427. * <p>Sets the array start text.</p>
  1428. *
  1429. * <p><code>null</code> is accepted, but will be converted to
  1430. * an empty String.</p>
  1431. *
  1432. * @param arrayStart the new array start text
  1433. */
  1434. protected void setArrayStart(String arrayStart) {
  1435. if (arrayStart == null) {
  1436. arrayStart = "";
  1437. }
  1438. this.arrayStart = arrayStart;
  1439. }
  1440. //---------------------------------------------------------------------
  1441. /**
  1442. * <p>Gets the array end text.</p>
  1443. *
  1444. * @return the current array end text
  1445. */
  1446. protected String getArrayEnd() {
  1447. return arrayEnd;
  1448. }
  1449. /**
  1450. * <p>Sets the array end text.</p>
  1451. *
  1452. * <p><code>null</code> is accepted, but will be converted to
  1453. * an empty String.</p>
  1454. *
  1455. * @param arrayEnd the new array end text
  1456. */
  1457. protected void setArrayEnd(String arrayEnd) {
  1458. if (arrayStart == null) {
  1459. arrayStart = "";
  1460. }
  1461. this.arrayEnd = arrayEnd;
  1462. }
  1463. //---------------------------------------------------------------------
  1464. /**
  1465. * <p>Gets the array separator text.</p>
  1466. *
  1467. * @return the current array separator text
  1468. */
  1469. protected String getArraySeparator() {
  1470. return arraySeparator;
  1471. }
  1472. /**
  1473. * <p>Sets the array separator text.</p>
  1474. *
  1475. * <p><code>null</code> is accepted, but will be converted to
  1476. * an empty String.</p>
  1477. *
  1478. * @param arraySeparator the new array separator text
  1479. */
  1480. protected void setArraySeparator(String arraySeparator) {
  1481. if (arraySeparator == null) {
  1482. arraySeparator = "";
  1483. }
  1484. this.arraySeparator = arraySeparator;
  1485. }
  1486. //---------------------------------------------------------------------
  1487. /**
  1488. * <p>Gets the content start text.</p>
  1489. *
  1490. * @return the current content start text
  1491. */
  1492. protected String getContentStart() {
  1493. return contentStart;
  1494. }
  1495. /**
  1496. * <p>Sets the content start text.</p>
  1497. *
  1498. * <p><code>null</code> is accepted, but will be converted to
  1499. * an empty String.</p>
  1500. *
  1501. * @param contentStart the new content start text
  1502. */
  1503. protected void setContentStart(String contentStart) {
  1504. if (contentStart == null) {
  1505. contentStart = "";
  1506. }
  1507. this.contentStart = contentStart;
  1508. }
  1509. //---------------------------------------------------------------------
  1510. /**
  1511. * <p>Gets the content end text.</p>
  1512. *
  1513. * @return the current content end text
  1514. */
  1515. protected String getContentEnd() {
  1516. return contentEnd;
  1517. }
  1518. /**
  1519. * <p>Sets the content end text.</p>
  1520. *
  1521. * <p><code>null</code> is accepted, but will be converted to
  1522. * an empty String.</p>
  1523. *
  1524. * @param contentEnd the new content end text
  1525. */
  1526. protected void setContentEnd(String contentEnd) {
  1527. if (contentEnd == null) {
  1528. contentEnd = "";
  1529. }
  1530. this.contentEnd = contentEnd;
  1531. }
  1532. //---------------------------------------------------------------------
  1533. /**
  1534. * <p>Gets the field name value separator text.</p>
  1535. *
  1536. * @return the current field name value separator text
  1537. */
  1538. protected String getFieldNameValueSeparator() {
  1539. return fieldNameValueSeparator;
  1540. }
  1541. /**
  1542. * <p>Sets the field name value separator text.</p>
  1543. *
  1544. * <p><code>null</code> is accepted, but will be converted to
  1545. * an empty String.</p>
  1546. *
  1547. * @param fieldNameValueSeparator the new field name value separator text
  1548. */
  1549. protected void setFieldNameValueSeparator(String fieldNameValueSeparator) {
  1550. if (fieldNameValueSeparator == null) {
  1551. fieldNameValueSeparator = "";
  1552. }
  1553. this.fieldNameValueSeparator = fieldNameValueSeparator;
  1554. }
  1555. //---------------------------------------------------------------------
  1556. /**
  1557. * <p>Gets the field separator text.</p>
  1558. *
  1559. * @return the current field separator text
  1560. */
  1561. protected String getFieldSeparator() {
  1562. return fieldSeparator;
  1563. }
  1564. /**
  1565. * <p>Sets the field separator text.</p>
  1566. *
  1567. * <p><code>null</code> is accepted, but will be converted to
  1568. * an empty String.</p>
  1569. *
  1570. * @param fieldSeparator the new field separator text
  1571. */
  1572. protected void setFieldSeparator(String fieldSeparator) {
  1573. if (fieldSeparator == null) {
  1574. fieldSeparator = "";
  1575. }
  1576. this.fieldSeparator = fieldSeparator;
  1577. }
  1578. //---------------------------------------------------------------------
  1579. /**
  1580. * <p>Gets whether the field separator should be added at the start
  1581. * of each buffer.</p>
  1582. *
  1583. * @return the fieldSeparatorAtStart flag
  1584. * @since 2.0
  1585. */
  1586. protected boolean isFieldSeparatorAtStart() {
  1587. return fieldSeparatorAtStart;
  1588. }
  1589. /**
  1590. * <p>Sets whether the field separator should be added at the start
  1591. * of each buffer.</p>
  1592. *
  1593. * @param fieldSeparatorAtStart the fieldSeparatorAtStart flag
  1594. * @since 2.0
  1595. */
  1596. protected void setFieldSeparatorAtStart(boolean fieldSeparatorAtStart) {
  1597. this.fieldSeparatorAtStart = fieldSeparatorAtStart;
  1598. }
  1599. //---------------------------------------------------------------------
  1600. /**
  1601. * <p>Gets whether the field separator should be added at the end
  1602. * of each buffer.</p>
  1603. *
  1604. * @return fieldSeparatorAtEnd flag
  1605. * @since 2.0
  1606. */
  1607. protected boolean isFieldSeparatorAtEnd() {
  1608. return fieldSeparatorAtEnd;
  1609. }
  1610. /**
  1611. * <p>Sets whether the field separator should be added at the end
  1612. * of each buffer.</p>
  1613. *
  1614. * @param fieldSeparatorAtEnd the fieldSeparatorAtEnd flag
  1615. * @since 2.0
  1616. */
  1617. protected void setFieldSeparatorAtEnd(boolean fieldSeparatorAtEnd) {
  1618. this.fieldSeparatorAtEnd = fieldSeparatorAtEnd;
  1619. }
  1620. //---------------------------------------------------------------------
  1621. /**
  1622. * <p>Gets the text to output when <code>null</code> found.</p>
  1623. *
  1624. * @return the current text to output when null found
  1625. */
  1626. protected String getNullText() {
  1627. return nullText;
  1628. }
  1629. /**
  1630. * <p>Sets the text to output when <code>null</code> found.</p>
  1631. *
  1632. * <p><code>null</code> is accepted, but will be converted to
  1633. * an empty String.</p>
  1634. *
  1635. * @param nullText the new text to output when null found
  1636. */
  1637. protected void setNullText(String nullText) {
  1638. if (nullText == null) {
  1639. nullText = "";
  1640. }
  1641. this.nullText = nullText;
  1642. }
  1643. //---------------------------------------------------------------------
  1644. /**
  1645. * <p>Gets the start text to output when a <code>Collection</code>,
  1646. * <code>Map</code> or array size is output.</p>
  1647. *
  1648. * <p>This is output before the size value.</p>
  1649. *
  1650. * @return the current start of size text
  1651. */
  1652. protected String getSizeStartText() {
  1653. return sizeStartText;
  1654. }
  1655. /**
  1656. * <p>Sets the start text to output when a <code>Collection</code>,
  1657. * <code>Map</code> or array size is output.</p>
  1658. *
  1659. * <p>This is output before the size value.</p>
  1660. *
  1661. * <p><code>null</code> is accepted, but will be converted to
  1662. * an empty String.</p>
  1663. *
  1664. * @param sizeStartText the new start of size text
  1665. */
  1666. protected void setSizeStartText(String sizeStartText) {
  1667. if (sizeStartText == null) {
  1668. sizeStartText = "";
  1669. }
  1670. this.sizeStartText = sizeStartText;
  1671. }
  1672. //---------------------------------------------------------------------
  1673. /**
  1674. * <p>Gets the end text to output when a <code>Collection</code>,
  1675. * <code>Map</code> or array size is output.</p>
  1676. *
  1677. * <p>This is output after the size value.</p>
  1678. *
  1679. * @return the current end of size text
  1680. */
  1681. protected String getSizeEndText() {
  1682. return sizeEndText;
  1683. }
  1684. /**
  1685. * <p>Sets the end text to output when a <code>Collection</code>,
  1686. * <code>Map</code> or array size is output.</p>
  1687. *
  1688. * <p>This is output after the size value.</p>
  1689. *
  1690. * <p><code>null</code> is accepted, but will be converted to
  1691. * an empty String.</p>
  1692. *
  1693. * @param sizeEndText the new end of size text
  1694. */
  1695. protected void setSizeEndText(String sizeEndText) {
  1696. if (sizeEndText == null) {
  1697. sizeEndText = "";
  1698. }
  1699. this.sizeEndText = sizeEndText;
  1700. }
  1701. //---------------------------------------------------------------------
  1702. /**
  1703. * <p>Gets the start text to output when an <code>Object</code> is
  1704. * output in summary mode.</p>
  1705. *
  1706. * <p>This is output before the size value.</p>
  1707. *
  1708. * @return the current start of summary text
  1709. */
  1710. protected String getSummaryObjectStartText() {
  1711. return summaryObjectStartText;
  1712. }
  1713. /**
  1714. * <p>Sets the start text to output when an <code>Object</code> is
  1715. * output in summary mode.</p>
  1716. *
  1717. * <p>This is output before the size value.</p>
  1718. *
  1719. * <p><code>null</code> is accepted, but will be converted to
  1720. * an empty String.</p>
  1721. *
  1722. * @param summaryObjectStartText the new start of summary text
  1723. */
  1724. protected void setSummaryObjectStartText(String summaryObjectStartText) {
  1725. if (summaryObjectStartText == null) {
  1726. summaryObjectStartText = "";
  1727. }
  1728. this.summaryObjectStartText = summaryObjectStartText;
  1729. }
  1730. //---------------------------------------------------------------------
  1731. /**
  1732. * <p>Gets the end text to output when an <code>Object</code> is
  1733. * output in summary mode.</p>
  1734. *
  1735. * <p>This is output after the size value.</p>
  1736. *
  1737. * @return the current end of summary text
  1738. */
  1739. protected String getSummaryObjectEndText() {
  1740. return summaryObjectEndText;
  1741. }
  1742. /**
  1743. * <p>Sets the end text to output when an <code>Object</code> is
  1744. * output in summary mode.</p>
  1745. *
  1746. * <p>This is output after the size value.</p>
  1747. *
  1748. * <p><code>null</code> is accepted, but will be converted to
  1749. * an empty String.</p>
  1750. *
  1751. * @param summaryObjectEndText the new end of summary text
  1752. */
  1753. protected void setSummaryObjectEndText(String summaryObjectEndText) {
  1754. if (summaryObjectEndText == null) {
  1755. summaryObjectEndText = "";
  1756. }
  1757. this.summaryObjectEndText = summaryObjectEndText;
  1758. }
  1759. //----------------------------------------------------------------------------
  1760. /**
  1761. * <p>Default <code>ToStringStyle</code>.</p>
  1762. *
  1763. * <p>This is an inner class rather than using
  1764. * <code>StandardToStringStyle</code> to ensure its immutability.</p>
  1765. */
  1766. private static final class DefaultToStringStyle extends ToStringStyle {
  1767. /**
  1768. * <p>Constructor.</p>
  1769. *
  1770. * <p>Use the static constant rather than instantiating.</p>
  1771. */
  1772. private DefaultToStringStyle() {
  1773. super();
  1774. }
  1775. /**
  1776. * <p>Ensure <code>Singleton</code> after serialization.</p>
  1777. *
  1778. * @return the singleton
  1779. */
  1780. private Object readResolve() {
  1781. return ToStringStyle.DEFAULT_STYLE;
  1782. }
  1783. }
  1784. //----------------------------------------------------------------------------
  1785. /**
  1786. * <p><code>ToStringStyle</code> that does not print out
  1787. * the field names.</p>
  1788. *
  1789. * <p>This is an inner class rather than using
  1790. * <code>StandardToStringStyle</code> to ensure its immutability.
  1791. */
  1792. private static final class NoFieldNameToStringStyle extends ToStringStyle {
  1793. /**
  1794. * <p>Constructor.</p>
  1795. *
  1796. * <p>Use the static constant rather than instantiating.</p>
  1797. */
  1798. private NoFieldNameToStringStyle() {
  1799. super();
  1800. this.setUseFieldNames(false);
  1801. }
  1802. /**
  1803. * <p>Ensure <code>Singleton</code> after serialization.</p>
  1804. *
  1805. * @return the singleton
  1806. */
  1807. private Object readResolve() {
  1808. return ToStringStyle.NO_FIELD_NAMES_STYLE;
  1809. }
  1810. }
  1811. //----------------------------------------------------------------------------
  1812. /**
  1813. * <p><code>ToStringStyle</code> that does not print out the
  1814. * classname, identity hashcode, content start or field name.</p>
  1815. *
  1816. * <p>This is an inner class rather than using
  1817. * <code>StandardToStringStyle</code> to ensure its immutability.</p>
  1818. */
  1819. private static final class SimpleToStringStyle extends ToStringStyle {
  1820. /**
  1821. * <p>Constructor.</p>
  1822. *
  1823. * <p>Use the static constant rather than instantiating.</p>
  1824. */
  1825. private SimpleToStringStyle() {
  1826. super();
  1827. this.setUseClassName(false);
  1828. this.setUseIdentityHashCode(false);
  1829. this.setUseFieldNames(false);
  1830. this.setContentStart("");
  1831. this.setContentEnd("");
  1832. }
  1833. /**
  1834. * <p>Ensure <code>Singleton</ode> after serialization.</p>
  1835. * @return the singleton
  1836. */
  1837. private Object readResolve() {
  1838. return ToStringStyle.SIMPLE_STYLE;
  1839. }
  1840. }
  1841. //----------------------------------------------------------------------------
  1842. /**
  1843. * <p><code>ToStringStyle</code> that outputs on multiple lines.</p>
  1844. *
  1845. * <p>This is an inner class rather than using
  1846. * <code>StandardToStringStyle</code> to ensure its immutability.</p>
  1847. */
  1848. private static final class MultiLineToStringStyle extends ToStringStyle {
  1849. /**
  1850. * <p>Constructor.</p>
  1851. *
  1852. * <p>Use the static constant rather than instantiating.</p>
  1853. */
  1854. private MultiLineToStringStyle() {
  1855. super();
  1856. this.setContentStart("[");
  1857. this.setFieldSeparator(SystemUtils.LINE_SEPARATOR + " ");
  1858. this.setFieldSeparatorAtStart(true);
  1859. this.setContentEnd(SystemUtils.LINE_SEPARATOR + "]");
  1860. }
  1861. /**
  1862. * <p>Ensure <code>Singleton</code> after serialization.</p>
  1863. *
  1864. * @return the singleton
  1865. */
  1866. private Object readResolve() {
  1867. return ToStringStyle.MULTI_LINE_STYLE;
  1868. }
  1869. }
  1870. //----------------------------------------------------------------------------
  1871. // Removed, as the XML style needs more work for escaping characters, arrays,
  1872. // collections, maps and embedded beans.
  1873. // /**
  1874. // * ToStringStyle that outputs in XML style
  1875. // */
  1876. // private static class XMLToStringStyle extends ToStringStyle {
  1877. //
  1878. // /**
  1879. // * Constructor - use the static constant rather than instantiating.
  1880. // */
  1881. // private XMLToStringStyle() {
  1882. // super();
  1883. // nullText = "null";
  1884. // sizeStartText = "size=";
  1885. // sizeEndText = "";
  1886. // }
  1887. //
  1888. // /**
  1889. // * @see ToStringStyle#appendStart(StringBuffer, Object)
  1890. // */
  1891. // public void appendStart(StringBuffer buffer, Object object) {
  1892. // buffer.append('<');
  1893. // buffer.append(getShortClassName(object.getClass()));
  1894. // buffer.append(" class=\"");
  1895. // appendClassName(buffer, object);
  1896. // buffer.append("\" hashCode=\"");
  1897. // appendIdentityHashCode(buffer, object);
  1898. // buffer.append("\">");
  1899. // buffer.append(SystemUtils.LINE_SEPARATOR);
  1900. // buffer.append(" ");
  1901. // }
  1902. //
  1903. // /**
  1904. // * @see ToStringStyle#appendFieldStart(StringBuffer, String)
  1905. // */
  1906. // protected void appendFieldStart(StringBuffer buffer, String fieldName) {
  1907. // buffer.append('<');
  1908. // buffer.append(fieldName);
  1909. // buffer.append('>');
  1910. // }
  1911. //
  1912. // /**
  1913. // * @see ToStringStyle#appendFieldEnd(StringBuffer, String)
  1914. // */
  1915. // protected void appendFieldEnd(StringBuffer buffer, String fieldName) {
  1916. // buffer.append("</");
  1917. // buffer.append(fieldName);
  1918. // buffer.append('>');
  1919. // buffer.append(SystemUtils.LINE_SEPARATOR);
  1920. // buffer.append(" ");
  1921. // }
  1922. //
  1923. // /**
  1924. // * @see ToStringStyle#appendEnd(StringBuffer, Object)
  1925. // */
  1926. // public void appendEnd(StringBuffer buffer, Object object) {
  1927. // int len = buffer.length();
  1928. // if (len > 2 && buffer.charAt(len - 1) == ' ' && buffer.charAt(len - 2) == ' ') {
  1929. // buffer.setLength(len - 2);
  1930. // }
  1931. // buffer.append("</");
  1932. // buffer.append(getShortClassName(object.getClass()));
  1933. // buffer.append("\">");
  1934. // }
  1935. //
  1936. // }
  1937. }