1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
package com.stevesoft.pat; |
9 |
|
|
10 |
|
import jalview.util.MessageManager; |
11 |
|
|
12 |
|
import java.util.Hashtable; |
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
|
|
| 71.5% |
Uncovered Elements: 41 (144) |
Complexity: 43 |
Complexity Density: 0.55 |
|
23 |
|
public abstract class Pattern |
24 |
|
{ |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
public final static char ESC = '\\'; |
30 |
|
|
31 |
|
final static String PROTECT_THESE = "[]{}(),$,-\"^."; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
public abstract int matchInternal(int i, Pthings p); |
38 |
|
|
39 |
|
public abstract String toString(); |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
Pattern next = null, parent = null; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 3 |
|
51 |
315895 |
public Pattern getNext()... |
52 |
|
{ |
53 |
250753 |
return next != null ? next : (parent == null ? null : parent.getNext()); |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
61 |
10566 |
public void setParent(Pattern p)... |
62 |
|
{ |
63 |
10566 |
if (next != null) |
64 |
|
{ |
65 |
569 |
next.setParent(p); |
66 |
|
} |
67 |
|
else |
68 |
|
{ |
69 |
9997 |
parent = p; |
70 |
|
} |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
78 |
299942 |
public int nextMatch(int i, Pthings pt)... |
79 |
|
{ |
80 |
299942 |
Pattern p = getNext(); |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
299942 |
return p == null ? i : p.matchInternal(i, pt); |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
91 |
0 |
public String nextString()... |
92 |
|
{ |
93 |
0 |
if (next == null) |
94 |
|
{ |
95 |
0 |
return ""; |
96 |
|
} |
97 |
0 |
return next.toString(); |
98 |
|
} |
99 |
|
|
100 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
101 |
0 |
final static boolean inString(char c, String s)... |
102 |
|
{ |
103 |
0 |
int i; |
104 |
0 |
for (i = 0; i < s.length(); i++) |
105 |
|
{ |
106 |
0 |
if (s.charAt(i) == c) |
107 |
|
{ |
108 |
0 |
return true; |
109 |
|
} |
110 |
|
} |
111 |
0 |
return false; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
119 |
0 |
final static String protect(String s, String PROTECT_THESE, char esc)... |
120 |
|
{ |
121 |
0 |
int i; |
122 |
0 |
StringBuffer sb = new StringBuffer(); |
123 |
0 |
String p = PROTECT_THESE + esc; |
124 |
0 |
for (i = 0; i < s.length(); i++) |
125 |
|
{ |
126 |
0 |
char c = s.charAt(i); |
127 |
0 |
if (inString(c, p)) |
128 |
|
{ |
129 |
0 |
sb.append(esc); |
130 |
|
} |
131 |
0 |
sb.append(c); |
132 |
|
} |
133 |
0 |
return sb.toString(); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
0 |
public int match(StringLike s, Pthings pt)... |
140 |
|
{ |
141 |
0 |
return matchAt(s, 0, pt); |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
147 |
340991 |
public int matchAt(StringLike s, int i, Pthings pt)... |
148 |
|
{ |
149 |
340991 |
pt.src = s; |
150 |
340991 |
int r = matchInternal(i, pt); |
151 |
340991 |
if (r < 0) |
152 |
|
{ |
153 |
336109 |
return -1; |
154 |
|
} |
155 |
4882 |
mfrom = r < i ? r + 1 : i; |
156 |
4882 |
return r < i ? i - r - 1 : r - i; |
157 |
|
} |
158 |
|
|
159 |
|
int mfrom = 0; |
160 |
|
|
161 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
162 |
412610 |
final boolean Masked(int i, Pthings pt)... |
163 |
|
{ |
164 |
412610 |
return pt.cbits == null ? false : pt.cbits.get(i); |
165 |
|
} |
166 |
|
|
167 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
168 |
10129 |
public Pattern add(Pattern p)... |
169 |
|
{ |
170 |
10129 |
if (next == null) |
171 |
|
{ |
172 |
3081 |
if (p == null) |
173 |
|
{ |
174 |
1 |
return this; |
175 |
|
} |
176 |
3080 |
next = p; |
177 |
3080 |
p.parent = parent; |
178 |
3080 |
parent = null; |
179 |
|
} |
180 |
|
else |
181 |
|
{ |
182 |
7048 |
next.add(p); |
183 |
|
} |
184 |
10128 |
return this; |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
190 |
471 |
public patInt minChars()... |
191 |
|
{ |
192 |
471 |
return new patInt(0); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
0 |
public patInt maxChars()... |
199 |
|
{ |
200 |
0 |
return new patInf(); |
201 |
|
} |
202 |
|
|
203 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
204 |
3047 |
public final patInt countMinChars()... |
205 |
|
{ |
206 |
3047 |
Pattern p = this; |
207 |
3047 |
patInt sum = new patInt(0); |
208 |
6096 |
while (p != null) |
209 |
|
{ |
210 |
3049 |
sum.pluseq(p.minChars()); |
211 |
3049 |
p = p.next; |
212 |
|
} |
213 |
3047 |
return sum; |
214 |
|
} |
215 |
|
|
216 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
217 |
576 |
public final patInt countMaxChars()... |
218 |
|
{ |
219 |
576 |
Pattern p = this; |
220 |
576 |
patInt sum = new patInt(0); |
221 |
1154 |
while (p != null) |
222 |
|
{ |
223 |
578 |
sum.pluseq(p.maxChars()); |
224 |
578 |
p = p.next; |
225 |
|
} |
226 |
576 |
return sum; |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
235 |
358 |
final int testMatch(Pattern p, int pos, Pthings pt)... |
236 |
|
{ |
237 |
358 |
int[] tab = null; |
238 |
358 |
if (pt.marks != null) |
239 |
|
{ |
240 |
350 |
try |
241 |
|
{ |
242 |
350 |
tab = new int[pt.marks.length]; |
243 |
1750 |
for (int i = 0; i < tab.length; i++) |
244 |
|
{ |
245 |
1400 |
tab[i] = pt.marks[i]; |
246 |
|
} |
247 |
|
} catch (Throwable t) |
248 |
|
{ |
249 |
|
} |
250 |
|
} |
251 |
358 |
int ret = p.matchInternal(pos, pt); |
252 |
358 |
if (ret < 0) |
253 |
|
{ |
254 |
8 |
pt.marks = tab; |
255 |
|
} |
256 |
358 |
return ret; |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
262 |
0 |
Pattern clone1(Hashtable h)... |
263 |
|
{ |
264 |
0 |
throw new Error(MessageManager.formatMessage( |
265 |
|
"error.no_such_method_as_clone1_for", new String[] |
266 |
|
{ getClass().getName() })); |
267 |
|
} |
268 |
|
|
|
|
| 90.5% |
Uncovered Elements: 2 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
269 |
7638 |
Pattern clone(Hashtable h)... |
270 |
|
{ |
271 |
7638 |
Pattern p = (Pattern) h.get(this); |
272 |
7638 |
if (p != null) |
273 |
|
{ |
274 |
2948 |
return p; |
275 |
|
} |
276 |
4690 |
p = clone1(h); |
277 |
4690 |
if (p == null) |
278 |
|
{ |
279 |
0 |
throw new Error(MessageManager.getString("error.null_from_clone1")); |
280 |
|
} |
281 |
4690 |
h.put(this, p); |
282 |
4690 |
h.put(p, p); |
283 |
4690 |
if (next != null) |
284 |
|
{ |
285 |
670 |
p.next = next.clone(h); |
286 |
|
} |
287 |
4690 |
if (parent != null) |
288 |
|
{ |
289 |
2948 |
p.parent = parent.clone(h); |
290 |
|
} |
291 |
4690 |
return p; |
292 |
|
} |
293 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
294 |
6700 |
public boolean equals(Object o)... |
295 |
|
{ |
296 |
6700 |
return o == this; |
297 |
|
} |
298 |
|
}; |