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. */