code: public static Object parsePattern(String pattern, boolean escaped, char escape) {
      char[] accum = new char[pattern.length()];
      int finger = 0;
      List tokens = new ArrayList();
      boolean trivial = true;
      for (int i = 0; i < pattern.length(); i++) {
        char c = pattern.charAt(i);
        if (c == sqlMatchOne) {
          finger = flush(accum, finger, tokens);
          tokens.add(matchOne);
          trivial = false;
        }
        else if (c == sqlMatchMany) {
          finger = flush(accum, finger, tokens);
          tokens.add(matchMany);
          trivial = false;
        }
        else if (escaped && c == escape)
          if (i == pattern.length()-1)
            return null;
          else {
            i++;
            accum[finger++] = pattern.charAt(i);
          }
        else
          accum[finger++] = c;
      }
      if (trivial)
        return new String(accum, 0, finger);
      flush(accum, finger, tokens);
      if (tokens.size() == 1 && tokens.get(0) == matchMany)
        return matchMany;
      return new Pattern(tokens.iterator());
    }
docs: Parse a string containing a SQL-style pattern
  @param pattern the string containing the pattern
  @param escaped true if the string employs an escape character
  @param escape the escape character (ignored if !escaped)
  @return an Object representing the result of the parse, as follows.
  <ul>
  <li>null if the pattern is syntactically invalid
  <li>the pattern as a string if the pattern contains no unescaped special characters
  and hence is better treated as an equality test.  Any escape chararacters will
  have been removed.
  <li>the matchMany object if the pattern will match any string at all.  This is
  better handled as a "NOT NULL" test.
  <li>the pattern as a Pattern object otherwise.
  </ul>