1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.text

File XWikiToStringStyle.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
32
4
1
102
59
8
0.25
8
4
2

Classes

Class Line # Actions
XWikiToStringStyle 39 32 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 161 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.text;
21   
22    import java.util.Collection;
23    import java.util.Iterator;
24    import java.util.Map;
25   
26    import org.apache.commons.lang3.builder.StandardToStringStyle;
27   
28    /**
29    * Custom XWiki Style for {@link org.apache.commons.lang3.builder.ToStringBuilder}.
30    * Generates {@code toString()} result of the format:
31    * <pre><code>
32    * Typed = [true] Type = [doc] Reference = [reference] Base References = [[baseref1], [baseref2]],
33    * Parameters = [[name1] = [value1], [name2] = [value2]]
34    * </code></pre>
35    *
36    * @version $Id: 764d15ab72eb74a504ed1dbfc4cb34a91ca6da5f $
37    * @since 4.0M2
38    */
 
39    public class XWikiToStringStyle extends StandardToStringStyle
40    {
41    private static final long serialVersionUID = 1767758908431225408L;
42   
43    /**
44    * Sets the XWiki style.
45    */
 
46  73914 toggle public XWikiToStringStyle()
47    {
48  73896 super();
49  73917 setUseClassName(false);
50  73914 setUseIdentityHashCode(false);
51  73917 setContentStart("");
52  73908 setContentEnd("]");
53  73918 setFieldNameValueSeparator(" = [");
54  73905 setSeparator(",");
55    }
56   
57    /**
58    * @param separator the separator to use between fields
59    */
 
60  74382 toggle public void setSeparator(String separator)
61    {
62  74404 setFieldSeparator(String.format("]%s ", separator));
63    }
64   
 
65  3 toggle @Override
66    protected void appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll)
67    {
68  3 Iterator<?> it = coll.iterator();
69  8 while (it.hasNext()) {
70  5 Object value = it.next();
71  5 buffer.append('[');
72  5 buffer.append(value);
73  5 buffer.append(']');
74  5 if (it.hasNext()) {
75  2 buffer.append(',');
76  2 buffer.append(' ');
77    }
78    }
79    }
80   
 
81  36837 toggle @Override
82    protected void appendDetail(StringBuffer buffer, String fieldName, Map<?, ?> map)
83    {
84  36850 Iterator<?> it = map.entrySet().iterator();
85  117066 while (it.hasNext()) {
86  80214 Map.Entry<?, ?> entry = (Map.Entry<?, ?>) it.next();
87  80210 buffer.append('[');
88  80213 buffer.append(entry.getKey());
89  80227 buffer.append(']');
90  80221 buffer.append(' ');
91  80215 buffer.append('=');
92  80205 buffer.append(' ');
93  80211 buffer.append('[');
94  80203 buffer.append(entry.getValue());
95  80227 buffer.append(']');
96  80222 if (it.hasNext()) {
97  57838 buffer.append(',');
98  57840 buffer.append(' ');
99    }
100    }
101    }
102    }