| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
package com.stevesoft.pat; |
| 9 |
|
|
| 10 |
|
import java.util.Hashtable; |
| 11 |
|
import java.util.Vector; |
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| |
|
| 0% |
Uncovered Elements: 78 (78) |
Complexity: 20 |
Complexity Density: 0.42 |
|
| 18 |
|
class Or extends Pattern |
| 19 |
|
{ |
| 20 |
|
Vector v; |
| 21 |
|
|
| 22 |
|
Pattern[] pv = null; |
| 23 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 24 |
0 |
Or()... |
| 25 |
|
{ |
| 26 |
0 |
v = new Vector(); |
| 27 |
|
} |
| 28 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 29 |
0 |
String leftForm()... |
| 30 |
|
{ |
| 31 |
0 |
return "(?:"; |
| 32 |
|
} |
| 33 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 34 |
0 |
String rightForm()... |
| 35 |
|
{ |
| 36 |
0 |
return ")"; |
| 37 |
|
} |
| 38 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 39 |
0 |
String sepForm()... |
| 40 |
|
{ |
| 41 |
0 |
return "|"; |
| 42 |
|
} |
| 43 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 44 |
0 |
public Or addOr(Pattern p)... |
| 45 |
|
{ |
| 46 |
0 |
pv = null; |
| 47 |
0 |
v.addElement(p); |
| 48 |
0 |
p.setParent(this); |
| 49 |
0 |
return this; |
| 50 |
|
} |
| 51 |
|
|
| |
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 52 |
0 |
public String toString()... |
| 53 |
|
{ |
| 54 |
0 |
int i; |
| 55 |
0 |
StringBuffer sb = new StringBuffer(); |
| 56 |
0 |
sb.append(leftForm()); |
| 57 |
0 |
if (v.size() > 0) |
| 58 |
|
{ |
| 59 |
0 |
sb.append(((Pattern) v.elementAt(0)).toString()); |
| 60 |
|
} |
| 61 |
0 |
for (i = 1; i < v.size(); i++) |
| 62 |
|
{ |
| 63 |
0 |
sb.append(sepForm()); |
| 64 |
0 |
sb.append(((Pattern) v.elementAt(i)).toString()); |
| 65 |
|
} |
| 66 |
0 |
sb.append(rightForm()); |
| 67 |
0 |
sb.append(nextString()); |
| 68 |
0 |
return sb.toString(); |
| 69 |
|
} |
| 70 |
|
|
| |
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 71 |
0 |
public int matchInternal(int pos, Pthings pt)... |
| 72 |
|
{ |
| 73 |
0 |
if (pv == null) |
| 74 |
|
{ |
| 75 |
0 |
pv = new Pattern[v.size()]; |
| 76 |
0 |
v.copyInto(pv); |
| 77 |
|
} |
| 78 |
0 |
for (int i = 0; i < v.size(); i++) |
| 79 |
|
{ |
| 80 |
0 |
Pattern p = pv[i]; |
| 81 |
0 |
int r = p.matchInternal(pos, pt); |
| 82 |
0 |
if (r >= 0) |
| 83 |
|
{ |
| 84 |
0 |
return r; |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
0 |
return -1; |
| 88 |
|
} |
| 89 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 90 |
0 |
public patInt minChars()... |
| 91 |
|
{ |
| 92 |
0 |
if (v.size() == 0) |
| 93 |
|
{ |
| 94 |
0 |
return new patInt(0); |
| 95 |
|
} |
| 96 |
0 |
patInt m = ((Pattern) v.elementAt(0)).countMinChars(); |
| 97 |
0 |
for (int i = 1; i < v.size(); i++) |
| 98 |
|
{ |
| 99 |
0 |
Pattern p = (Pattern) v.elementAt(i); |
| 100 |
0 |
m.mineq(p.countMinChars()); |
| 101 |
|
} |
| 102 |
0 |
return m; |
| 103 |
|
} |
| 104 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 105 |
0 |
public patInt maxChars()... |
| 106 |
|
{ |
| 107 |
0 |
if (v.size() == 0) |
| 108 |
|
{ |
| 109 |
0 |
return new patInt(0); |
| 110 |
|
} |
| 111 |
0 |
patInt m = ((Pattern) v.elementAt(0)).countMaxChars(); |
| 112 |
0 |
for (int i = 1; i < v.size(); i++) |
| 113 |
|
{ |
| 114 |
0 |
Pattern p = (Pattern) v.elementAt(i); |
| 115 |
0 |
m.maxeq(p.countMaxChars()); |
| 116 |
|
} |
| 117 |
0 |
return m; |
| 118 |
|
} |
| 119 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 120 |
0 |
Pattern clone1(Hashtable h)... |
| 121 |
|
{ |
| 122 |
0 |
Or o = new Or(); |
| 123 |
0 |
h.put(this, o); |
| 124 |
0 |
h.put(o, o); |
| 125 |
0 |
for (int i = 0; i < v.size(); i++) |
| 126 |
|
{ |
| 127 |
0 |
o.v.addElement(((Pattern) v.elementAt(i)).clone(h)); |
| 128 |
|
} |
| 129 |
0 |
return o; |
| 130 |
|
} |
| 131 |
|
}; |