Tokenize a given string assuming it is like a URL.

@param s the string to be parsed as a wildcard-able URI
@return the array of tokens of URI parts.
@throws IllegalArgumentException when the string cannot be parsed as a wildcard-able URI
181231
List<Token<UriElement>> tokenize(String s) throws IllegalArgumentException {
        if (s == null || s.length() == 0) {
            return new ArrayList<Token<UriElement>>();
        }

        //
        // Make sure if a scheme is not specified, we default one before we parse as a URI.
        //
        if ( !SCHEME_URI_PATTERN.matcher(s).matches()) {
            s = ("http://")+s;
        }

        //
        // Parse as a URI
        //
        URI uri = URI.create(s);

        //
        // Detect what the scheme is, if any.
        //
        List<Token<UriElement>> result = new ArrayList<Token<UriElement>>(10);
        String scheme = "http";
        if (uri.getScheme() != null) {
            scheme = uri.getScheme();
        }


        //
        // A wildcard-ed hostname is parsed as an authority.
        //
        String host = uri.getHost();
        String parsedPortFromAuthority = null;
        String parsedUserInfoFromAuthority = null;
        String userFromAuthority = null;
        String passwordFromAuthority = null;
        if (host == null) {
            String authority = uri.getAuthority();
            if (authority != null) {
                host = authority;
                int asteriskIdx = host.indexOf("@");
                if ( asteriskIdx >= 0) {
                    parsedUserInfoFromAuthority = host.substring(0, asteriskIdx);
                    host = host.substring(asteriskIdx+1);
                    int colonIdx = parsedUserInfoFromAuthority.indexOf(":");
                    if ( colonIdx >= 0) {
                        userFromAuthority = parsedUserInfoFromAuthority.substring(0, colonIdx);
                        passwordFromAuthority = parsedUserInfoFromAuthority.substring(colonIdx+1);
                    }
                }
                int colonIdx = host.indexOf(":");
                if ( colonIdx >=0 ) {
                    parsedPortFromAuthority = host.substring(colonIdx + 1);
                    host = host.substring(0, colonIdx);
                }
            } else {
                throw new IllegalArgumentException("Hostname is required.");
            }
        }

        //
        // Split the host and reverse it for the tokenization.
        //
        List<String> hostParts = Arrays.asList(host.split("\\."));
        Collections.reverse(hostParts);
        for (String hostPart: hostParts) {
            result.add(new Token<UriElement>(hostPart, UriElement.HOST));
        }

        if (parsedPortFromAuthority != null) {
            result.add(new Token<UriElement>(parsedPortFromAuthority, UriElement.PORT));
        } else if (uri.getPort() > 0) {
            result.add(new Token<UriElement>(String.valueOf(uri.getPort()), UriElement.PORT));
        } else if (getDefaultPort(scheme) > 0) {
            result.add(new Token<UriElement>(String.valueOf(getDefaultPort(scheme)), UriElement.PORT));
        }


        if ( parsedUserInfoFromAuthority != null ) {
            if ( userFromAuthority != null) {
                result.add(new Token<UriElement>(userFromAuthority, UriElement.USERINFO));
            }
            if ( passwordFromAuthority != null ) {
                result.add(new Token<UriElement>(passwordFromAuthority, UriElement.USERINFO));
            }
            if ( userFromAuthority == null && passwordFromAuthority == null) {
                result.add(new Token<UriElement>(parsedUserInfoFromAuthority, UriElement.USERINFO));
            }
        } else if (uri.getUserInfo() != null) {
            String userInfo = uri.getUserInfo();
            int colonIdx = userInfo.indexOf(":");
            if ( colonIdx >= 0) {
                result.add(new Token<UriElement>(userInfo.substring(0, colonIdx), UriElement.USERINFO));
                result.add(new Token<UriElement>(userInfo.substring(colonIdx+1), UriElement.USERINFO));
            } else {
                result.add(new Token<UriElement>(uri.getUserInfo(), UriElement.USERINFO));
            }
        }

        if (isNotBlank(uri.getPath())) {
            String path = uri.getPath();
            if (path.startsWith("/")) {
                path = path.substring(1);
            }
            if (isNotBlank(path)) {
                for (String p: path.split("/")) {
                    result.add(new Token<UriElement>(p, UriElement.PATH));
                }
            }
        }
        return result;
    }
