private boolean matchFilter(String string,String pattern){
  if (pattern.equals("*") || pattern.equals(string)) {
    return true;
  }
  int length=pattern.length();
  int wildCardIndex=pattern.indexOf("*");
  if (wildCardIndex >= 0) {
    String patternSubStr=pattern.substring(0,wildCardIndex);
    if (!string.startsWith(patternSubStr,0)) {
      return false;
    }
    int beginIndex=patternSubStr.length() + 1;
    int stringIndex=0;
    if (wildCardIndex > 0) {
      stringIndex=beginIndex;
    }
    String sub=pattern.substring(beginIndex,length);
    while ((wildCardIndex=pattern.indexOf("*",beginIndex)) != -1) {
      patternSubStr=pattern.substring(beginIndex,wildCardIndex);
      if (string.indexOf(patternSubStr,stringIndex) == -1) {
        return false;
      }
      beginIndex=wildCardIndex + 1;
      stringIndex=stringIndex + patternSubStr.length() + 1;
      sub=pattern.substring(beginIndex,length);
    }
    if (string.endsWith(sub)) {
      return true;
    }
  }
  return false;
}

private boolean matchFilter ( String string , String pattern ) { if ( pattern . equals ( "*" ) || pattern . equals ( string ) ) { return true ; } int length = pattern . length ( ) ; int wildCardIndex = pattern . indexOf ( "*" ) ; if ( wildCardIndex >= 0 ) { String patternSubStr = pattern . substring ( 0 , wildCardIndex ) ; if ( ! string . startsWith ( patternSubStr , 0 ) ) { return false ; } int beginIndex = patternSubStr . length ( ) + 1 ; int stringIndex = 0 ; if ( wildCardIndex > 0 ) { stringIndex = beginIndex ; } String sub = pattern . substring ( beginIndex , length ) ; while ( ( wildCardIndex = pattern . indexOf ( "*" , beginIndex ) ) != - 1 ) { patternSubStr = pattern . substring ( beginIndex , wildCardIndex ) ; if ( string . indexOf ( patternSubStr , stringIndex ) == - 1 ) { return false ; } beginIndex = wildCardIndex + 1 ; stringIndex = stringIndex + patternSubStr . length ( ) + 1 ; sub = pattern . substring ( beginIndex , length ) ; } if ( string . endsWith ( sub ) ) { return true ; } } return false ; }
returns true if the given pattern is contained in the string .
