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

File ListBuilder2.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

10
31
12
2
146
92
18
0.58
2.58
6
1.5

Classes

Class Line # Actions
ListBuilder2 35 20 0% 12 34
0.00%
ListBuilder2.CharPos 37 11 0% 6 19
0.00%
 

Contributing tests

No tests hitting this source file were found.

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