View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.lang3.builder;
18  
19  import java.lang.reflect.Array;
20  import java.util.Collection;
21  import java.util.Map;
22  
23  /**
24   * Works with {@link ToStringBuilder} to create a {@code toString}.
25   *
26   * <p>
27   * This class is intended to be used as a singleton.
28   * There is no need to instantiate a new style each time.
29   * Simply instantiate the class once, customize the values as required, and
30   * store the result in a public static final variable for the rest of the
31   * program to access.
32   * </p>
33   *
34   * @since 1.0
35   */
36  public class StandardToStringStyle extends ToStringStyle {
37  
38      /**
39       * Required for serialization support.
40       *
41       * @see java.io.Serializable
42       */
43      private static final long serialVersionUID = 1L;
44  
45      /**
46       * Constructs a new instance.
47       */
48      public StandardToStringStyle() {
49      }
50  
51      /**
52       * Gets the array end text.
53       *
54       * @return The current array end text
55       */
56      @Override
57      public String getArrayEnd() {
58          return super.getArrayEnd();
59      }
60  
61      /**
62       * Gets the array separator text.
63       *
64       * @return The current array separator text
65       */
66      @Override
67      public String getArraySeparator() {
68          return super.getArraySeparator();
69      }
70  
71      /**
72       * Gets the array start text.
73       *
74       * @return The current array start text
75       */
76      @Override
77      public String getArrayStart() {
78          return super.getArrayStart();
79      }
80  
81      /**
82       * Gets the content end text.
83       *
84       * @return The current content end text
85       */
86      @Override
87      public String getContentEnd() {
88          return super.getContentEnd();
89      }
90  
91      /**
92       * Gets the content start text.
93       *
94       * @return The current content start text
95       */
96      @Override
97      public String getContentStart() {
98          return super.getContentStart();
99      }
100 
101     /**
102      * Gets the field name value separator text.
103      *
104      * @return The current field name value separator text
105      */
106     @Override
107     public String getFieldNameValueSeparator() {
108         return super.getFieldNameValueSeparator();
109     }
110 
111     /**
112      * Gets the field separator text.
113      *
114      * @return The current field separator text
115      */
116     @Override
117     public String getFieldSeparator() {
118         return super.getFieldSeparator();
119     }
120 
121     /**
122      * Gets the text to output when {@code null} found.
123      *
124      * @return The current text to output when {@code null} found
125      */
126     @Override
127     public String getNullText() {
128         return super.getNullText();
129     }
130 
131     /**
132      * Gets the end text to output when a {@link Collection},
133      * {@link Map} or {@link Array} size is output.
134      *
135      * <p>
136      * This is output after the size value.
137      * </p>
138      *
139      * @return The current end of size text
140      */
141     @Override
142     public String getSizeEndText() {
143         return super.getSizeEndText();
144     }
145 
146     /**
147      * Gets the text to output when a {@link Collection},
148      * {@link Map} or {@link Array} size is output.
149      *
150      * <p>
151      * This is output before the size value.
152      * </p>
153      *
154      * @return The current start of size text
155      */
156     @Override
157     public String getSizeStartText() {
158         return super.getSizeStartText();
159     }
160 
161     /**
162      * Gets the end text to output when an {@link Object} is
163      * output in summary mode.
164      *
165      * <p>
166      * This is output after the size value.
167      * </p>
168      *
169      * @return The current end of summary text
170      */
171     @Override
172     public String getSummaryObjectEndText() {
173         return super.getSummaryObjectEndText();
174     }
175 
176     /**
177      * Gets the start text to output when an {@link Object} is
178      * output in summary mode.
179      *
180      * <p>
181      * This is output before the size value.
182      * </p>
183      *
184      * @return The current start of summary text
185      */
186     @Override
187     public String getSummaryObjectStartText() {
188         return super.getSummaryObjectStartText();
189     }
190 
191     /**
192      * Tests whether to output array content detail.
193      *
194      * @return The current array content detail setting
195      */
196     @Override
197     public boolean isArrayContentDetail() {
198         return super.isArrayContentDetail();
199     }
200 
201     /**
202      * Tests whether full detail is used when the caller does not specify a detail level.
203      *
204      * @return The current defaultFullDetail flag
205      */
206     @Override
207     public boolean isDefaultFullDetail() {
208         return super.isDefaultFullDetail();
209     }
210 
211     /**
212      * Tests whether the field separator should be added at the end of each buffer.
213      *
214      * @return fieldSeparatorAtEnd flag
215      * @since 2.0
216      */
217     @Override
218     public boolean isFieldSeparatorAtEnd() {
219         return super.isFieldSeparatorAtEnd();
220     }
221 
222     /**
223      * Tests whether the field separator should be added at the start of each buffer.
224      *
225      * @return The fieldSeparatorAtStart flag
226      * @since 2.0
227      */
228     @Override
229     public boolean isFieldSeparatorAtStart() {
230         return super.isFieldSeparatorAtStart();
231     }
232 
233     /**
234      * Tests whether to use the class name.
235      *
236      * @return The current useClassName flag
237      */
238     @Override
239     public boolean isUseClassName() {
240         return super.isUseClassName();
241     }
242 
243     /**
244      * Tests whether to use the field names passed in.
245      *
246      * @return The current useFieldNames flag
247      */
248     @Override
249     public boolean isUseFieldNames() {
250         return super.isUseFieldNames();
251     }
252 
253     /**
254      * Tests whether to use the identity hash code.
255      *
256      * @return The current useIdentityHashCode flag
257      */
258     @Override
259     public boolean isUseIdentityHashCode() {
260         return super.isUseIdentityHashCode();
261     }
262 
263     /**
264      * Tests whether short class names should be output.
265      *
266      * @return The current useShortClassName flag
267      * @since 2.0
268      */
269     @Override
270     public boolean isUseShortClassName() {
271         return super.isUseShortClassName();
272     }
273 
274     /**
275      * Sets whether to output array content detail.
276      *
277      * @param arrayContentDetail  The new arrayContentDetail flag
278      */
279     @Override
280     public void setArrayContentDetail(final boolean arrayContentDetail) {
281         super.setArrayContentDetail(arrayContentDetail);
282     }
283 
284     /**
285      * Sets the array end text.
286      *
287      * <p>
288      * {@code null} is accepted, but will be converted
289      * to an empty String.
290      * </p>
291      *
292      * @param arrayEnd  The new array end text
293      */
294     @Override
295     public void setArrayEnd(final String arrayEnd) {
296         super.setArrayEnd(arrayEnd);
297     }
298 
299     /**
300      * Sets the array separator text.
301      *
302      * <p>
303      * {@code null} is accepted, but will be converted
304      * to an empty String.
305      * </p>
306      *
307      * @param arraySeparator  The new array separator text
308      */
309     @Override
310     public void setArraySeparator(final String arraySeparator) {
311         super.setArraySeparator(arraySeparator);
312     }
313 
314     /**
315      * Sets the array start text.
316      *
317      * <p>
318      * {@code null} is accepted, but will be converted
319      * to an empty String.
320      * </p>
321      *
322      * @param arrayStart  The new array start text
323      */
324     @Override
325     public void setArrayStart(final String arrayStart) {
326         super.setArrayStart(arrayStart);
327     }
328 
329     /**
330      * Sets the content end text.
331      *
332      * <p>
333      * {@code null} is accepted, but will be converted
334      * to an empty String.
335      * </p>
336      *
337      * @param contentEnd  The new content end text
338      */
339     @Override
340     public void setContentEnd(final String contentEnd) {
341         super.setContentEnd(contentEnd);
342     }
343 
344     /**
345      * Sets the content start text.
346      *
347      * <p>
348      * {@code null} is accepted, but will be converted
349      * to an empty String.
350      * </p>
351      *
352      * @param contentStart  The new content start text
353      */
354     @Override
355     public void setContentStart(final String contentStart) {
356         super.setContentStart(contentStart);
357     }
358 
359     /**
360      * Sets whether to use full detail when the caller doesn't
361      * specify.
362      *
363      * @param defaultFullDetail  The new defaultFullDetail flag
364      */
365     @Override
366     public void setDefaultFullDetail(final boolean defaultFullDetail) {
367         super.setDefaultFullDetail(defaultFullDetail);
368     }
369 
370     /**
371      * Sets the field name value separator text.
372      *
373      * <p>
374      * {@code null} is accepted, but will be converted
375      * to an empty String.
376      * </p>
377      *
378      * @param fieldNameValueSeparator  The new field name value separator text
379      */
380     @Override
381     public void setFieldNameValueSeparator(final String fieldNameValueSeparator) {
382         super.setFieldNameValueSeparator(fieldNameValueSeparator);
383     }
384 
385     /**
386      * Sets the field separator text.
387      *
388      * <p>
389      * {@code null} is accepted, but will be converted
390      * to an empty String.
391      * </p>
392      *
393      * @param fieldSeparator  The new field separator text
394      */
395     @Override
396     public void setFieldSeparator(final String fieldSeparator) {
397         super.setFieldSeparator(fieldSeparator);
398     }
399 
400     /**
401      * Sets whether the field separator should be added at the end
402      * of each buffer.
403      *
404      * @param fieldSeparatorAtEnd  The fieldSeparatorAtEnd flag
405      * @since 2.0
406      */
407     @Override
408     public void setFieldSeparatorAtEnd(final boolean fieldSeparatorAtEnd) {
409         super.setFieldSeparatorAtEnd(fieldSeparatorAtEnd);
410     }
411 
412     /**
413      * Sets whether the field separator should be added at the start
414      * of each buffer.
415      *
416      * @param fieldSeparatorAtStart  The fieldSeparatorAtStart flag
417      * @since 2.0
418      */
419     @Override
420     public void setFieldSeparatorAtStart(final boolean fieldSeparatorAtStart) {
421         super.setFieldSeparatorAtStart(fieldSeparatorAtStart);
422     }
423 
424     /**
425      * Sets the text to output when {@code null} found.
426      *
427      * <p>
428      * {@code null} is accepted, but will be converted
429      * to an empty String.
430      * </p>
431      *
432      * @param nullText  The new text to output when {@code null} found
433      */
434     @Override
435     public void setNullText(final String nullText) {
436         super.setNullText(nullText);
437     }
438 
439     /**
440      * Sets the end text to output when a {@link Collection},
441      * {@link Map} or {@link Array} size is output.
442      *
443      * <p>
444      * This is output after the size value.
445      * </p>
446      *
447      * <p>
448      * {@code null} is accepted, but will be converted
449      * to an empty String.
450      * </p>
451      *
452      * @param sizeEndText  The new end of size text
453      */
454     @Override
455     public void setSizeEndText(final String sizeEndText) {
456         super.setSizeEndText(sizeEndText);
457     }
458 
459     /**
460      * Sets the start text to output when a {@link Collection},
461      * {@link Map} or {@link Array} size is output.
462      *
463      * <p>
464      * This is output before the size value.
465      * </p>
466      *
467      * <p>
468      * {@code null} is accepted, but will be converted to
469      * an empty String.
470      * </p>
471      *
472      * @param sizeStartText  The new start of size text
473      */
474     @Override
475     public void setSizeStartText(final String sizeStartText) {
476         super.setSizeStartText(sizeStartText);
477     }
478 
479     /**
480      * Sets the end text to output when an {@link Object} is
481      * output in summary mode.
482      *
483      * <p>
484      * This is output after the size value.
485      * </p>
486      *
487      * <p>
488      * {@code null} is accepted, but will be converted to
489      * an empty String.
490      * </p>
491      *
492      * @param summaryObjectEndText  The new end of summary text
493      */
494     @Override
495     public void setSummaryObjectEndText(final String summaryObjectEndText) {
496         super.setSummaryObjectEndText(summaryObjectEndText);
497     }
498 
499     /**
500      * Sets the start text to output when an {@link Object} is
501      * output in summary mode.
502      *
503      * <p>
504      * This is output before the size value.
505      * </p>
506      *
507      * <p>
508      * {@code null} is accepted, but will be converted to
509      * an empty String.
510      * </p>
511      *
512      * @param summaryObjectStartText  The new start of summary text
513      */
514     @Override
515     public void setSummaryObjectStartText(final String summaryObjectStartText) {
516         super.setSummaryObjectStartText(summaryObjectStartText);
517     }
518 
519     /**
520      * Sets whether to use the class name.
521      *
522      * @param useClassName  The new useClassName flag
523      */
524     @Override
525     public void setUseClassName(final boolean useClassName) {
526         super.setUseClassName(useClassName);
527     }
528 
529     /**
530      * Sets whether to use the field names passed in.
531      *
532      * @param useFieldNames  The new useFieldNames flag
533      */
534     @Override
535     public void setUseFieldNames(final boolean useFieldNames) {
536         super.setUseFieldNames(useFieldNames);
537     }
538 
539     /**
540      * Sets whether to use the identity hash code.
541      *
542      * @param useIdentityHashCode  The new useIdentityHashCode flag
543      */
544     @Override
545     public void setUseIdentityHashCode(final boolean useIdentityHashCode) {
546         super.setUseIdentityHashCode(useIdentityHashCode);
547     }
548 
549     /**
550      * Sets whether to output short or long class names.
551      *
552      * @param useShortClassName  The new useShortClassName flag
553      * @since 2.0
554      */
555     @Override
556     public void setUseShortClassName(final boolean useShortClassName) {
557         super.setUseShortClassName(useShortClassName);
558     }
559 
560 }