1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@version |
32 |
|
@since |
33 |
|
|
|
|
| 0% |
Uncovered Elements: 60 (60) |
Complexity: 18 |
Complexity Density: 0.51 |
|
34 |
|
public class ListBuilder1 |
35 |
|
{ |
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
36 |
|
private static class CharPos |
37 |
|
{ |
38 |
|
public final int pos; |
39 |
|
|
40 |
|
public final char rowChar; |
41 |
|
|
42 |
|
public final char treeChar; |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
44 |
0 |
public CharPos(char treeChar, char rowChar, int pos)... |
45 |
|
{ |
46 |
0 |
this.treeChar = treeChar; |
47 |
0 |
this.rowChar = rowChar; |
48 |
0 |
this.pos = pos; |
49 |
|
} |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
51 |
0 |
@Override... |
52 |
|
public boolean equals(Object obj) |
53 |
|
{ |
54 |
0 |
if (obj == this) { |
55 |
0 |
return true; |
56 |
|
} |
57 |
0 |
if (!(obj instanceof CharPos)) { |
58 |
0 |
return false; |
59 |
|
} |
60 |
0 |
CharPos p = (CharPos) obj; |
61 |
0 |
return p.pos == pos && p.treeChar == treeChar; |
62 |
|
} |
63 |
|
} |
64 |
|
|
65 |
|
private TreeBuilder1<CharPos> fBuilder = new TreeBuilder1<CharPos>( |
66 |
|
new TreeBuilder1.ITreeBuilderListener<CharPos>() |
67 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
0 |
public void beginItem(int depth, CharPos data)... |
69 |
|
{ |
70 |
0 |
fListener.beginRow(data.treeChar, data.rowChar); |
71 |
|
} |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
0 |
public void beginLevel(int depth, CharPos prev)... |
74 |
|
{ |
75 |
0 |
fListener.beginTree(prev.treeChar); |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
0 |
public void endItem(int depth, CharPos data)... |
79 |
|
{ |
80 |
0 |
fListener.endRow(data.treeChar, data.rowChar); |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0 |
public void endLevel(int i, CharPos prev)... |
84 |
|
{ |
85 |
0 |
fListener.endTree(prev.treeChar); |
86 |
|
} |
87 |
|
}); |
88 |
|
|
89 |
|
private IListListener fListener; |
90 |
|
|
91 |
|
private List<CharPos> fPrevRow; |
92 |
|
|
93 |
|
|
94 |
|
@param |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0 |
public ListBuilder1(IListListener listener)... |
97 |
|
{ |
98 |
0 |
fListener = listener; |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 6 |
Complexity Density: 0.38 |
|
104 |
0 |
public void alignContext(String row)... |
105 |
|
{ |
106 |
0 |
List<CharPos> list = getCharPositions(row); |
107 |
0 |
int prevLen = fPrevRow != null ? fPrevRow.size() : 0; |
108 |
0 |
int currentLen = list.size(); |
109 |
0 |
int len = Math.min(currentLen, prevLen); |
110 |
0 |
int i; |
111 |
0 |
for (i = 0; i < len - 1; i++) { |
112 |
0 |
CharPos prev = fPrevRow.get(i); |
113 |
0 |
CharPos second = list.get(i); |
114 |
0 |
if (!prev.equals(second)) { |
115 |
0 |
break; |
116 |
|
} |
117 |
|
} |
118 |
0 |
fBuilder.trim(i, true); |
119 |
0 |
if (i < currentLen) { |
120 |
0 |
for (; i < currentLen; i++) { |
121 |
0 |
CharPos p = list.get(i); |
122 |
0 |
fBuilder.align(p.pos, p); |
123 |
|
} |
124 |
|
} |
125 |
0 |
fPrevRow = list; |
126 |
|
} |
127 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
0 |
public void finish()... |
129 |
|
{ |
130 |
0 |
fBuilder.finish(); |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.42 |
|
133 |
0 |
private List<CharPos> getCharPositions(String s)... |
134 |
|
{ |
135 |
0 |
List<CharPos> list = new ArrayList<CharPos>(); |
136 |
0 |
char[] array = s.toCharArray(); |
137 |
0 |
int pos = 0; |
138 |
0 |
for (int i = 0; i < array.length; i++) { |
139 |
0 |
char ch = array[i]; |
140 |
0 |
if (ch == '\r' || ch == '\n') { |
141 |
0 |
continue; |
142 |
|
} |
143 |
0 |
if (!Character.isSpaceChar(ch)) { |
144 |
0 |
char treeChar = getTreeType(ch); |
145 |
0 |
list.add(new CharPos(treeChar, ch, pos)); |
146 |
|
} |
147 |
0 |
pos++; |
148 |
|
} |
149 |
0 |
return list; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
@param |
154 |
|
@return |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0 |
protected char getTreeType(char rowType)... |
157 |
|
{ |
158 |
0 |
return rowType; |
159 |
|
} |
160 |
|
} |