Example usage for java.util StringTokenizer nextToken

List of usage examples for java.util StringTokenizer nextToken

Introduction

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

Prototype

public String nextToken() 

Source Link

Document

Returns the next token from this string tokenizer.

Usage

From source file:Main.java

/**
 * Returns a Set of String from a formatted string.
 * The format is /* www. ja  v  a 2  s.c om*/
 * <pre>
 * &lt;value1&gt;,&lt;value2&gt;...,&lt;value3&gt;
 * </pre>
 *
 * @param str Formatted String.
 * @return a map of String to Set of String
 */
public static Set<String> parseStringToSet(String str) {
    Set<String> set = new HashSet<String>();
    StringTokenizer st = new StringTokenizer(str, ",");
    while (st.hasMoreTokens()) {
        set.add(st.nextToken().trim());
    }
    return set;
}

From source file:Main.java

public static boolean valiChar(String string) {
    StringTokenizer s = new StringTokenizer(string, ",");
    //      int num=0;
    if (s.hasMoreTokens()) {
        String str = s.nextToken();
        byte[] cc = str.getBytes();
        int a = (int) cc[0];
        if (a < 32 || a > 127) {
            return false;
        }//from w  w  w  . ja v  a 2  s. co m
    }
    return true;
}

From source file:Main.java

protected static String[] split(final String str, final String delimiter) {
    if (str == null || str.trim().length() == 0) {
        return EMPTY_STRINGS;
    }//w w w  .  jav a 2s  .  c om
    final List<String> list = new ArrayList<String>();
    final StringTokenizer st = new StringTokenizer(str, delimiter);
    while (st.hasMoreElements()) {
        list.add(st.nextToken());
    }
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:Main.java

public static boolean isInRange(String ip, String[] netInfo) {

    // Log.d(TAG, "checking if " + ip + " is in range of " + netInfo[0] +
    // "/"//from   ww w  . j  a  v  a2s .  co  m
    // + netInfo[1]);

    StringTokenizer maskTokens = new StringTokenizer(netInfo[1], ".");

    StringTokenizer ipTokens = new StringTokenizer(ip, ".");
    int ipArray[] = new int[4];
    ipArray[0] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken());
    ipArray[1] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken());
    ipArray[2] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken());
    ipArray[3] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken());

    String networkAddress = ipArray[0] + "." + ipArray[1] + "." + ipArray[2] + "." + ipArray[3];

    return netInfo[0].equals(networkAddress);

}

From source file:Main.java

private static String[] tokenize(String str) {
    StringTokenizer tokenizer = new StringTokenizer(str);
    String[] arr = new String[tokenizer.countTokens()];
    int i = 0;/*from w  ww .j av a  2s. c  o m*/
    while (tokenizer.hasMoreTokens()) {
        arr[i++] = tokenizer.nextToken();
    }
    return arr;
}

From source file:kaleidoscope.util.HttpUtils.java

public static Locale getLocale(String acceptLanguage) {
    Locale locale = null;//from   ww  w. j av a2 s. c  o m

    if (StringUtils.isEmpty(acceptLanguage) != true) {
        StringTokenizer langToken = new StringTokenizer(acceptLanguage, ",; ");
        String language = langToken.nextToken().replace('-', '_');

        StringTokenizer localeToken = new StringTokenizer(language, "_");
        switch (localeToken.countTokens()) {
        case 1:
            locale = new Locale(localeToken.nextToken());
            break;
        case 2:
            locale = new Locale(localeToken.nextToken(), localeToken.nextToken());
            break;
        case 3:
            locale = new Locale(localeToken.nextToken(), localeToken.nextToken(), localeToken.nextToken());
            break;
        }
    }

    if (locale == null) {
        locale = Locale.getDefault();
    }

    return locale;
}

From source file:Main.java

public static List<String> parseTokenList(String tokenList) {
    List<String> result = new ArrayList<String>();
    StringTokenizer tokenizer = new StringTokenizer(tokenList, " ");
    while (tokenizer.hasMoreTokens()) {
        result.add(tokenizer.nextToken());
    }// www .  ja  v  a2  s  .  co m
    return result;
}

From source file:Main.java

public static String getIdentifier(HashMap<String, ArrayList<String>> addresses) {
    String wifi_address = addresses.get("eth0").get(0); //for now we expect there to be only 1 address, the one OLSRd has assigned
    //need to extract the 3rd and 4th octet of the address
    StringTokenizer tokens = new StringTokenizer(wifi_address, ".");
    tokens.nextElement();//www  .j  a v  a 2 s. c o  m
    tokens.nextElement();
    String identifier = tokens.nextToken() + "." + tokens.nextToken();
    return identifier;
}

From source file:Main.java

public static Integer[] getMinSec(String str) {

    Integer[] data = new Integer[2];

    StringTokenizer tokens = new StringTokenizer(str, ",");
    int counter = 0;

    while (tokens.hasMoreTokens()) {
        String next = tokens.nextToken();
        data[counter++] = Integer.valueOf(next);
    }/*from w w w. java 2  s.  c o m*/

    return data;
}

From source file:Main.java

public static int findProcessIdWithPS(String command) throws Exception {

    int procId = -1;

    Runtime r = Runtime.getRuntime();

    Process procPs;//w w  w  . j a  va 2 s . com

    procPs = r.exec(SHELL_CMD_PS);

    BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
    String line;

    while ((line = reader.readLine()) != null) {
        if (line.contains(' ' + command)) {

            StringTokenizer st = new StringTokenizer(line, " ");
            st.nextToken(); // proc owner

            procId = Integer.parseInt(st.nextToken().trim());

            break;
        }
    }

    return procId;

}