Example usage for java.util StringTokenizer hasMoreTokens

List of usage examples for java.util StringTokenizer hasMoreTokens

Introduction

In this page you can find the example usage for java.util StringTokenizer hasMoreTokens.

Prototype

public boolean hasMoreTokens() 

Source Link

Document

Tests if there are more tokens available from this tokenizer's string.

Usage

From source file:Main.java

public static Pattern compilePattern(String key, boolean ignoreCase) {
    StringTokenizer stk = new StringTokenizer(key, "*?", true);
    StringBuilder regex = new StringBuilder();
    while (stk.hasMoreTokens()) {
        String tk = stk.nextToken();
        char ch1 = tk.charAt(0);
        if (ch1 == '*') {
            regex.append(".*");
        } else if (ch1 == '?') {
            regex.append(".");
        } else {//from  w w  w  .ja  va  2 s. c  o  m
            regex.append("\\Q").append(tk).append("\\E");
        }
    }
    return Pattern.compile(regex.toString(), ignoreCase ? Pattern.CASE_INSENSITIVE : 0);
}

From source file:Main.java

/**
 * Returns a reference to a file with the specified name that is located
 * somewhere on the classpath. The code for this method is an adaptation of
 * code supplied by Dave Postill./*  ww w  . j a  v  a  2  s .  co  m*/
 * 
 * @param name
 *          the filename.
 * 
 * @return a reference to a file or <code>null if no file could be
 *         found.
 */
public static File findFileOnClassPath(final String name) {

    final String classpath = System.getProperty("java.class.path");
    final String pathSeparator = System.getProperty("path.separator");

    final StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator);

    while (tokenizer.hasMoreTokens()) {
        final String pathElement = tokenizer.nextToken();

        final File directoryOrJar = new File(pathElement);
        final File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile();

        if (absoluteDirectoryOrJar.isFile()) {
            final File target = new File(absoluteDirectoryOrJar.getParent(), name);
            if (target.exists()) {
                return target;
            }
        } else {
            final File target = new File(directoryOrJar, name);
            if (target.exists()) {
                return target;
            }
        }

    }
    return null;

}

From source file:edu.illinois.cs.cogcomp.wikifier.utils.io.InFile.java

public static List<String> tokenize(String s, String delims) {
     if (s == null)
         return null;
     List<String> res = new ArrayList<String>();
     StringTokenizer st = new StringTokenizer(s, delims);
     while (st.hasMoreTokens())
         res.add(st.nextToken());/*from  www .  j  a v  a2  s .c  o m*/
     return res;
 }

From source file:info.bonjean.beluga.util.HTTPUtil.java

public static Map<String, String> parseUrl(String url) {
    Map<String, String> parametersMap = new HashMap<String, String>();
    String parameters = url.substring(url.indexOf("?") + 1);

    StringTokenizer paramGroup = new StringTokenizer(parameters, "&");

    while (paramGroup.hasMoreTokens()) {
        StringTokenizer value = new StringTokenizer(paramGroup.nextToken(), "=");
        parametersMap.put(value.nextToken(), value.nextToken());
    }//from  w  w  w  .j av a2s  .  co  m

    return parametersMap;
}

From source file:ch.admin.suis.msghandler.common.MessageType.java

/**
 * Creates a list of message types from the provided string value. If the value
 * is null or empty, an empty list is returned.
 *
 * @param typesValue the types in the form <code>type1 type2</code>, i.e. the types are
 *                   numerical values separated by whitespaces
 * @return List of message types from a message
 *//*ww  w  .j av a2s. c  o m*/
public static List<MessageType> from(String typesValue) {
    // read the message types
    final ArrayList<MessageType> messageTypes = new ArrayList<>();

    if (null != typesValue) {
        final StringTokenizer types = new StringTokenizer(typesValue);

        while (types.hasMoreTokens()) {
            String type = types.nextToken();
            messageTypes.add(new MessageType(Integer.decode(type)));
        }
    }

    return messageTypes;
}

From source file:edu.illinois.cs.cogcomp.wikifier.utils.io.InFile.java

public static List<String> tokenize(String s) {
     if (s == null)
         return null;
     List<String> res = new ArrayList<String>();
     StringTokenizer st = new StringTokenizer(s, " \n\t\r");
     while (st.hasMoreTokens())
         res.add(st.nextToken());/* www  .  j  a va2  s . c o  m*/
     return res;
 }

From source file:com.enonic.cms.framework.util.UrlPathEncoder.java

private static StringBuffer doEncodePath(String localPath, String encoding) {
    StringBuffer encodedPath = new StringBuffer(localPath.length() * 2);
    if (localPath.startsWith("/")) {
        encodedPath.append("/");
    }//from  ww w  .j av  a2s .com

    StringTokenizer st = new StringTokenizer(localPath, "/");
    int i = 0;
    while (st.hasMoreTokens()) {
        String pathElement = st.nextToken();
        i++;
        if (i > 1) {
            encodedPath.append("/");
        }
        try {
            encodedPath.append(URLEncoder.encode(pathElement, encoding));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(
                    "Failed to encode path '" + localPath + "' with encoding '" + encoding + "'", e);
        }
    }

    if (localPath.endsWith("/")) {
        encodedPath.append("/");
    }
    return encodedPath;
}

From source file:com.opensymphony.xwork2.config.ConfigurationUtil.java

/**
 * Splits the string into a list using a comma as the token separator.
 * @param parent The comma separated string.
 * @return A list of tokens from the specified string.
 *///from w w w  .jav  a  2  s .  c o m
public static List<String> buildParentListFromString(String parent) {
    if (StringUtils.isEmpty(parent)) {
        return Collections.emptyList();
    }

    StringTokenizer tokenizer = new StringTokenizer(parent, ",");
    List<String> parents = new ArrayList<>();

    while (tokenizer.hasMoreTokens()) {
        String parentName = tokenizer.nextToken().trim();

        if (StringUtils.isNotEmpty(parentName)) {
            parents.add(parentName);
        }
    }

    return parents;
}

From source file:com.flipkart.poseidon.handlers.http.utils.StringUtils.java

/**
 * Gets the query parameters from the URL
 * @param httpUrl The URL from which query params have to be extracted
 * @return // ww w.  j  a va2  s .  c o m
 */
public static Map<String, String> getQueryParams(String httpUrl) {
    Map<String, String> params = new HashMap<String, String>();
    if (httpUrl == null) {
        return params;
    }

    URL url = null;
    try {
        url = new URL(httpUrl);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }

    String query = url.getQuery();
    if (query == null) {
        return params;
    }

    StringTokenizer tokenizer = new StringTokenizer(query, "&");
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        int index = token.indexOf("=");
        params.put(token.substring(0, index).trim(), token.substring(index + 1).trim());
    }

    return params;
}

From source file:Main.java

private static ArrayList<String> parseLine(String line) {
    StringTokenizer st = new StringTokenizer(line);
    ArrayList<String> tokens = new ArrayList<>();

    while (st.hasMoreTokens()) {
        tokens.add(st.nextToken());//from ww  w .j av  a 2  s.  c o m
    }

    return tokens;
}