|
@@ -2,20 +2,16 @@ |
2 |
2 |
|
|
3 |
3 |
|
import com.esotericsoftware.wildcard.*; |
4 |
4 |
|
|
5 |
|
- |
public class WildMultiDirMatcher implements DirMatcher |
6 |
|
- |
{ |
|
5 |
+ |
public class WildMultiDirMatcher implements DirMatcher { |
7 |
6 |
|
private final FilePathPartMatcher[] mMatchers; |
8 |
7 |
|
private final boolean mFirstPartIsStarStar; |
9 |
8 |
|
private final int mMinimumParts; |
10 |
9 |
|
|
11 |
|
- |
public WildMultiDirMatcher( String... zDirParts ) |
12 |
|
- |
{ |
|
10 |
+ |
public WildMultiDirMatcher( String... zDirParts ) { |
13 |
11 |
|
int requiredParts = 0; |
14 |
12 |
|
mMatchers = new FilePathPartMatcher[zDirParts.length]; |
15 |
|
- |
for ( int i = 0; i < zDirParts.length; i++ ) |
16 |
|
- |
{ |
17 |
|
- |
if ( !(mMatchers[i] = createMatcher( zDirParts[i] )).acceptsAnyNumberOfParts() ) |
18 |
|
- |
{ |
|
13 |
+ |
for ( int i = 0; i < zDirParts.length; i++ ) { |
|
14 |
+ |
if ( !(mMatchers[i] = createMatcher( zDirParts[i] )).acceptsAnyNumberOfParts() ) { |
19 |
15 |
|
requiredParts++; |
20 |
16 |
|
} |
21 |
17 |
|
} |
|
@@ -23,34 +19,26 @@ |
23 |
19 |
|
mMinimumParts = requiredParts; |
24 |
20 |
|
} |
25 |
21 |
|
|
26 |
|
- |
private FilePathPartMatcher createMatcher( String pPart ) |
27 |
|
- |
{ |
28 |
|
- |
if ( "**".equals( pPart ) ) |
29 |
|
- |
{ |
|
22 |
+ |
private FilePathPartMatcher createMatcher( String pPart ) { |
|
23 |
+ |
if ( "**".equals( pPart ) ) { |
30 |
24 |
|
return StarStarFilePathPartMatcher.INSTANCE; |
31 |
25 |
|
} |
32 |
|
- |
if ( !pPart.contains( "*" ) && !pPart.contains( "?" ) ) |
33 |
|
- |
{ |
|
26 |
+ |
if ( !pPart.contains( "*" ) && !pPart.contains( "?" ) ) { |
34 |
27 |
|
return new ExactFilePathPartMatcher( pPart ); |
35 |
28 |
|
} |
36 |
29 |
|
return new WildCardPatternFilePathPartMatcher( pPart ); |
37 |
30 |
|
} |
38 |
31 |
|
|
39 |
32 |
|
@Override |
40 |
|
- |
public boolean acceptableParentDir( String dirPath ) |
41 |
|
- |
{ |
42 |
|
- |
if ( !mFirstPartIsStarStar ) |
43 |
|
- |
{ |
|
33 |
+ |
public boolean acceptableParentDir( String dirPath ) { |
|
34 |
+ |
if ( !mFirstPartIsStarStar ) { |
44 |
35 |
|
String[] zDirParts = FilePathPartMatcher.SLASH.split( dirPath, 0 ); |
45 |
|
- |
for ( int i = 0; (i < zDirParts.length) && (i < mMatchers.length); i++ ) |
46 |
|
- |
{ |
|
36 |
+ |
for ( int i = 0; (i < zDirParts.length) && (i < mMatchers.length); i++ ) { |
47 |
37 |
|
FilePathPartMatcher zMatcher = mMatchers[i]; |
48 |
|
- |
if ( !zMatcher.acceptable( zDirParts[i] ) ) |
49 |
|
- |
{ |
|
38 |
+ |
if ( !zMatcher.acceptable( zDirParts[i] ) ) { |
50 |
39 |
|
return false; |
51 |
40 |
|
} |
52 |
|
- |
if ( zMatcher.acceptsAnyNumberOfParts() ) |
53 |
|
- |
{ |
|
41 |
+ |
if ( zMatcher.acceptsAnyNumberOfParts() ) { |
54 |
42 |
|
break; |
55 |
43 |
|
} |
56 |
44 |
|
} |
|
@@ -59,16 +47,13 @@ |
59 |
47 |
|
} |
60 |
48 |
|
|
61 |
49 |
|
@Override |
62 |
|
- |
public boolean acceptable( String dirPath ) |
63 |
|
- |
{ |
|
50 |
+ |
public boolean acceptable( String dirPath ) { |
64 |
51 |
|
String[] zDirParts = FilePathPartMatcher.SLASH.split( dirPath, 0 ); |
65 |
52 |
|
return (zDirParts.length >= mMinimumParts) && checkAcceptable( 0, zDirParts, 0 ); |
66 |
53 |
|
} |
67 |
54 |
|
|
68 |
|
- |
private boolean checkAcceptable( int pMatcherIndex, String[] pDirParts, int pPartsIndex ) |
69 |
|
- |
{ |
70 |
|
- |
while ( true ) |
71 |
|
- |
{ |
|
55 |
+ |
private boolean checkAcceptable( int pMatcherIndex, String[] pDirParts, int pPartsIndex ) { |
|
56 |
+ |
while ( true ) { |
72 |
57 |
|
// Check: No Matcher & No Parts -> true, but No Matcher & Have Parts -> false |
73 |
58 |
|
boolean noParts = pDirParts.length <= pPartsIndex; |
74 |
59 |
|
if ( mMatchers.length <= pMatcherIndex ) // No Matcher! |
|
@@ -76,24 +61,19 @@ |
76 |
61 |
|
return noParts; // No Parts! |
77 |
62 |
|
} |
78 |
63 |
|
FilePathPartMatcher zMatcher = mMatchers[pMatcherIndex]; |
79 |
|
- |
if ( zMatcher.acceptsAnyNumberOfParts() ) |
80 |
|
- |
{ |
|
64 |
+ |
if ( zMatcher.acceptsAnyNumberOfParts() ) { |
81 |
65 |
|
// Check 0 parts match |
82 |
|
- |
if ( checkAcceptable( pMatcherIndex + 1, pDirParts, pPartsIndex ) ) |
83 |
|
- |
{ |
|
66 |
+ |
if ( checkAcceptable( pMatcherIndex + 1, pDirParts, pPartsIndex ) ) { |
84 |
67 |
|
return true; |
85 |
68 |
|
} |
86 |
69 |
|
// Check n skipped parts |
87 |
|
- |
for ( int i = pPartsIndex + 1; i <= pDirParts.length; i++ ) |
88 |
|
- |
{ |
89 |
|
- |
if ( checkAcceptable( pMatcherIndex + 1, pDirParts, i ) ) |
90 |
|
- |
{ |
|
70 |
+ |
for ( int i = pPartsIndex + 1; i <= pDirParts.length; i++ ) { |
|
71 |
+ |
if ( checkAcceptable( pMatcherIndex + 1, pDirParts, i ) ) { |
91 |
72 |
|
return true; |
92 |
73 |
|
} |
93 |
74 |
|
} |
94 |
75 |
|
} |
95 |
|
- |
if ( noParts || !zMatcher.acceptable( pDirParts[pPartsIndex] ) ) |
96 |
|
- |
{ |
|
76 |
+ |
if ( noParts || !zMatcher.acceptable( pDirParts[pPartsIndex] ) ) { |
97 |
77 |
|
return false; |
98 |
78 |
|
} |
99 |
79 |
|
pMatcherIndex++; |