1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.block

File HeaderBlock.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

4
26
11
1
160
77
14
0.54
2.36
11
1.27

Classes

Class Line # Actions
HeaderBlock 34 26 0% 14 18
0.560975656.1%
 

Contributing tests

This file is covered by 103 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.List;
23    import java.util.Map;
24   
25    import org.apache.commons.lang3.builder.EqualsBuilder;
26    import org.apache.commons.lang3.builder.HashCodeBuilder;
27    import org.xwiki.rendering.listener.HeaderLevel;
28    import org.xwiki.rendering.listener.Listener;
29   
30    /**
31    * @version $Id: 191c68a68b0cd26fda2cce6c607ff0b213401597 $
32    * @since 1.5M2
33    */
 
34    public class HeaderBlock extends AbstractBlock
35    {
36    /**
37    * The level of the header.
38    */
39    private HeaderLevel level;
40   
41    /**
42    * The id of the header.
43    */
44    private String id;
45   
46    /**
47    * @param childBlocks the children of the header.
48    * @param level the level of the header
49    */
 
50  17 toggle public HeaderBlock(List<Block> childBlocks, HeaderLevel level)
51    {
52  17 super(childBlocks);
53   
54  17 this.level = level;
55    }
56   
57    /**
58    * @param childBlocks the children of the header.
59    * @param level the level of the header
60    * @param parameters the parameters of the header
61    */
 
62  941 toggle public HeaderBlock(List<Block> childBlocks, HeaderLevel level, Map<String, String> parameters)
63    {
64  941 super(childBlocks, parameters);
65   
66  941 this.level = level;
67    }
68   
69    /**
70    * @param childBlocks the children of the header.
71    * @param level the level of the header
72    * @param id the id of the header.
73    */
 
74  0 toggle public HeaderBlock(List<Block> childBlocks, HeaderLevel level, String id)
75    {
76  0 this(childBlocks, level);
77   
78  0 this.id = id;
79    }
80   
81    /**
82    * @param childBlocks the children of the header.
83    * @param level the level of the header
84    * @param parameters the parameters of the header
85    * @param id the id of the header.
86    */
 
87  941 toggle public HeaderBlock(List<Block> childBlocks, HeaderLevel level, Map<String, String> parameters, String id)
88    {
89  941 this(childBlocks, level, parameters);
90   
91  941 this.id = id;
92    }
93   
94    /**
95    * @return the level of the header
96    */
 
97  1573 toggle public HeaderLevel getLevel()
98    {
99  1573 return this.level;
100    }
101   
102    /**
103    * @return the id of the header.
104    */
 
105  1515 toggle public String getId()
106    {
107  1515 return this.id;
108    }
109   
110    /**
111    * @return the {@link SectionBlock} corresponding to this header
112    */
 
113  8 toggle public SectionBlock getSection()
114    {
115  8 return (SectionBlock) getParent();
116    }
117   
 
118  723 toggle @Override
119    public void before(Listener listener)
120    {
121  723 listener.beginHeader(getLevel(), getId(), getParameters());
122    }
123   
 
124  723 toggle @Override
125    public void after(Listener listener)
126    {
127  723 listener.endHeader(getLevel(), getId(), getParameters());
128    }
129   
 
130  4 toggle @Override
131    public boolean equals(Object obj)
132    {
133  4 if (obj == this) {
134  4 return true;
135    }
136   
137  0 if (obj instanceof HeaderBlock && super.equals(obj)) {
138  0 EqualsBuilder builder = new EqualsBuilder();
139   
140  0 builder.append(getLevel(), ((HeaderBlock) obj).getLevel());
141  0 builder.append(getId(), ((HeaderBlock) obj).getId());
142   
143  0 return builder.isEquals();
144    }
145   
146  0 return false;
147    }
148   
 
149  0 toggle @Override
150    public int hashCode()
151    {
152  0 HashCodeBuilder builder = new HashCodeBuilder();
153   
154  0 builder.appendSuper(super.hashCode());
155  0 builder.append(getLevel());
156  0 builder.append(getId());
157   
158  0 return builder.toHashCode();
159    }
160    }