Example usage for java.util StringTokenizer hasMoreElements

List of usage examples for java.util StringTokenizer hasMoreElements

Introduction

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

Prototype

public boolean hasMoreElements() 

Source Link

Document

Returns the same value as the hasMoreTokens method.

Usage

From source file:Main.java

/**
 * A value of the header information./*  w w w  .j  a  v a 2s.  c  o  m*/
 *
 * @param content      like {@code text/html;charset=utf-8}.
 * @param key          like {@code charset}.
 * @param defaultValue list {@code utf-8}.
 * @return If you have a value key, you will return the parsed value if you don't return the default value.
 */
public static String parseHeadValue(String content, String key, String defaultValue) {
    if (!TextUtils.isEmpty(content) && !TextUtils.isEmpty(key)) {
        StringTokenizer stringTokenizer = new StringTokenizer(content, ";");
        while (stringTokenizer.hasMoreElements()) {
            String valuePair = stringTokenizer.nextToken();
            int index = valuePair.indexOf('=');
            if (index > 0) {
                String name = valuePair.substring(0, index).trim();
                if (key.equalsIgnoreCase(name)) {
                    defaultValue = valuePair.substring(index + 1).trim();
                    break;
                }
            }
        }
    }
    return defaultValue;
}

From source file:Main.java

/**
 * gets a tokenizer and returns an arraylist with the separated elements of the tokenizer
 * /* w w w .j a  v a  2 s  .c o  m*/
 * @param strt the tokenizer
 * @param hasToTrim if has to trim every single element of the tokenizer
 * @return the AL with the elements
 */
public static String[] getStringArrayFromString(String strValues, String strSeparator, boolean hasToTrim) {

    // if null
    if (strValues == null)
        return new String[0];

    // creates the AL
    ArrayList<String> al = new ArrayList<String>();
    StringTokenizer strt = new StringTokenizer(strValues, strSeparator);

    while (strt.hasMoreElements()) {
        // gets the next element
        String strElement = (String) strt.nextElement();

        // if is to be trimmed, it does it
        if (hasToTrim)
            strElement = strElement.trim();

        // and adds it to the AL
        al.add(strElement);
    }

    String[] strArray = new String[al.size()];

    // returns the AL
    return al.toArray(strArray);
}

From source file:Main.java

public static String getBuildVersionRelease() {
    String version = "";
    try {/*from  w  w w .j  a v  a 2  s.  co  m*/
        String release = Build.VERSION.RELEASE;
        StringTokenizer st = new StringTokenizer(release, ".");
        boolean first = true;
        while (st.hasMoreElements()) {
            String number = st.nextToken();
            if (number != null)
                number = number.substring(0, 1);
            version = (first) ? number : version + "." + number;
            first = false;
        }
    } catch (Exception e) {
    }
    return version;
}

From source file:Main.java

public static void dumpParameters(Parameters parameters) {
    String flattened = parameters.flatten();
    StringTokenizer tokenizer = new StringTokenizer(flattened, ";");
    Log.d(TAG, "Dump all camera parameters:");
    while (tokenizer.hasMoreElements()) {
        Log.d(TAG, tokenizer.nextToken());
    }/*from  ww  w  . j a va 2  s. c om*/
}

From source file:Main.java

private static String[] parseCommandStr(String str) {
    StringTokenizer st = new StringTokenizer(str, "|");
    String[] command_arr = new String[st.countTokens()];
    int i = 0;/*from  w w w  .  j a v a  2s. c o m*/
    while (st.hasMoreElements()) {

        command_arr[i] = (String) st.nextElement();
        i++;
    }
    return command_arr;
}

From source file:Main.java

private static String[] setPlacesToWatch(String placeWatch) {

    String[] places = { "" };
    if (placeWatch != null && !placeWatch.equals("")) {
        StringTokenizer tok = new StringTokenizer(placeWatch, ",");
        List<String> l = new ArrayList<String>();
        while (tok.hasMoreElements()) {
            l.add(tok.nextToken().toString());
        }/*  ww  w .  ja  v a 2  s.  c o  m*/
        if (!l.isEmpty()) {
            //Object[] o = l.toArray();
            places = new String[l.size()];// (String[])o;
            int idx = 0;
            for (String s : l) {
                places[idx++] = s;
            }
        }

    }
    return places;
}

From source file:org.vedantatree.expressionoasis.utils.StringUtils.java

/**
 * Gets the last token for spcefied dlimiter and string.
 * /*  w  ww  .j av a2s .  co  m*/
 * @param value the string to parse
 * @param delimiter the delimiter used for parsing.
 * @return
 */
public final static String getLastToken(String value, String delimiter) {
    String result = null;
    StringTokenizer tokenizer = new StringTokenizer(value, delimiter);
    while (tokenizer.hasMoreElements()) {
        result = (String) tokenizer.nextElement();
    }
    return result;
}

From source file:Main.java

/**
 * Build schema location map of schemas used in given
 * <code>schemaLocationAttribute</code> and adds them to the given
 * <code>schemaLocationMap</code>.
 * //w w  w  . j  a v a 2 s. c  o m
 * @see <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">XML Schema
 *      Part 0: Primer Second Edition | 5.6 schemaLocation</a>
 * 
 * @param schemaLocationMap
 *          {@link Map} to add schema locations to.
 * @param schemaLocation
 *          attribute value to build schema location map from.
 * @return {@link Map} of schema namespace URIs to location URLs.
 * @since 8.1
 */
static final Map<String, List<String>> buildSchemaLocationMap(Map<String, List<String>> schemaLocationMap,
        final String schemaLocation) {
    if (null == schemaLocation) {
        return schemaLocationMap;
    }

    if (null == schemaLocation || schemaLocation.isEmpty()) {
        // should really ever be null but being safe.
        return schemaLocationMap;
    }

    final StringTokenizer st = new StringTokenizer(schemaLocation, " \n\t\r");
    while (st.hasMoreElements()) {
        final String ns = st.nextToken();
        final String loc = st.nextToken();
        List<String> locs = schemaLocationMap.get(ns);
        if (null == locs) {
            locs = new ArrayList<>();
            schemaLocationMap.put(ns, locs);
        }
        if (!locs.contains(loc)) {
            locs.add(loc);
        }
    }

    return schemaLocationMap;
}

From source file:org.genemania.util.GeneManiaStringUtils.java

public static List<Long> networksStringToList(String networkIdStr) {
    List<Long> ret = new ArrayList<Long>();
    StringTokenizer st = new StringTokenizer(networkIdStr, Constants.NETWORK_IDS_SEPARATOR);
    while (st.hasMoreElements()) {
        String nextNetworkId = st.nextToken();
        try {/*w w w  . ja  v  a  2  s .c  om*/
            ret.add(Long.parseLong(nextNetworkId));
        } catch (NumberFormatException e) {
            LOG.warn("Invalid network ID: " + nextNetworkId);
        }
    }
    return ret;
}

From source file:gsn.storage.SQLUtils.java

public static String getTableName(String query) {
    String q = SQLValidator.removeSingleQuotes(SQLValidator.removeQuotes(query)).toLowerCase();
    StringTokenizer tokens = new StringTokenizer(q, " ");
    while (tokens.hasMoreElements())
        if (tokens.nextToken().equalsIgnoreCase("from") && tokens.hasMoreTokens())
            return tokens.nextToken();
    return null;/*from   ww  w .j  a v a  2 s .  co m*/
}