protected static boolean matchTokens ( String [ ] tokens , String [ ] patterns ) { int patNdxStart = 0 ; int patNdxEnd = patterns . length - 1 ; int tokNdxStart = 0 ; int tokNdxEnd = tokens . length - 1 ; while ( patNdxStart <= patNdxEnd && tokNdxStart <= tokNdxEnd ) { // find first ** String patDir = patterns [ patNdxStart ] ; if ( patDir . equals ( PATH_MATCH ) ) { break ; } if ( ! WildcharUtils . match ( tokens [ tokNdxStart ] , patDir ) ) { return false ; } patNdxStart ++ ; tokNdxStart ++ ; } if ( tokNdxStart > tokNdxEnd ) { for ( int i = patNdxStart ; i <= patNdxEnd ; i ++ ) { // string is finished if ( ! patterns [ i ] . equals ( PATH_MATCH ) ) { return false ; } } return true ; } if ( patNdxStart > patNdxEnd ) { return false ; // string is not finished, but pattern is } while ( patNdxStart <= patNdxEnd && tokNdxStart <= tokNdxEnd ) { // to the last ** String patDir = patterns [ patNdxEnd ] ; if ( patDir . equals ( PATH_MATCH ) ) { break ; } if ( ! WildcharUtils . match ( tokens [ tokNdxEnd ] , patDir ) ) { return false ; } patNdxEnd -- ; tokNdxEnd -- ; } if ( tokNdxStart > tokNdxEnd ) { for ( int i = patNdxStart ; i <= patNdxEnd ; i ++ ) { // string is finished if ( ! patterns [ i ] . equals ( PATH_MATCH ) ) { return false ; } } return true ; } while ( ( patNdxStart != patNdxEnd ) && ( tokNdxStart <= tokNdxEnd ) ) { int patIdxTmp = - 1 ; for ( int i = patNdxStart + 1 ; i <= patNdxEnd ; i ++ ) { if ( patterns [ i ] . equals ( PATH_MATCH ) ) { patIdxTmp = i ; break ; } } if ( patIdxTmp == patNdxStart + 1 ) { patNdxStart ++ ; // skip **/** situation continue ; } // find the pattern between padIdxStart & padIdxTmp in str between strIdxStart & strIdxEnd int patLength = ( patIdxTmp - patNdxStart - 1 ) ; int strLength = ( tokNdxEnd - tokNdxStart + 1 ) ; int ndx = - 1 ; strLoop : for ( int i = 0 ; i <= strLength - patLength ; i ++ ) { for ( int j = 0 ; j < patLength ; j ++ ) { String subPat = patterns [ patNdxStart + j + 1 ] ; String subStr = tokens [ tokNdxStart + i + j ] ; if ( ! WildcharUtils . match ( subStr , subPat ) ) { continue strLoop ; } } ndx = tokNdxStart + i ; break ; } if ( ndx == - 1 ) { return false ; } patNdxStart = patIdxTmp ; tokNdxStart = ndx + patLength ; } for ( int i = patNdxStart ; i <= patNdxEnd ; i ++ ) { if ( ! patterns [ i ] . equals ( PATH_MATCH ) ) { return false ; } } return true ; }
Match tokenized string and pattern .