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

File FormatBlock.java

 

Coverage histogram

../../../../img/srcFileCovDistChart4.png
80% of files have more coverage

Code metrics

4
16
8
1
116
57
11
0.69
2
8
1.38

Classes

Class Line # Actions
FormatBlock 36 16 0% 11 17
0.3928571339.3%
 

Contributing tests

This file is covered by 197 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.rendering.block;
21   
22    import java.util.Collections;
23    import java.util.List;
24    import java.util.Map;
25   
26    import org.apache.commons.lang3.builder.HashCodeBuilder;
27    import org.xwiki.rendering.listener.Format;
28    import org.xwiki.rendering.listener.Listener;
29   
30    /**
31    * Represents a text formatting block (bold, italic, etc).
32    *
33    * @version $Id: 55047ee4c63f71a4377affa51898a8eb26daa711 $
34    * @since 1.6M1
35    */
 
36    public class FormatBlock extends AbstractBlock
37    {
38    /**
39    * The formatting to apply to the children blocks.
40    */
41    private Format format;
42   
43    /**
44    * Create an empty format block with no children. This is useful when the user wants to call {@link #addChild(Block)}
45    * manually for adding children one by one after the block is constructed.
46    */
 
47  0 toggle public FormatBlock()
48    {
49  0 this.format = Format.NONE;
50    }
51   
52    /**
53    * @param childrenBlocks the nested children blocks
54    * @param format the formatting to apply to the children blocks
55    */
 
56  3099 toggle public FormatBlock(List<Block> childrenBlocks, Format format)
57    {
58  3099 this(childrenBlocks, format, Collections.emptyMap());
59    }
60   
61    /**
62    * @param childrenBlocks the nested children blocks
63    * @param format the formatting to apply to the children blocks
64    * @param parameters the custom parameters
65    */
 
66  34408 toggle public FormatBlock(List<Block> childrenBlocks, Format format, Map<String, String> parameters)
67    {
68  34404 super(childrenBlocks, parameters);
69  34408 this.format = format;
70    }
71   
72    /**
73    * @return the formatting to apply to the children blocks
74    */
 
75  136003 toggle public Format getFormat()
76    {
77  136014 return this.format;
78    }
79   
 
80  68003 toggle @Override
81    public void before(Listener listener)
82    {
83  68007 listener.beginFormat(getFormat(), getParameters());
84    }
85   
 
86  68004 toggle @Override
87    public void after(Listener listener)
88    {
89  68007 listener.endFormat(getFormat(), getParameters());
90    }
91   
 
92  0 toggle @Override
93    public boolean equals(Object obj)
94    {
95  0 if (obj == this) {
96  0 return true;
97    }
98   
99  0 if (obj instanceof FormatBlock && super.equals(obj)) {
100  0 return getFormat() == ((FormatBlock) obj).getFormat();
101    }
102   
103  0 return false;
104    }
105   
 
106  0 toggle @Override
107    public int hashCode()
108    {
109  0 HashCodeBuilder builder = new HashCodeBuilder();
110   
111  0 builder.appendSuper(super.hashCode());
112  0 builder.append(getFormat());
113   
114  0 return builder.toHashCode();
115    }
116    }