org.hackystat.sensorbase.uripattern
Class PatternMatcher

java.lang.Object
  extended by org.hackystat.sensorbase.uripattern.PatternMatcher

public class PatternMatcher
extends java.lang.Object

A utility class which does pattern matches.

Author:
Qin Zhang

Constructor Summary
PatternMatcher()
           
 
Method Summary
(package private) static boolean matchesFilePath(java.lang.String pattern, java.lang.String fileName, boolean isCaseSensitive)
          Determines whether a file name matches a pattern.
static boolean matchesPattern(java.lang.String pattern, java.lang.String str, boolean caseSensitive)
          Tests whether a string matches a pattern or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PatternMatcher

public PatternMatcher()
Method Detail

matchesFilePath

static boolean matchesFilePath(java.lang.String pattern,
                               java.lang.String fileName,
                               boolean isCaseSensitive)
Determines whether a file name matches a pattern. The pattern rule follows ant file set selections rules that is used in ant.

Some systems use slash, while others use back-slash as path separator. This function will not distinguish them (effectively,they are treated as the same character).

If a pattern ends with a path separator, then '**' will be append to it before matching. (i.e. if pattern is 'src/', then it will be treated as 'src/**'.

Parameters:
pattern - The pattern. If null, then the method will always return true.
fileName - The file name to be tested against the pattern.
isCaseSensitive - Whether fileName is case sensitive.
Returns:
True if the file name matches the pattern.

matchesPattern

public static boolean matchesPattern(java.lang.String pattern,
                                     java.lang.String str,
                                     boolean caseSensitive)
Tests whether a string matches a pattern or not. Wild characters are:

Note that this method is NOT designed to match file path, use matchesFilePath instead.

Parameters:
pattern - The pattern. If null, the function always returns true.
str - The string to be matched against the pattern.
caseSensitive - Whether the matches is case sensitive or not.
Returns:
True if string matches the pattern.