1118204
public static String wrap(String s) {
		StringBuilder sb = new StringBuilder();

		sb.append("(");
		sb.append(s);
		sb.append(")");

		return sb.toString();
	}
678407
public static String urlNonFormEncode(final String s)
        {
        if (StringUtils.isBlank(s))
            {
            LOG.warn("Could not encode blank string");
            throw new IllegalArgumentException("Blank string");
            }
        try
            {
            // We use the HttpClient encoder because the java URLEncoder
            // class uses form encoding.
            return URIUtil.encodeQuery(s, "UTF-8");
            }
        catch (final URIException e)
            {
            LOG.error ("Could not encode: " + s, e);
            
            // This really should never happen.
            assert false;
            return s;
            }
        }
1095105
public static String[] tokenize(String args) {

    // Split the args string on whitespace boundaries accounting for quoted
    // strings.
    args = args.trim();
    List<String> argList = new ArrayList<>();
    String arg = "";
    char activeQuote = 0;
    for (int ii = 0; ii < args.length(); ii++) {
      char ch = args.charAt(ii);
      if ((ch == '\'') || (ch == '"')) {
        arg += ch;
        ii++;
        while ((ii < args.length()) && (args.charAt(ii) != ch)) {
          arg += args.charAt(ii++);
        }
        arg += ch;
      } else if (Character.isWhitespace(ch)) {
        // System.out.printf ("adding argument '%s'%n", arg);
        argList.add(arg);
        arg = "";
        while ((ii < args.length()) && Character.isWhitespace(args.charAt(ii))) {
          ii++;
        }
        if (ii < args.length()) {
          // Encountered a non-whitespace character.
          // Back up to process it on the next loop iteration.
          ii--;
        }
      } else { // must be part of current argument
        arg += ch;
      }
    }
    if (!arg.equals("")) {
      argList.add(arg);
    }

    String[] argsArray = argList.toArray(new String[argList.size()]);
    return argsArray;
  }
740036
@SuppressWarnings("unchecked")
    public String tokenAsString(Comparable tokenAsComparable) {
        ByteBuffer bb = tokenType.decompose(tokenAsComparable);
        Token token = tokenFactory.fromByteArray(bb);
        return tokenFactory.toString(token);
    }
