Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../img/srcFileCovDistChart8.png 68% of files have more coverage
31   143   18   2.58
10   90   0.58   6
12     1.5  
2    
 
  ListBuilder       Line # 32 20 0% 12 2 94.1% 0.9411765
  ListBuilder.CharPos       Line # 34 11 0% 6 11 42.1% 0.42105263
 
  (130)
 
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.wikimodel.util;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    /**
26    * This is an internal utility class used as a context to keep in memory the
27    * current state of parsed trees (list items).
28    *
29    * @version $Id: 906ec846fe9a9b48d33d17bf4c1f6965c4680cb3 $
30    * @since 4.0M1
31    */
 
32    public class ListBuilder
33    {
 
34    static class CharPos implements TreeBuilder.IPos<CharPos>
35    {
36    private int fPos;
37   
38    private char fRowChar;
39   
40    private char fTreeChar;
41   
 
42  1197 toggle public CharPos(char treeChar, char rowChar, int pos)
43    {
44  1197 fPos = pos;
45  1197 fTreeChar = treeChar;
46  1197 fRowChar = rowChar;
47    }
48   
 
49  0 toggle @Override
50    public boolean equals(Object obj)
51    {
52  0 if (obj == this) {
53  0 return true;
54    }
55  0 if (!(obj instanceof CharPos)) {
56  0 return false;
57    }
58  0 CharPos pos = (CharPos) obj;
59  0 return equalsData(pos) && pos.fPos == fPos;
60    }
61   
 
62  575 toggle public boolean equalsData(CharPos pos)
63    {
64  575 return pos.fTreeChar == fTreeChar;
65    }
66   
 
67  1294 toggle public int getPos()
68    {
69  1294 return fPos;
70    }
71    }
72   
73    TreeBuilder<CharPos> fBuilder = new TreeBuilder<CharPos>(
74    new TreeBuilder.ITreeListener<CharPos>()
75    {
 
76  930 toggle public void onBeginRow(CharPos pos)
77    {
78  930 fListener.beginRow(pos.fTreeChar, pos.fRowChar);
79    }
80   
 
81  652 toggle public void onBeginTree(CharPos pos)
82    {
83  652 fListener.beginTree(pos.fTreeChar);
84    }
85   
 
86  930 toggle public void onEndRow(CharPos pos)
87    {
88  930 fListener.endRow(pos.fTreeChar, pos.fRowChar);
89    }
90   
 
91  652 toggle public void onEndTree(CharPos pos)
92    {
93  652 fListener.endTree(pos.fTreeChar);
94    }
95    });
96   
97    private IListListener fListener;
98   
99    /**
100    * @param listener
101    */
 
102  399 toggle public ListBuilder(IListListener listener)
103    {
104  399 fListener = listener;
105    }
106   
107    /**
108    * @param rowParams the parameters of the row
109    */
 
110  1290 toggle public void alignContext(String row)
111    {
112  1290 List<CharPos> list = getCharPositions(row);
113  1290 fBuilder.align(list);
114    }
115   
 
116  1290 toggle private List<CharPos> getCharPositions(String s)
117    {
118  1290 List<CharPos> list = new ArrayList<CharPos>();
119  1290 char[] array = s.toCharArray();
120  1290 int pos = 0;
121  2929 for (int i = 0; i < array.length; i++) {
122  1639 char ch = array[i];
123  1639 if (ch == '\r' || ch == '\n') {
124  0 continue;
125    }
126  1639 if (!Character.isSpaceChar(ch)) {
127  1197 char treeChar = getTreeType(ch);
128  1197 list.add(new CharPos(treeChar, ch, pos));
129    }
130  1639 pos++;
131    }
132  1290 return list;
133    }
134   
135    /**
136    * @param rowType the type of the row
137    * @return the type of the tree corresponding to the given row type
138    */
 
139  217 toggle protected char getTreeType(char rowType)
140    {
141  217 return rowType;
142    }
143    }