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