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:StringUtil.java

/**
 * Parses a list according to the specified delimiter into an
 * array of Strings.//w  ww  .  j  av a  2  s .  c  om
 * @see java.util.StringTokenizer
 * @param list a string of token seperated values
 * @param delim the delimiter character(s).  Each character in the string is a
 * single delimeter.
 * @return an array of strings
 */
public static String[] parseList(String list, String delim) {
    List result = new ArrayList();
    StringTokenizer tokenizer = new StringTokenizer(list, delim);
    while (tokenizer.hasMoreTokens()) {
        result.add(tokenizer.nextToken());
    }
    return (String[]) result.toArray(new String[0]);
}

From source file:ch.cyberduck.core.URIEncoder.java

/**
 * URL encode a path/* ww  w .j av a 2s.c om*/
 *
 * @param p Path
 * @return URI encoded
 * @see java.net.URLEncoder#encode(String, String)
 */
public static String encode(final String p) {
    try {
        final StringBuilder b = new StringBuilder();
        final StringTokenizer t = new StringTokenizer(p, "/");
        if (!t.hasMoreTokens()) {
            return p;
        }
        if (StringUtils.startsWith(p, String.valueOf(Path.DELIMITER))) {
            b.append(Path.DELIMITER);
        }
        while (t.hasMoreTokens()) {
            b.append(URLEncoder.encode(t.nextToken(), "UTF-8"));
            if (t.hasMoreTokens()) {
                b.append(Path.DELIMITER);
            }
        }
        if (StringUtils.endsWith(p, String.valueOf(Path.DELIMITER))) {
            b.append(Path.DELIMITER);
        }
        // Because URLEncoder uses <code>application/x-www-form-urlencoded</code> we have to replace these
        // for proper URI percented encoding.
        return b.toString().replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
    } catch (UnsupportedEncodingException e) {
        return p;
    }
}

From source file:Main.java

/**
 * parses comma or space separated list. A null return value means a wildcard.
 * //from   w  w  w. j ava  2  s . c  om
 * @return List of tokens or null if the commaSeparatedListText is null, '*', or empty
 */
public static List<String> parseCommaSeparatedList(final String commaSeparatedListText) {
    List<String> entries = null;
    if (commaSeparatedListText != null && !"*".equals(commaSeparatedListText)) {
        final StringTokenizer tokenizer = new StringTokenizer(commaSeparatedListText, ", ");
        while (tokenizer.hasMoreTokens()) {
            if (entries == null) {
                entries = new ArrayList<String>();
            }
            entries.add(tokenizer.nextToken());
        }
    }
    return entries;
}

From source file:Main.java

public static Color convertHexStringToColor(String str) throws NumberFormatException {
    int multiplier = 1;
    StringTokenizer tokenizer = new StringTokenizer(str, " \t\r\n\b:;[]()+");
    while (tokenizer.hasMoreTokens()) {
        multiplier = 1;/*from w ww  . java  2 s .  com*/
        String token = tokenizer.nextToken();
        if (null == token) {
            throw new NumberFormatException(str);
        }
        if (token.startsWith("-")) {
            multiplier = -1;
            token = token.substring(1);
        }
        int point_index = token.indexOf(".");
        if (point_index > 0) {
            token = token.substring(0, point_index);
        } else if (point_index == 0) {
            return new Color(0);
        }
        try {
            if (token.startsWith("0x")) {
                return new Color(multiplier * Integer.parseInt(token.substring(2), 16));
            } else if (token.startsWith("#")) {
                return new Color(multiplier * Integer.parseInt(token.substring(1), 16));
            } else if (token.startsWith("0") && !token.equals("0")) {
                return new Color(multiplier * Integer.parseInt(token.substring(1), 8));
            } else {
                return new Color(multiplier * Integer.parseInt(token));
            }
        } catch (NumberFormatException e) {
            continue;
        }
    }
    throw new NumberFormatException(str);

}

From source file:com.kixeye.chassis.bootstrap.aws.UserData.java

public static UserData parse(String userData) {
    if (!StringUtils.isBlank(userData)) {
        StringTokenizer stringTokenizer = new StringTokenizer(userData, "\n");
        while (stringTokenizer.hasMoreTokens()) {
            String line = stringTokenizer.nextToken();
            int envStartIdx = line.indexOf(ENVIRONMENT_TEXT);
            if (envStartIdx >= 0) {
                String env = line.substring(envStartIdx + ENVIRONMENT_TEXT.length());
                return new UserData(StringUtils.trimToNull(env));
            }// w w w . j  a v  a 2s  .c  o m
        }
    }
    throw new BootstrapException("Found no environment data in user-data " + userData);
}

From source file:Main.java

/**
 * parses comma or space separated list. A null return value means a wildcard.
 * @return List of tokens or null if the commaSeparatedListText is null, '*', or empty
 *///from ww w .  j  av  a 2s  . c  o m
public static List<String> parseCommaSeparatedList(String commaSeparatedListText) {
    List<String> entries = null;
    if (commaSeparatedListText != null) {
        if (!"*".equals(commaSeparatedListText)) {
            StringTokenizer tokenizer = new StringTokenizer(commaSeparatedListText, ", ");
            while (tokenizer.hasMoreTokens()) {
                if (entries == null) {
                    entries = new ArrayList<String>();
                }
                entries.add(tokenizer.nextToken());
            }
        }
    }
    return entries;
}

From source file:Main.java

public static String[] split(String str, String delimiters) {
    final StringTokenizer st = new StringTokenizer(str, delimiters);
    final List<String> tokens = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        final String token = st.nextToken();
        tokens.add(token);/*ww w. j a va2  s. c o m*/
    }
    return tokens.toArray(new String[tokens.size()]);
}

From source file:Main.java

public static String[] parseExtensions(String extensions) {
    StringTokenizer st = new StringTokenizer(extensions, ",");
    String[] ext = new String[st.countTokens()];
    int i = 0;/* w  ww . java2s  .  co  m*/
    while (st.hasMoreTokens()) {
        ext[i++] = st.nextToken();
    }
    return ext;
}

From source file:Main.java

public static Vector<String> getSets(String setString) {
    StringTokenizer tokenizer = new StringTokenizer(setString, ";");
    Vector<String> sets = new Vector<String>();
    while (tokenizer.hasMoreTokens()) {
        sets.add(tokenizer.nextToken());
    }//from w w  w  .j av a  2 s  .c o m
    if (sets.size() == 0)
        sets.add("");
    return sets;
}

From source file:com.salesmanager.core.util.LanguageUtil.java

public static List parseLanguages(String langs) {
    List lst = new ArrayList();
    if (langs != null) {
        StringTokenizer st = new StringTokenizer(langs, ";");
        while (st != null && st.hasMoreTokens()) {
            String lang = st.nextToken();
            lst.add(lang);/*from  w  w w.j  a v  a  2s  . c  om*/
        }
    }
    return lst;
}