code: static String[] splitOnTokens(final String text) {
          // used by wildcardMatch
          // package level so a unit test may run on this
  
          if (text.indexOf('?') == NOT_FOUND && text.indexOf('*') == NOT_FOUND) {
              return new String[] { text };
          }
  
          final char[] array = text.toCharArray();
          final ArrayList<String> list = new ArrayList<String>();
          final StringBuilder buffer = new StringBuilder();
          char prevChar = 0;
          for (int i = 0; i < array.length; i++) {
              final char ch = array[i];
              if (ch == '?' || ch == '*') {
                  if (buffer.length() != 0) {
                      list.add(buffer.toString());
                      buffer.setLength(0);
                  }
                  if (ch == '?') {
                      list.add("?");
                  } else if (prevChar != '*') {// ch == '*' here; check if previous char was '*'
                      list.add("*");
                  }
              } else {
                  buffer.append(ch);
              }
              prevChar = ch;
          }
          if (buffer.length() != 0) {
              list.add(buffer.toString());
          }
  
          return list.toArray(new String[list.size()]);
      }
docs: Splits a string into a number of tokens.
  The text is split by '?' and '*'.
  Where multiple '*' occur consecutively they are collapsed into a single '*'.
  
  @param text  the text to split
  @return the array of tokens, never null