153468
static String urlencode(final String s) {
		try {
			return URLEncoder.encode(s, CHARSET_NAME);
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}
1295446
public Object stringToKey(String s) {
      char type = s.charAt(0);
      switch (type) {
         case 'S':
            // this is a String, NOT a Short. For Short see case 'X'.
            return s.substring(2);
         case 'I':
            // This is an Integer
            return Integer.valueOf(s.substring(2));
         case 'Y':
            // This is a BYTE
            return Byte.valueOf(s.substring(2));
         case 'L':
            // This is a Long
            return Long.valueOf(s.substring(2));
         case 'X':
            // This is a SHORT
            return Short.valueOf(s.substring(2));
         case 'D':
            // This is a Double
            return Double.valueOf(s.substring(2));
         case 'F':
            // This is a Float
            return Float.valueOf(s.substring(2));
         case 'B':
            // This is a Boolean, NOT a Byte. For Byte see case 'Y'.
            return Boolean.valueOf(s.substring(2));
         case 'C':
            // This is a Character
            return Character.valueOf(s.charAt(2));
         case 'U':
            // This is a java.util.UUID
            return UUID.fromString(s.substring(2));
         case 'A':
            // This is an array of bytes encoded as a Base64 string
            return Base64.getDecoder().decode(s.substring(2));
         case 'T':
            // this is a custom Transformable or a type with a registered Transformer
            int indexOfSecondDelimiter = s.indexOf(':', 2);
            String keyClassName = s.substring(2, indexOfSecondDelimiter);
            String keyAsString = s.substring(indexOfSecondDelimiter + 1);
            Transformer t = getTransformer(keyClassName);
            if (t != null) {
               return t.fromString(keyAsString);
            } else {
               throw log.noTransformerForKey(keyClassName);
            }
      }
      throw new CacheException("Unknown key type metadata: " + type);
   }
206246
public static String urlDecode(String s) {
        try {
            return URLDecoder.decode(s, StandardCharsets.UTF_8.name());
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("get a jdk that actually supports utf-8", e);
        }
    }
751682
public Matcher matcher(CharSequence s) {
        Matcher m = new Matcher(this);
        m.setTarget(s);
        return m;
    }
929477
public static URI stringAsURI(String s) throws IOException {
    URI u = null;
    // try to make a URI
    try {
      u = new URI(s);
    } catch (URISyntaxException e){
      LOG.error("Syntax error in URI " + s
          + ". Please check hdfs configuration.", e);
    }

    // if URI is null or scheme is undefined, then assume it's file://
    if(u == null || u.getScheme() == null){
      LOG.warn("Path " + s + " should be specified as a URI "
          + "in configuration files. Please update hdfs configuration.");
      u = fileAsURI(new File(s));
    }
    return u;
  }
736377
public static HashMap<String, String> ner(String s) {
		if(ner==null)
			return null;
		return ner.tag(s);
	}
555700
public static String[] toArrayElement(String s) {
    return (s == null || s.length() == 0) ? new String[0] : new String[]{s};
  }
1135208
static String[] tokenize(String str) {
        char sep = '.';
        int start = 0;
        int len = str.length();
        int count = 0;
        for (int pos = 0; pos < len; pos++) {
            if (str.charAt(pos) == sep) {
                if (pos != start) {
                    count++;
                }
                start = pos + 1;
            }
        }
        if (len != start) {
            count++;
        }
        String[] l = new String[count];

        count = 0;
        start = 0;
        for (int pos = 0; pos < len; pos++) {
            if (str.charAt(pos) == sep) {
                if (pos != start) {
                    String tok = str.substring(start, pos);
                    l[count++] = tok;
                }
                start = pos + 1;
            }
        }
        if (len != start) {
            String tok = str.substring(start);
            l[count/* ++ */] = tok;
        }
        return l;
    }
790460
@SuppressWarnings("deprecation")
    public static String urlUnescape(String s) {
        try {
            return URLDecoder.decode(s, "UTF8");
        } catch (UnsupportedEncodingException e) {
            // should be impossible; all JVMs must support UTF8
            // but have a fallback just in case
            return URLDecoder.decode(s);
        }
    }
653596
public static URL asUrlOrResource(String s) {
        if (Strings.isNullOrEmpty(s)) {
            return null;
        }

        try {
            return new URL(s);
        } catch (MalformedURLException e) {
            //If its not a valid URL try to treat it as a local resource.
            return findConfigResource(s);
        }
    }
799901
public static List<String> split(
                    final String str
                    )
    {
        String  s = str;
        if (s != null) {
            s = s.trim();
        }

        List<String>  list = new ArrayList<String>();
        if (s == null || s.length() == 0) {
            return list;
        }

        String[]  tokens = s.split( "[ \t\n\r\f]" );
        // NOTE: tokens[i] may be an empty string "".

        // excludes empty strings.
        int  n_tokens = tokens.length;
        for (int  i = 0; i < n_tokens; i++) {
            if (tokens[i].length() > 0) {
                list.add( tokens[i] );
            }
        }

        return list;
    }
1242510
private static String[] tokenize(String string) {
		if (string.indexOf("?") == -1 && string.indexOf("*") == -1) {
			return new String[] { string };
		}

		char[] textArray = string.toCharArray();
		List<String> tokens = new ArrayList<String>();
		StringBuilder tokenBuilder = new StringBuilder();

		for (int i = 0; i < textArray.length; i++) {
			if (textArray[i] != '?' && textArray[i] != '*') {
				// collect non wild card characters
				tokenBuilder.append(textArray[i]);
				continue;
			}

			if (tokenBuilder.length() != 0) {
				tokens.add(tokenBuilder.toString());
				tokenBuilder.setLength(0);
			}
			if (textArray[i] == '?') {
				tokens.add("?");
			} else if (tokens.size() == 0 || (i > 0 && tokens.get(tokens.size() - 1).equals("*") == false)) {
				tokens.add("*");
			}
		}

		if (tokenBuilder.length() != 0) {
			tokens.add(tokenBuilder.toString());
		}

		return (String[]) tokens.toArray(new String[tokens.size()]);
	}