1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
package issrg.SAWS; |
47 |
|
|
48 |
|
import java.io.File; |
49 |
|
import java.io.FilenameFilter; |
50 |
|
import java.util.Vector; |
51 |
|
import java.util.StringTokenizer; |
52 |
|
|
|
|
| 67% |
Uncovered Elements: 34 (103) |
Complexity: 18 |
Complexity Density: 0.31 |
|
53 |
|
public class WildCardFilter implements FilenameFilter |
54 |
|
{ |
55 |
|
String wildPattern = null; |
56 |
|
Vector pattern = new Vector(); |
57 |
|
|
58 |
|
final String FIND = "find"; |
59 |
|
final String EXPECT = "expect"; |
60 |
|
final String ANYTHING = "anything"; |
61 |
|
final String NOTHING = "nothing"; |
62 |
|
|
|
|
| 80.6% |
Uncovered Elements: 6 (31) |
Complexity: 6 |
Complexity Density: 0.29 |
|
63 |
3
|
public WildCardFilter(String wildString)... |
64 |
|
{ |
65 |
3
|
wildPattern = wildString; |
66 |
|
|
67 |
3
|
wildString = wildString.toLowerCase(); |
68 |
|
|
69 |
3
|
int i = wildString.indexOf("**"); |
70 |
3
|
while ( i >= 0 ) |
71 |
|
{ |
72 |
0
|
wildString = wildString.substring(0, i+1) |
73 |
|
+ wildString.substring(i+2); |
74 |
|
|
75 |
0
|
i = wildString.indexOf("**"); |
76 |
|
} |
77 |
|
|
78 |
3
|
StringTokenizer tokens = new StringTokenizer(wildString, "*", true); |
79 |
3
|
String token = null; |
80 |
15
|
while (tokens.hasMoreTokens()) |
81 |
|
{ |
82 |
12
|
token = tokens.nextToken(); |
83 |
|
|
84 |
12
|
if (token.equals("*")) |
85 |
|
{ |
86 |
9
|
pattern.addElement(FIND); |
87 |
9
|
if (tokens.hasMoreTokens()) |
88 |
|
{ |
89 |
9
|
token = tokens.nextToken(); |
90 |
9
|
pattern.addElement(token); |
91 |
|
} |
92 |
|
else |
93 |
|
{ |
94 |
0
|
pattern.addElement(ANYTHING); |
95 |
|
} |
96 |
|
} |
97 |
|
else |
98 |
|
{ |
99 |
3
|
pattern.addElement(EXPECT); |
100 |
3
|
pattern.addElement(token); |
101 |
|
} |
102 |
|
} |
103 |
|
|
104 |
3
|
if ( !token.equals("*") ) |
105 |
|
{ |
106 |
3
|
pattern.addElement(EXPECT); |
107 |
3
|
pattern.addElement(NOTHING); |
108 |
|
} |
109 |
|
|
110 |
|
} |
111 |
|
|
112 |
|
|
|
|
| 76.4% |
Uncovered Elements: 13 (55) |
Complexity: 12 |
Complexity Density: 0.34 |
|
113 |
17
|
public boolean accept(File dir, String name)... |
114 |
|
{ |
115 |
17
|
String path = dir.getPath(); |
116 |
17
|
if ( !path.endsWith("/") && !path.endsWith("\\") ) |
117 |
|
{ |
118 |
17
|
path += File.separator; |
119 |
|
} |
120 |
17
|
File tempFile = new File(path, name); |
121 |
|
|
122 |
17
|
if ( tempFile.isDirectory() ) |
123 |
|
{ |
124 |
3
|
return true; |
125 |
|
} |
126 |
|
|
127 |
14
|
name = name.toLowerCase(); |
128 |
|
|
129 |
14
|
boolean acceptName = true; |
130 |
|
|
131 |
14
|
String command = null; |
132 |
14
|
String param = null; |
133 |
|
|
134 |
14
|
int currPos = 0; |
135 |
14
|
int cmdPos = 0; |
136 |
|
|
137 |
70
|
while ( cmdPos < pattern.size() ) |
138 |
|
{ |
139 |
70
|
command = (String) pattern.elementAt(cmdPos); |
140 |
70
|
param = (String) pattern.elementAt(cmdPos + 1); |
141 |
|
|
142 |
70
|
if ( command.equals(FIND) ) |
143 |
|
{ |
144 |
42
|
if ( param.equals(ANYTHING) ) |
145 |
|
{ |
146 |
0
|
break; |
147 |
|
} |
148 |
|
|
149 |
42
|
int nextPos = name.indexOf(param, currPos); |
150 |
42
|
if (nextPos >= 0) |
151 |
|
{ |
152 |
|
|
153 |
42
|
currPos = nextPos + param.length(); |
154 |
|
} |
155 |
|
else |
156 |
|
{ |
157 |
0
|
acceptName = false; |
158 |
0
|
break; |
159 |
|
} |
160 |
|
} |
161 |
|
else |
162 |
|
{ |
163 |
28
|
if ( command.equals(EXPECT) ) |
164 |
|
{ |
165 |
|
|
166 |
28
|
if ( param.equals(NOTHING) ) |
167 |
|
{ |
168 |
14
|
if ( currPos != name.length() ) |
169 |
|
{ |
170 |
0
|
acceptName = false; |
171 |
|
} |
172 |
|
|
173 |
14
|
break; |
174 |
|
} |
175 |
|
else |
176 |
|
{ |
177 |
14
|
int nextPos = name.indexOf(param, currPos); |
178 |
14
|
if ( nextPos != currPos ) |
179 |
|
{ |
180 |
0
|
acceptName = false; |
181 |
0
|
break; |
182 |
|
} |
183 |
|
|
184 |
14
|
currPos += param.length(); |
185 |
|
} |
186 |
|
} |
187 |
|
} |
188 |
|
|
189 |
56
|
cmdPos += 2; |
190 |
|
} |
191 |
|
|
192 |
14
|
return acceptName; |
193 |
|
} |
194 |
|
|
195 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
0
|
public String toString()... |
197 |
|
{ |
198 |
0
|
return wildPattern; |
199 |
|
} |
200 |
|
|
201 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
202 |
0
|
public String toPattern()... |
203 |
|
{ |
204 |
0
|
StringBuffer out = new StringBuffer(); |
205 |
|
|
206 |
0
|
int i=0; |
207 |
0
|
while (i<pattern.size()) |
208 |
|
{ |
209 |
0
|
out.append( "(" ); |
210 |
0
|
out.append( (String) pattern.elementAt(i) ); |
211 |
0
|
out.append( " " ); |
212 |
0
|
out.append( (String) pattern.elementAt(i+1) ); |
213 |
0
|
out.append( ") " ); |
214 |
|
|
215 |
0
|
i += 2; |
216 |
|
} |
217 |
|
|
218 |
0
|
return out.toString(); |
219 |
|
} |
220 |
|
} |
221 |
|
|
222 |
|
|