| 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 |
|
|
| |
|
| 0% |
Uncovered Elements: 144 (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 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 3 |
|
| 51 |
0 |
public Pattern getNext()... |
| 52 |
|
{ |
| 53 |
0 |
return next != null ? next : (parent == null ? null : parent.getNext()); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 61 |
0 |
public void setParent(Pattern p)... |
| 62 |
|
{ |
| 63 |
0 |
if (next != null) |
| 64 |
|
{ |
| 65 |
0 |
next.setParent(p); |
| 66 |
|
} |
| 67 |
|
else |
| 68 |
|
{ |
| 69 |
0 |
parent = p; |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 78 |
0 |
public int nextMatch(int i, Pthings pt)... |
| 79 |
|
{ |
| 80 |
0 |
Pattern p = getNext(); |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
0 |
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 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 147 |
0 |
public int matchAt(StringLike s, int i, Pthings pt)... |
| 148 |
|
{ |
| 149 |
0 |
pt.src = s; |
| 150 |
0 |
int r = matchInternal(i, pt); |
| 151 |
0 |
if (r < 0) |
| 152 |
|
{ |
| 153 |
0 |
return -1; |
| 154 |
|
} |
| 155 |
0 |
mfrom = r < i ? r + 1 : i; |
| 156 |
0 |
return r < i ? i - r - 1 : r - i; |
| 157 |
|
} |
| 158 |
|
|
| 159 |
|
int mfrom = 0; |
| 160 |
|
|
| 161 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 162 |
0 |
final boolean Masked(int i, Pthings pt)... |
| 163 |
|
{ |
| 164 |
0 |
return pt.cbits == null ? false : pt.cbits.get(i); |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 168 |
0 |
public Pattern add(Pattern p)... |
| 169 |
|
{ |
| 170 |
0 |
if (next == null) |
| 171 |
|
{ |
| 172 |
0 |
if (p == null) |
| 173 |
|
{ |
| 174 |
0 |
return this; |
| 175 |
|
} |
| 176 |
0 |
next = p; |
| 177 |
0 |
p.parent = parent; |
| 178 |
0 |
parent = null; |
| 179 |
|
} |
| 180 |
|
else |
| 181 |
|
{ |
| 182 |
0 |
next.add(p); |
| 183 |
|
} |
| 184 |
0 |
return this; |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 190 |
0 |
public patInt minChars()... |
| 191 |
|
{ |
| 192 |
0 |
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 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 204 |
0 |
public final patInt countMinChars()... |
| 205 |
|
{ |
| 206 |
0 |
Pattern p = this; |
| 207 |
0 |
patInt sum = new patInt(0); |
| 208 |
0 |
while (p != null) |
| 209 |
|
{ |
| 210 |
0 |
sum.pluseq(p.minChars()); |
| 211 |
0 |
p = p.next; |
| 212 |
|
} |
| 213 |
0 |
return sum; |
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 217 |
0 |
public final patInt countMaxChars()... |
| 218 |
|
{ |
| 219 |
0 |
Pattern p = this; |
| 220 |
0 |
patInt sum = new patInt(0); |
| 221 |
0 |
while (p != null) |
| 222 |
|
{ |
| 223 |
0 |
sum.pluseq(p.maxChars()); |
| 224 |
0 |
p = p.next; |
| 225 |
|
} |
| 226 |
0 |
return sum; |
| 227 |
|
} |
| 228 |
|
|
| 229 |
|
|
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
| 234 |
|
|
| |
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
| 235 |
0 |
final int testMatch(Pattern p, int pos, Pthings pt)... |
| 236 |
|
{ |
| 237 |
0 |
int[] tab = null; |
| 238 |
0 |
if (pt.marks != null) |
| 239 |
|
{ |
| 240 |
0 |
try |
| 241 |
|
{ |
| 242 |
0 |
tab = new int[pt.marks.length]; |
| 243 |
0 |
for (int i = 0; i < tab.length; i++) |
| 244 |
|
{ |
| 245 |
0 |
tab[i] = pt.marks[i]; |
| 246 |
|
} |
| 247 |
|
} catch (Throwable t) |
| 248 |
|
{ |
| 249 |
|
} |
| 250 |
|
} |
| 251 |
0 |
int ret = p.matchInternal(pos, pt); |
| 252 |
0 |
if (ret < 0) |
| 253 |
|
{ |
| 254 |
0 |
pt.marks = tab; |
| 255 |
|
} |
| 256 |
0 |
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 |
|
|
| |
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
| 269 |
0 |
Pattern clone(Hashtable h)... |
| 270 |
|
{ |
| 271 |
0 |
Pattern p = (Pattern) h.get(this); |
| 272 |
0 |
if (p != null) |
| 273 |
|
{ |
| 274 |
0 |
return p; |
| 275 |
|
} |
| 276 |
0 |
p = clone1(h); |
| 277 |
0 |
if (p == null) |
| 278 |
|
{ |
| 279 |
0 |
throw new Error(MessageManager.getString("error.null_from_clone1")); |
| 280 |
|
} |
| 281 |
0 |
h.put(this, p); |
| 282 |
0 |
h.put(p, p); |
| 283 |
0 |
if (next != null) |
| 284 |
|
{ |
| 285 |
0 |
p.next = next.clone(h); |
| 286 |
|
} |
| 287 |
0 |
if (parent != null) |
| 288 |
|
{ |
| 289 |
0 |
p.parent = parent.clone(h); |
| 290 |
|
} |
| 291 |
0 |
return p; |
| 292 |
|
} |
| 293 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 294 |
0 |
public boolean equals(Object o)... |
| 295 |
|
{ |
| 296 |
0 |
return o == this; |
| 297 |
|
} |
| 298 |
|
}; |