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

File ListBuilder.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

10
31
12
2
140
90
18
0.58
2.58
6
1.5

Classes

Class Line # Actions
ListBuilder 32 20 0% 12 2
0.941176594.1%
ListBuilder.CharPos 34 11 0% 6 11
0.4210526342.1%
 

Contributing tests

This file is covered by 190 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.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: d40a614fa3c14d34a47662702cd141ce395ccfc3 $
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  11650 toggle public CharPos(char treeChar, char rowChar, int pos)
43    {
44  11650 fPos = pos;
45  11650 fTreeChar = treeChar;
46  11650 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  8783 toggle public boolean equalsData(CharPos pos)
63    {
64  8783 return pos.fTreeChar == fTreeChar;
65    }
66   
 
67  17714 toggle public int getPos()
68    {
69  17714 return fPos;
70    }
71    }
72   
73    TreeBuilder<CharPos> fBuilder = new TreeBuilder<CharPos>(
74    new TreeBuilder.ITreeListener<CharPos>()
75    {
 
76  6874 toggle public void onBeginRow(CharPos pos)
77    {
78  6874 fListener.beginRow(pos.fTreeChar, pos.fRowChar);
79    }
80   
 
81  2887 toggle public void onBeginTree(CharPos pos)
82    {
83  2887 fListener.beginTree(pos.fTreeChar);
84    }
85   
 
86  6874 toggle public void onEndRow(CharPos pos)
87    {
88  6874 fListener.endRow(pos.fTreeChar, pos.fRowChar);
89    }
90   
 
91  2887 toggle public void onEndTree(CharPos pos)
92    {
93  2887 fListener.endTree(pos.fTreeChar);
94    }
95    });
96   
97    private IListListener fListener;
98   
 
99  1046 toggle public ListBuilder(IListListener listener)
100    {
101  1046 fListener = listener;
102    }
103   
104    /**
105    * @param row the parameters of the row
106    */
 
107  7886 toggle public void alignContext(String row)
108    {
109  7886 List<CharPos> list = getCharPositions(row);
110  7886 fBuilder.align(list);
111    }
112   
 
113  7886 toggle private List<CharPos> getCharPositions(String s)
114    {
115  7886 List<CharPos> list = new ArrayList<CharPos>();
116  7886 char[] array = s.toCharArray();
117  7886 int pos = 0;
118  19970 for (int i = 0; i < array.length; i++) {
119  12084 char ch = array[i];
120  12084 if (ch == '\r' || ch == '\n') {
121  0 continue;
122    }
123  12084 if (!Character.isSpaceChar(ch)) {
124  11650 char treeChar = getTreeType(ch);
125  11650 list.add(new CharPos(treeChar, ch, pos));
126    }
127  12084 pos++;
128    }
129  7886 return list;
130    }
131   
132    /**
133    * @param rowType the type of the row
134    * @return the type of the tree corresponding to the given row type
135    */
 
136  207 toggle protected char getTreeType(char rowType)
137    {
138  207 return rowType;
139    }
140    }