boolean (PrefixItem[] patDirs, String str) { final String[] strDirs = str.split(ourSeparatorPattern); int patIdxStart = 0; final int patIdxEnd = patDirs.length-1; int strIdxStart = 0; final int strIdxEnd = strDirs.length-1; // up to first '**' while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { final AntDomPattern.PrefixItem item = patDirs[patIdxStart]; if ("**".equals(item.getStrPattern())) { break; } if (!item.getPattern().matcher(strDirs[strIdxStart]).matches()) { return false; } patIdxStart++; strIdxStart++; } if (strIdxStart > strIdxEnd) { // String is exhausted return true; } if (patIdxStart > patIdxEnd) { // String not exhausted, but pattern is. Failure. return false; } // pattern now holds ** while string is not exhausted // this will generate false positives but we can live with that. return true; }