1. Project Clover database Tue Dec 20 2016 21:24:09 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 166 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  19527 toggle public XWikiToStringStyle()
47    {
48  19529 super();
49  19529 setUseClassName(false);
50  19500 setUseIdentityHashCode(false);
51  19501 setContentStart("");
52  19514 setContentEnd("]");
53  19504 setFieldNameValueSeparator(" = [");
54  19515 setSeparator(",");
55    }
56   
57    /**
58    * @param separator the separator to use between fields
59    */
 
60  19986 toggle public void setSeparator(String separator)
61    {
62  20015 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  9638 toggle @Override
82    protected void appendDetail(StringBuffer buffer, String fieldName, Map<?, ?> map)
83    {
84  9645 Iterator<?> it = map.entrySet().iterator();
85  22858 while (it.hasNext()) {
86  13218 Map.Entry<?, ?> entry = (Map.Entry<?, ?>) it.next();
87  13225 buffer.append('[');
88  13223 buffer.append(entry.getKey());
89  13223 buffer.append(']');
90  13222 buffer.append(' ');
91  13225 buffer.append('=');
92  13220 buffer.append(' ');
93  13222 buffer.append('[');
94  13223 buffer.append(entry.getValue());
95  13227 buffer.append(']');
96  13226 if (it.hasNext()) {
97  5198 buffer.append(',');
98  5201 buffer.append(' ');
99    }
100    }
101    }
102    }