class RegexUtils {

  public static Pattern globToPattern(String glob) {
    ArgumentChecker.notNull(glob, "glob");
    Map<Character, String> replacements = ImmutableMap.of('?', ".", '*', ".*?", '%', ".*?");
    StringBuilder builder = new StringBuilder();
    StringBuilder tokenBuilder = new StringBuilder();
    for (int i = 0; i < glob.length(); i++) {
      char c = glob.charAt(i);
      if (!replacements.containsKey(c)) {
        tokenBuilder.append(c);
      } else {
        if (tokenBuilder.length() != 0) {
          String quotedToken = Pattern.quote(tokenBuilder.toString());
          builder.append(quotedToken);
          tokenBuilder.setLength(0);
        }
        builder.append(replacements.get(c));
      }
    }
    if (tokenBuilder.length() != 0) {
      builder.append(Pattern.quote(tokenBuilder.toString()));
    }
    return Pattern.compile(builder.toString());
  }

  private  RegexUtils();

}