@Test public void testMatch() { String s = "/time/;jsessionid=6E697A0D5DDDBC4F7206250E5E594305js/frame/menuModel.js"; assertTrue(PathPatternMatcher.match("*.js", s)); }
public static boolean match(String pattern, String str) { if (str.startsWith("/") != pattern.startsWith("/")) { return false; } List patDirs = tokenizePath(pattern); List strDirs = tokenizePath(str); int patIdxStart = 0; int patIdxEnd = patDirs.size() - 1; int strIdxStart = 0; int strIdxEnd = strDirs.size() - 1; while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxStart); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxStart))) { return false; } patIdxStart++; strIdxStart++; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } else { if (patIdxStart > patIdxEnd) { return false; } } while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxEnd); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxEnd))) { return false; } patIdxEnd--; strIdxEnd--; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { int patIdxTmp = -1; for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { if (patDirs.get(i).equals("**")) { patIdxTmp = i; break; } } if (patIdxTmp == patIdxStart + 1) { patIdxStart++; continue; } int patLength = patIdxTmp - patIdxStart - 1; int strLength = strIdxEnd - strIdxStart + 1; int foundIdx = -1; strLoop: for (int i = 0; i <= strLength - patLength; i++) { for (int j = 0; j < patLength; j++) { String subPat = (String) patDirs.get(patIdxStart + j + 1); String subStr = (String) strDirs.get(strIdxStart + i + j); if (!matchStrings(subPat, subStr)) { continue strLoop; } } foundIdx = strIdxStart + i; break; } if (foundIdx == -1) { return false; } patIdxStart = patIdxTmp; strIdxStart = foundIdx + patLength; } for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; }
PathPatternMatcher { public static boolean match(String pattern, String str) { if (str.startsWith("/") != pattern.startsWith("/")) { return false; } List patDirs = tokenizePath(pattern); List strDirs = tokenizePath(str); int patIdxStart = 0; int patIdxEnd = patDirs.size() - 1; int strIdxStart = 0; int strIdxEnd = strDirs.size() - 1; while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxStart); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxStart))) { return false; } patIdxStart++; strIdxStart++; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } else { if (patIdxStart > patIdxEnd) { return false; } } while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxEnd); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxEnd))) { return false; } patIdxEnd--; strIdxEnd--; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { int patIdxTmp = -1; for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { if (patDirs.get(i).equals("**")) { patIdxTmp = i; break; } } if (patIdxTmp == patIdxStart + 1) { patIdxStart++; continue; } int patLength = patIdxTmp - patIdxStart - 1; int strLength = strIdxEnd - strIdxStart + 1; int foundIdx = -1; strLoop: for (int i = 0; i <= strLength - patLength; i++) { for (int j = 0; j < patLength; j++) { String subPat = (String) patDirs.get(patIdxStart + j + 1); String subStr = (String) strDirs.get(strIdxStart + i + j); if (!matchStrings(subPat, subStr)) { continue strLoop; } } foundIdx = strIdxStart + i; break; } if (foundIdx == -1) { return false; } patIdxStart = patIdxTmp; strIdxStart = foundIdx + patLength; } for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } }
PathPatternMatcher { public static boolean match(String pattern, String str) { if (str.startsWith("/") != pattern.startsWith("/")) { return false; } List patDirs = tokenizePath(pattern); List strDirs = tokenizePath(str); int patIdxStart = 0; int patIdxEnd = patDirs.size() - 1; int strIdxStart = 0; int strIdxEnd = strDirs.size() - 1; while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxStart); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxStart))) { return false; } patIdxStart++; strIdxStart++; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } else { if (patIdxStart > patIdxEnd) { return false; } } while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxEnd); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxEnd))) { return false; } patIdxEnd--; strIdxEnd--; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { int patIdxTmp = -1; for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { if (patDirs.get(i).equals("**")) { patIdxTmp = i; break; } } if (patIdxTmp == patIdxStart + 1) { patIdxStart++; continue; } int patLength = patIdxTmp - patIdxStart - 1; int strLength = strIdxEnd - strIdxStart + 1; int foundIdx = -1; strLoop: for (int i = 0; i <= strLength - patLength; i++) { for (int j = 0; j < patLength; j++) { String subPat = (String) patDirs.get(patIdxStart + j + 1); String subStr = (String) strDirs.get(strIdxStart + i + j); if (!matchStrings(subPat, subStr)) { continue strLoop; } } foundIdx = strIdxStart + i; break; } if (foundIdx == -1) { return false; } patIdxStart = patIdxTmp; strIdxStart = foundIdx + patLength; } for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; }  }
PathPatternMatcher { public static boolean match(String pattern, String str) { if (str.startsWith("/") != pattern.startsWith("/")) { return false; } List patDirs = tokenizePath(pattern); List strDirs = tokenizePath(str); int patIdxStart = 0; int patIdxEnd = patDirs.size() - 1; int strIdxStart = 0; int strIdxEnd = strDirs.size() - 1; while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxStart); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxStart))) { return false; } patIdxStart++; strIdxStart++; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } else { if (patIdxStart > patIdxEnd) { return false; } } while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxEnd); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxEnd))) { return false; } patIdxEnd--; strIdxEnd--; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { int patIdxTmp = -1; for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { if (patDirs.get(i).equals("**")) { patIdxTmp = i; break; } } if (patIdxTmp == patIdxStart + 1) { patIdxStart++; continue; } int patLength = patIdxTmp - patIdxStart - 1; int strLength = strIdxEnd - strIdxStart + 1; int foundIdx = -1; strLoop: for (int i = 0; i <= strLength - patLength; i++) { for (int j = 0; j < patLength; j++) { String subPat = (String) patDirs.get(patIdxStart + j + 1); String subStr = (String) strDirs.get(strIdxStart + i + j); if (!matchStrings(subPat, subStr)) { continue strLoop; } } foundIdx = strIdxStart + i; break; } if (foundIdx == -1) { return false; } patIdxStart = patIdxTmp; strIdxStart = foundIdx + patLength; } for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; }  static boolean isPattern(String str); static boolean match(String pattern, String str); }
PathPatternMatcher { public static boolean match(String pattern, String str) { if (str.startsWith("/") != pattern.startsWith("/")) { return false; } List patDirs = tokenizePath(pattern); List strDirs = tokenizePath(str); int patIdxStart = 0; int patIdxEnd = patDirs.size() - 1; int strIdxStart = 0; int strIdxEnd = strDirs.size() - 1; while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxStart); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxStart))) { return false; } patIdxStart++; strIdxStart++; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } else { if (patIdxStart > patIdxEnd) { return false; } } while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { String patDir = (String) patDirs.get(patIdxEnd); if ("**".equals(patDir)) { break; } if (!matchStrings(patDir, (String) strDirs.get(strIdxEnd))) { return false; } patIdxEnd--; strIdxEnd--; } if (strIdxStart > strIdxEnd) { for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; } while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { int patIdxTmp = -1; for (int i = patIdxStart + 1; i <= patIdxEnd; i++) { if (patDirs.get(i).equals("**")) { patIdxTmp = i; break; } } if (patIdxTmp == patIdxStart + 1) { patIdxStart++; continue; } int patLength = patIdxTmp - patIdxStart - 1; int strLength = strIdxEnd - strIdxStart + 1; int foundIdx = -1; strLoop: for (int i = 0; i <= strLength - patLength; i++) { for (int j = 0; j < patLength; j++) { String subPat = (String) patDirs.get(patIdxStart + j + 1); String subStr = (String) strDirs.get(strIdxStart + i + j); if (!matchStrings(subPat, subStr)) { continue strLoop; } } foundIdx = strIdxStart + i; break; } if (foundIdx == -1) { return false; } patIdxStart = patIdxTmp; strIdxStart = foundIdx + patLength; } for (int i = patIdxStart; i <= patIdxEnd; i++) { if (!patDirs.get(i).equals("**")) { return false; } } return true; }  static boolean isPattern(String str); static boolean match(String pattern, String str);  }