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

/**
 * Tokenize the given String into a String array via a StringTokenizer.
 * <p>The given delimiters string is supposed to consist of any number of
 * delimiter characters. Each of those characters can be used to separate
 * tokens. A delimiter is always a single character; for multi-character
 * delimiters, consider using {@code delimitedListToStringArray}
 * @param str the String to tokenize/*from   w  w w.ja  v  a2s . c o  m*/
 * @param delimiters the delimiter characters, assembled as String
 * (each of those characters is individually considered as delimiter)
 * @param trimTokens trim the tokens via String's {@code trim}
 * @param ignoreEmptyTokens omit empty tokens from the result array
 * (only applies to tokens that are empty after trimming; StringTokenizer
 * will not consider subsequent delimiters as token in the first place).
 * @return an array of the tokens ({@code null} if the input String
 * was {@code null})
 * @see java.util.StringTokenizer
 * @see String#trim()
 * @see #delimitedListToStringArray
 */
public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens,
        boolean ignoreEmptyTokens) {

    if (str == null) {
        return null;
    }
    StringTokenizer st = new StringTokenizer(str, delimiters);
    List<String> tokens = new ArrayList<>();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (trimTokens) {
            token = token.trim();
        }
        if (!ignoreEmptyTokens || token.length() > 0) {
            tokens.add(token);
        }
    }
    return toStringArray(tokens);
}

From source file:com.evolveum.liferay.usercreatehook.ws.WSConfig.java

public static List<String> getReservedScreennames() {
    List<String> result = new ArrayList<String>();
    String value = PropsUtil.get(PROPERTY_SCREENNAME_RESERVED);
    if (!StringUtils.isBlank(value)) {
        StringTokenizer st = new StringTokenizer(value, ",");
        while (st.hasMoreTokens()) {
            String reservedScreenname = st.nextToken().trim().toLowerCase();
            result.add(reservedScreenname);
        }/*from w ww .ja  v a 2  s  . c  o m*/
    }
    LOG.debug("Property '" + PROPERTY_SCREENNAME_RESERVED + "'  value: '" + value
            + "'. Used reserved screennames from list: '" + result + "'");
    return result;
}

From source file:com.microsoft.aad.adal.HashMapExtensions.java

/**
 * decode url string into a key value pairs with given query delimiter given
 * string as a=1&b=2 will return key value of [[a,1],[b,2]].
 * //from  w ww  . j ava2 s .  c  o  m
 * @param parameters
 * @param delimiter
 * @return key value pairs
 */
static final HashMap<String, String> URLFormDecodeData(String parameters, String delimiter) {
    HashMap<String, String> result = new HashMap<String, String>();

    if (!StringExtensions.IsNullOrBlank(parameters)) {
        StringTokenizer parameterTokenizer = new StringTokenizer(parameters, delimiter);

        while (parameterTokenizer.hasMoreTokens()) {
            String pair = parameterTokenizer.nextToken();
            String[] elements = pair.split("=");

            if (elements != null && elements.length == 2) {
                String key = null;
                String value = null;
                try {
                    key = StringExtensions.URLFormDecode(elements[0].trim());
                    value = StringExtensions.URLFormDecode(elements[1].trim());
                } catch (UnsupportedEncodingException e) {
                    Log.d(TAG, e.getMessage());
                }

                if (!StringExtensions.IsNullOrBlank(key) && !StringExtensions.IsNullOrBlank(value)) {
                    result.put(key, value);
                }
            }
        }
    }

    return result;
}

From source file:Main.java

public static void killProcess(String packageName) {
    String processId = "";
    try {/*ww  w .  j  a  v  a 2s  . c o m*/
        Runtime r = Runtime.getRuntime();
        Process p = r.exec("ps");
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String inline;
        while ((inline = br.readLine()) != null) {
            if (packageName != null) {
                if (inline.contains(packageName)) {
                    break;
                }
            } else {
                Log.e("PvTorrent_proc", "packageName is null");
            }

        }
        br.close();
        Log.i("PvTorrent_proc", "inline" + inline);
        if (inline != null) {

            StringTokenizer processInfoTokenizer = new StringTokenizer(inline);
            int count = 0;
            while (processInfoTokenizer.hasMoreTokens()) {
                count++;
                processId = processInfoTokenizer.nextToken();
                if (count == 2) {
                    break;
                }
            }
            Log.i("PvTorrent_proc", "kill process : " + processId);
            r.exec("kill -9 " + processId);
        }
    } catch (IOException ex) {
        Log.e("PvTorrent_proc", "kill" + ex.getStackTrace());
    }
}

From source file:com.streamsets.pipeline.lib.fuzzy.FuzzyMatch.java

private static Set<String> tokenizeString(String str) {
    Set<String> set = new HashSet<>();

    // Normalize and tokenize the input strings before storing as a set.
    StringTokenizer st = new StringTokenizer(str);
    while (st.hasMoreTokens()) {
        String t1 = st.nextToken();
        String[] tokens = camelAndSnakeCaseSplitter.split(t1);
        for (int i = 0; i < tokens.length; i++) {
            tokens[i] = tokens[i].toLowerCase();
        }/*  w w w . j a va  2s. c  o m*/
        Collections.addAll(set, tokens);
    }

    set.remove("");

    return set;
}

From source file:edu.stanford.muse.util.SloppyDates.java

public static List<DateRangeSpec> parseDateSpec(String dateSpec) {
    List<DateRangeSpec> result = new ArrayList<DateRangeSpec>();
    StringTokenizer st = new StringTokenizer(dateSpec, ".,;");
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        result.add(new DateRangeSpec(token));
    }/* www  .  jav a  2 s. c o m*/
    return result;
}

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  ww w  . j a  v  a2s.  c  o m*/

    return parametersMap;
}

From source file:Main.java

/**
 * Find an element using XPath-quotation expressions. Path must not including
 * the context element, path elements can be separated by / or .,
 * and namespace is NOT supported.//from  www  .ja  va2 s .  c  om
 * @param context Element to start the search from, cannot be null.
 * @param path XPath-quotation expression, cannot be null.
 * @return the first matched element if there are matches, otherwise
 * return null.
 */
public static Element getElementByPath(Element context, String path) {
    Element cur = context;
    StringTokenizer tokens = new StringTokenizer(path, "/");

    while (tokens.hasMoreTokens()) {
        String name = tokens.nextToken();

        cur = getChildElement(cur, name);
        if (cur == null) {
            return null;
        }
    }
    return cur;
}

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

public static Map parseTokenLine(String line, String delimiter) {

    BidiMap returnMap = new TreeBidiMap();

    if (StringUtils.isBlank(line) || StringUtils.isBlank(delimiter)) {
        return returnMap;
    }/*from  w  w  w  . j av a2 s  . c  o  m*/

    StringTokenizer st = new StringTokenizer(line, delimiter);

    int count = 0;
    while (st.hasMoreTokens()) {
        String value = st.nextToken();
        returnMap.put(value, count);
        count++;
    }

    return returnMap;

}

From source file:StringUtils.java

public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens,
        boolean ignoreEmptyTokens) {

    StringTokenizer st = new StringTokenizer(str, delimiters);
    List tokens = new ArrayList();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (trimTokens) {
            token = token.trim();//from  w w w.  j a va 2 s .c  o  m
        }
        if (!ignoreEmptyTokens || token.length() > 0) {
            tokens.add(token);
        }
    }
    return toStringArray(tokens);
}