public static String optimizeDirPattern(String dirPattern) {
    if (!dirPattern.startsWith("/")) {
      dirPattern = "/" + dirPattern;
    }
    //now dirPattern starts and ends with '/'

    dirPattern = normalizeWildcards(dirPattern);

    dirPattern = StringUtil.replace(dirPattern, "/.*.*/", "(/.*)?/");
    dirPattern = StringUtil.trimEnd(dirPattern, "/");

    dirPattern = optimize(dirPattern);
    return dirPattern;
  }
public static String optimizeDirPattern(String dirPattern)