Subversion Repository Public Repository

litesoft

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.esotericsoftware.wildcard.support;

import com.esotericsoftware.wildcard.*;

public class WildMultiDirMatcher implements DirMatcher {
    private final FilePathPartMatcher[] mMatchers;
    private final boolean mFirstPartIsStarStar;
    private final int mMinimumParts;

    public WildMultiDirMatcher( String... zDirParts ) {
        int requiredParts = 0;
        mMatchers = new FilePathPartMatcher[zDirParts.length];
        for ( int i = 0; i < zDirParts.length; i++ ) {
            if ( !(mMatchers[i] = createMatcher( zDirParts[i] )).acceptsAnyNumberOfParts() ) {
                requiredParts++;
            }
        }
        mFirstPartIsStarStar = mMatchers[0].acceptsAnyNumberOfParts();
        mMinimumParts = requiredParts;
    }

    private FilePathPartMatcher createMatcher( String pPart ) {
        if ( "**".equals( pPart ) ) {
            return StarStarFilePathPartMatcher.INSTANCE;
        }
        if ( !pPart.contains( "*" ) && !pPart.contains( "?" ) ) {
            return new ExactFilePathPartMatcher( pPart );
        }
        return new WildCardPatternFilePathPartMatcher( pPart );
    }

    @Override
    public boolean acceptableParentDir( String dirPath ) {
        if ( !mFirstPartIsStarStar ) {
            String[] zDirParts = FilePathPartMatcher.SLASH.split( dirPath, 0 );
            for ( int i = 0; (i < zDirParts.length) && (i < mMatchers.length); i++ ) {
                FilePathPartMatcher zMatcher = mMatchers[i];
                if ( !zMatcher.acceptable( zDirParts[i] ) ) {
                    return false;
                }
                if ( zMatcher.acceptsAnyNumberOfParts() ) {
                    break;
                }
            }
        }
        return true;
    }

    @Override
    public boolean acceptable( String dirPath ) {
        String[] zDirParts = FilePathPartMatcher.SLASH.split( dirPath, 0 );
        return (zDirParts.length >= mMinimumParts) && checkAcceptable( 0, zDirParts, 0 );
    }

    private boolean checkAcceptable( int pMatcherIndex, String[] pDirParts, int pPartsIndex ) {
        while ( true ) {
            // Check: No Matcher & No Parts -> true, but No Matcher & Have Parts -> false
            boolean noParts = pDirParts.length <= pPartsIndex;
            if ( mMatchers.length <= pMatcherIndex ) // No Matcher!
            {
                return noParts; // No Parts!
            }
            FilePathPartMatcher zMatcher = mMatchers[pMatcherIndex];
            if ( zMatcher.acceptsAnyNumberOfParts() ) {
                // Check 0 parts match
                if ( checkAcceptable( pMatcherIndex + 1, pDirParts, pPartsIndex ) ) {
                    return true;
                }
                // Check n skipped parts
                for ( int i = pPartsIndex + 1; i <= pDirParts.length; i++ ) {
                    if ( checkAcceptable( pMatcherIndex + 1, pDirParts, i ) ) {
                        return true;
                    }
                }
            }
            if ( noParts || !zMatcher.acceptable( pDirParts[pPartsIndex] ) ) {
                return false;
            }
            pMatcherIndex++;
            pPartsIndex++;
        }
    }
}

Commits for litesoft/trunk/Java/ScarPlus/src/com/esotericsoftware/wildcard/support/WildMultiDirMatcher.java

Diff revisions: vs.
Revision Author Commited Message
959 Diff Diff GeorgeS picture GeorgeS Sat 19 Jul, 2014 15:27:50 +0000

Scar update

185 Diff Diff GeorgeS picture GeorgeS Sat 30 Apr, 2011 00:16:34 +0000
184 Diff Diff GeorgeS picture GeorgeS Tue 26 Apr, 2011 00:20:57 +0000
183 GeorgeS picture GeorgeS Mon 25 Apr, 2011 01:40:10 +0000