Example usage for java.util StringTokenizer countTokens

List of usage examples for java.util StringTokenizer countTokens

Introduction

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

Prototype

public int countTokens() 

Source Link

Document

Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.

Usage

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

public static Map deformatUrlResponse(String payload) throws Exception {
    HashMap nvp = new HashMap();
    StringTokenizer stTok = new StringTokenizer(payload, "&");
    while (stTok.hasMoreTokens()) {
        StringTokenizer stInternalTokenizer = new StringTokenizer(stTok.nextToken(), "=");
        if (stInternalTokenizer.countTokens() == 2) {
            String key = URLDecoder.decode(stInternalTokenizer.nextToken(), "UTF-8");
            String value = URLDecoder.decode(stInternalTokenizer.nextToken(), "UTF-8");
            nvp.put(key.toUpperCase(), value);
        }/*ww w  .j  a va  2  s  .c o m*/
    }
    return nvp;
}

From source file:Main.java

public static int[] getIntArray(Context ctx, String prefsKey, String key) {
    StringTokenizer st = new StringTokenizer(
            (TextUtils.isEmpty(prefsKey) ? getPrefManager(ctx) : getPrefs(ctx, prefsKey)).getString(key, ""),
            ",");
    int[] savedList = new int[st.countTokens()];
    for (int i = 0; i < savedList.length; i++) {
        savedList[i] = Integer.parseInt(st.nextToken());
    }//from  w  w  w .j  a  va  2  s .  c  o m
    return savedList;
}

From source file:com.groupon.odo.proxylib.Utils.java

/**
 * Split string of comma-delimited ints into an a int array
 *
 * @param str//from  www.ja  v  a2s  .  c o  m
 * @return
 * @throws IllegalArgumentException
 */
public static int[] arrayFromStringOfIntegers(String str) throws IllegalArgumentException {
    StringTokenizer tokenizer = new StringTokenizer(str, ",");
    int n = tokenizer.countTokens();
    int[] list = new int[n];
    for (int i = 0; i < n; i++) {
        String token = tokenizer.nextToken();
        list[i] = Integer.parseInt(token);
    }
    return list;
}

From source file:net.naijatek.myalumni.util.utilities.MailUtil.java

/**
 * This method trim the email variable, so if it contains only spaces, then
 * it will be empty string, then we have 0 token :-) The returned value is
 * never null//from w w  w .j av a2 s .co  m
 *
* @param email String
* @throws BadInputException
* @return String[]
 */
private static String[] getEmails(String email) throws BadInputException {
    if (email == null) {
        email = "";
    }
    email = email.trim();// very important
    StringTokenizer t = new StringTokenizer(email, ";");
    String[] ret = new String[t.countTokens()];
    int index = 0;
    while (t.hasMoreTokens()) {
        String mail = t.nextToken().trim();
        checkGoodEmail(mail);
        ret[index] = mail;
        //log.debug(ret[index]);
        index++;
    }
    return ret;
}

From source file:Main.java

/**
 * /*from   ww w. j a v  a  2s  .  c o m*/
 * @param value
 * @return double[][]
 */
public static double[][] to2dDoubleArray(final String value) {
    final String strippedValue = value.replace(ARRAY_OPEN_TAG, EMPTY_STRING).replace(ARRAY_CLOSE_TAG,
            EMPTY_STRING);
    final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ARRAY_SEPARATOR);
    final double[][] array = new double[tokenizer.countTokens()][];
    int i = 0;

    while (tokenizer.hasMoreTokens()) {
        array[i++] = toDoubleArray(tokenizer.nextToken());
    }

    return array;
}

From source file:com.zuoxiaolong.niubi.job.persistent.hibernate.HibernateNamingStrategy.java

private static String[] splitName(String someName) {
    StringTokenizer tokenizer = new StringTokenizer(someName, SEPARATOR);
    String[] tokens = new String[tokenizer.countTokens()];
    int i = 0;/*from   w  ww  .  j  a  v a2  s  . co m*/
    while (tokenizer.hasMoreTokens()) {
        tokens[i] = tokenizer.nextToken();
        i++;
    }
    return tokens;
}

From source file:com.apporiented.hermesftp.utils.IOUtils.java

/**
 * Tries to figure out the application's home directory.
 * /*from w w  w .j a  va  2s  .  com*/
 * @return The directory.
 */
public static File getHomeDir() {
    File result = null;
    String cp = System.getProperty("java.class.path");
    StringTokenizer tokenizer = new StringTokenizer(cp, File.pathSeparator);
    if (tokenizer.countTokens() == 1) {
        File jar = new File(tokenizer.nextToken());
        try {
            result = jar.getCanonicalFile().getParentFile().getParentFile();
        } catch (IOException e) {
        }
    } else {
        File userDir = new File(System.getProperty("user.dir"));
        result = userDir.getAbsoluteFile().getParentFile();
    }
    return result;
}

From source file:de.elbe5.base.util.StringUtil.java

public static String toHtmlText(String src) {
    if (src == null) {
        return "";
    }//from   www.  j av  a 2  s  . c om
    if (src.indexOf('\n') == -1)
        return StringEscapeUtils.escapeHtml4(src);

    StringTokenizer stk = new StringTokenizer(src, "\n", true);
    if (stk.countTokens() == 0)
        return "";
    StringBuilder sb = new StringBuilder();
    String token;
    while (stk.hasMoreTokens()) {
        token = stk.nextToken();
        if (token.equals("\n"))
            sb.append("\n<br/>\n");
        else
            sb.append(StringEscapeUtils.escapeHtml4(token));
    }
    return sb.toString();
}

From source file:org.alfresco.web.bean.ajax.FileUploadBean.java

static NodeRef pathToNodeRef(FacesContext fc, String path) {
    // convert cm:name based path to a NodeRef
    StringTokenizer t = new StringTokenizer(path, "/");
    int tokenCount = t.countTokens();
    String[] elements = new String[tokenCount];
    for (int i = 0; i < tokenCount; i++) {
        elements[i] = t.nextToken();/*from  w  w  w. j  a  v a  2s .  c o m*/
    }
    return BaseServlet.resolveWebDAVPath(fc, elements, false);
}

From source file:org.projecthdata.social.api.connect.HDataServiceProvider.java

private static StringBuilder getBaseUrl(String ehrUrl) {
    URI uri = URIBuilder.fromUri(ehrUrl).build();
    StringBuilder builder = new StringBuilder();
    builder.append(uri.getScheme()).append("://");
    builder.append(uri.getHost());//w ww  .ja v  a 2 s .c om
    if (uri.getPort() >= 0) {
        builder.append(":").append(uri.getPort());
    }
    if (uri.getPath() != null) {
        StringTokenizer tokenizer = new StringTokenizer(uri.getPath(), "/");
        // if there is more than one path element, then the first one should
        // be the webapp name
        if (tokenizer.countTokens() > 1) {
            builder.append("/").append(tokenizer.nextToken());
        }
    }
    return builder;
}