FileDocCategorySizeDatePackage
WCMatcher.javaAPI DocAndroid 1.5 API11697Wed May 06 22:41:16 BST 2009com.vladium.util

WCMatcher

public abstract class WCMatcher extends Object
author
Vlad Roubtsov, (C) 2002

Fields Summary
private static final WCMatcher
ALL_MATCHER
private static final WCMatcher
EMPTY_MATCHER
Constructors Summary
WCMatcher()

Methods Summary
public static com.vladium.util.WCMatchercompile(java.lang.String pattern)

        if (pattern == null) throw new IllegalArgumentException ("null input: pattern");
        
        final char [] chars = pattern.toCharArray (); // is this faster than using charAt()?
        final int charsLength = chars.length;
        
        if (charsLength == 0)
            return EMPTY_MATCHER; // TODO: should be an EMPTY_MATCHER
        else
        {
            int patternLength = 0, starCount = 0, questionCount = 0;
            boolean star = false;
            
            for (int c = 0; c < charsLength; ++ c)
            {
                final char ch = chars [c];
                if (ch == '*")
                {
                    if (! star)
                    {
                        star = true;
                        ++ starCount; 
                        chars [patternLength ++] = '*";
                    }
                }
                else
                {
                    star = false;
                    if (ch == '?") ++ questionCount;
                    chars [patternLength ++] = ch;
                }
            }
            
            // [assertion: patternLength > 0]
            
            if ((starCount == 1) && (questionCount == 0))
            {
                if (patternLength == 1)
                    return ALL_MATCHER;
                else if (chars [0] == '*")
                    return new EndsWithMatcher (chars, patternLength);
                else if (chars [patternLength - 1] == '*")
                    return new StartsWithMatcher (chars, patternLength);
            }
            
            return new PatternMatcher (chars, patternLength);
        }
    
public abstract booleanmatches(java.lang.String s)

public abstract booleanmatches(char[] chars)