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

/**
 * 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  w w  w.j  ava  2 s.  c  o  m
 * @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:de.iteratec.iteraplan.db.SqlScriptExecutor.java

public static List<String> readSqlScript(InputStream in) {
    InputStream setupSqlInputStream = in;
    String sqlString = null;/* w w w.j av a2  s  .  c  o m*/
    try {
        sqlString = IOUtils.toString(setupSqlInputStream);
    } catch (IOException fnfe) {
        LOGGER.error("unable to read data.");
    } finally {
        if (setupSqlInputStream != null) {
            try {
                setupSqlInputStream.close();
            } catch (IOException e) {
                LOGGER.error("Cannot close stream for setupSqlFile", e);
            }
        }
    }
    List<String> sqlStatements = Lists.newArrayList();

    StringTokenizer tokenizer = new StringTokenizer(sqlString, ";");
    while (tokenizer.hasMoreTokens()) {
        String nextToken = tokenizer.nextToken();
        sqlStatements.add(nextToken);
    }

    return sqlStatements;
}

From source file:com.googlecode.jsfFlex.myFaces.LocaleUtils.java

/**
 * Convert locale string used by converter tags to locale.
 *
 * @param name name of the locale/*from w  w  w. j  a  va  2 s.  co  m*/
 * @return locale specified by the given String
 *
 * @see org.apache.myfaces.taglib.core.ConvertDateTimeTag#setConverterLocale
 * @see org.apache.myfaces.taglib.core.ConvertNumberTag#setConverterLocale
 */
public static Locale converterTagLocaleFromString(String name) {
    try {
        Locale locale;
        StringTokenizer st = new StringTokenizer(name, "_");
        String language = st.nextToken();

        if (st.hasMoreTokens()) {
            String country = st.nextToken();

            if (st.hasMoreTokens()) {
                String variant = st.nextToken();
                locale = new Locale(language, country, variant);
            } else {
                locale = new Locale(language, country);
            }
        } else {
            locale = new Locale(language);
        }

        return locale;
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "Locale parsing exception - " + "invalid string representation '" + name + "'");
    }
}

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();
        }/*from w w w  .  j  a va  2s .  com*/
        Collections.addAll(set, tokens);
    }

    set.remove("");

    return set;
}

From source file:Main.java

/**
 * /*from  w  w w.  j av a2 s.c o m*/
 * @param value
 * @return int[]
 */
public static int[] toIntArray(final String value) {
    if (value == null) {
        return new int[] {};
    }

    final String strippedValue = value.replace(ARRAY_OPEN_TAG, EMPTY_STRING).replace(ARRAY_CLOSE_TAG,
            EMPTY_STRING);
    final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR);
    final Collection<Integer> intCollection = new ArrayList<>();

    while (tokenizer.hasMoreTokens()) {
        intCollection.add(Integer.valueOf(tokenizer.nextToken().trim()));
    }

    return toIntArray(intCollection);
}

From source file:Main.java

/**
 * /*from  ww  w.ja v  a  2  s.c om*/
 * @param value
 * @return boolean[]
 */
public static boolean[] toBooleanArray(final String value) {
    if (value == null) {
        return new boolean[] {};
    }

    final String strippedValue = value.replace(ARRAY_OPEN_TAG, EMPTY_STRING).replace(ARRAY_CLOSE_TAG,
            EMPTY_STRING);
    final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR);
    final Collection<Boolean> intCollection = new ArrayList<>();

    while (tokenizer.hasMoreTokens()) {
        intCollection.add(Boolean.valueOf(tokenizer.nextToken().trim()));
    }

    return toBooleanArray(intCollection);
}

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  a2s .  co 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:com.codedx.burp.security.InvalidCertificateDialogStrategy.java

private static String getCN(X509Certificate cert) {
    String principal = cert.getSubjectX500Principal().toString();
    StringTokenizer tokenizer = new StringTokenizer(principal, ",");
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        int i = token.indexOf("CN=");
        if (i >= 0) {
            return token.substring(i + 3);
        }//from   ww w.ja v a2  s.co m
    }
    return null;
}

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();//  w  w  w  . ja  v  a  2  s.  c  om
        }
        if (!ignoreEmptyTokens || token.length() > 0) {
            tokens.add(token);
        }
    }
    return toStringArray(tokens);
}

From source file:com.trailmagic.image.ui.WebSupport.java

public static Long extractImageIdFromRequest(HttpServletRequest req)
        throws IllegalArgumentException, NumberFormatException {
    UrlPathHelper pathHelper = new UrlPathHelper();
    String myPath = pathHelper.getLookupPathForRequest(req);
    s_logger.debug("Lookup path: " + pathHelper.getLookupPathForRequest(req));
    StringTokenizer pathTokens = new StringTokenizer(myPath, "/");
    String token = null;/*from w  w w . ja  va  2s.c  o m*/
    while (pathTokens.hasMoreTokens()) {
        token = pathTokens.nextToken();
    }

    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Last token is: " + token);
    }

    if (token == null || "".equals(token)) {
        throw new IllegalArgumentException("Invalid request");
    }
    return new Long(token);
}