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:com.adaptris.mail.Pop3sReceiverFactory.java

private static String[] asArray(String s) {
    StringTokenizer st = new StringTokenizer(s, ",");
    List<String> l = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String tok = st.nextToken().trim();
        if (!isEmpty(tok))
            l.add(tok);/*from   ww w. ja  v a  2s  .  c om*/
    }
    return l.toArray(new String[0]);
}

From source file:cn.com.sunjiesh.xcutils.common.VersionUtil.java

/**
 * //w  w w  .  j a  va 2s .co m
 * @param version1
 * @param version2
 * @return
 */
public static int compareVersion(String version1, String version2) {

    StringTokenizer version1Tokenizer = new StringTokenizer(version1, ".");
    StringTokenizer version2Tokenizer = new StringTokenizer(version2, ".");
    if (version1.equals(version2)) {
        return 0;
    } else {
        while (version1Tokenizer.hasMoreTokens() && version2Tokenizer.hasMoreTokens()) {
            String version1Token = version1Tokenizer.nextToken();
            String Version2Token = version2Tokenizer.nextToken();
            if (StringUtils.isNotBlank(version1Token)) {
                version1Token = version1Token.replace("-", "");
            }
            if (StringUtils.isNotBlank(Version2Token)) {
                Version2Token = Version2Token.replace("-", "");
            }
            if (StringUtils.isNotBlank(version1Token)) {
                version1Token = version1Token.replace("0", "");
                if (version1Token.equals("")) {
                    version1Token = "0";
                }
            }
            if (StringUtils.isNotBlank(Version2Token)) {
                Version2Token = Version2Token.replace("0", "");
                if (Version2Token.equals("")) {
                    Version2Token = "0";
                }
            }
            if (NumberUtils.isDigits(version1Token) && NumberUtils.isDigits(Version2Token)) {//???
                if (Integer.parseInt(version1Token) < Integer.parseInt(Version2Token)) {
                    return -1;
                }
                if (Integer.parseInt(version1Token) > Integer.parseInt(Version2Token)) {
                    return 1;
                }
            }
        }
    }
    return 0;
}

From source file:de.micromata.genome.gwiki.page.impl.actionbean.GWikiErrorsTag.java

/**
 * Verwendet einen StringTokenizer und liefert das Ergebnis als Liste
 *//*from w ww  .  jav a2s. com*/
public static List<String> parseStringTokens(String text, String delimiter, boolean returnDelimiter) {
    List<String> result = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(text, delimiter, returnDelimiter);
    while (st.hasMoreTokens() == true) {
        result.add(st.nextToken());
    }
    return result;
}

From source file:de.mpg.imeji.presentation.util.LoginHelper.java

/**
 * Get handle of System administrator of eSciDoc instance.
 * /*from   www  . ja va 2s  .  c  om*/
 * @return
 */
//    public static String loginSystemAdmin()
//    {
//        String handle = null;
//        try
//        {
//            handle = login(PropertyReader.getProperty("framework.admin.username"),
//                    PropertyReader.getProperty("framework.admin.password"));
//        }
//        catch (Exception e)
//        {
//            sessionBean = (SessionBean)BeanHelper.getSessionBean(SessionBean.class);
//            BeanHelper
//                    .info(sessionBean.getLabel("error") + ", wrong administrator user. Check config file or FW: " + e);
//            logger.error("Error escidoc admin login", e);
//        }
//        return handle;
//    }

public static String login(String userName, String password) throws Exception {
    String frameworkUrl = PropertyReader.getProperty("escidoc.framework_access.framework.url");
    StringTokenizer tokens = new StringTokenizer(frameworkUrl, "//");
    tokens.nextToken();
    StringTokenizer hostPort = new StringTokenizer(tokens.nextToken(), ":");
    String host = hostPort.nextToken();
    int port = 80;
    if (hostPort.hasMoreTokens()) {
        port = Integer.parseInt(hostPort.nextToken());
    }
    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().closeIdleConnections(1000);
    client.getHostConfiguration().setHost(host, port, "http");
    client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    PostMethod login = new PostMethod(frameworkUrl + "/aa/j_spring_security_check");
    login.addParameter("j_username", userName);
    login.addParameter("j_password", password);
    try {
        client.executeMethod(login);
    } catch (Exception e) {
        throw new RuntimeException("Error login in " + frameworkUrl + "  status: " + login.getStatusCode()
                + " - " + login.getStatusText());
    }
    login.releaseConnection();
    CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
    Cookie[] logoncookies = cookiespec.match(host, port, "/", false, client.getState().getCookies());
    Cookie sessionCookie = logoncookies[0];
    PostMethod postMethod = new PostMethod("/aa/login");
    postMethod.addParameter("target", frameworkUrl);
    client.getState().addCookie(sessionCookie);
    client.executeMethod(postMethod);
    if (HttpServletResponse.SC_SEE_OTHER != postMethod.getStatusCode()) {
        throw new HttpException("Wrong status code: " + postMethod.getStatusCode());
    }
    String userHandle = null;
    Header headers[] = postMethod.getResponseHeaders();
    for (int i = 0; i < headers.length; ++i) {
        if ("Location".equals(headers[i].getName())) {
            String location = headers[i].getValue();
            int index = location.indexOf('=');
            userHandle = new String(Base64.decode(location.substring(index + 1, location.length())));
        }
    }
    if (userHandle == null) {
        throw new ServiceException("User not logged in.");
    }
    return userHandle;
}

From source file:SplitPaneDemo2.java

protected static Vector parseList(String theStringList) {
    Vector v = new Vector(10);
    StringTokenizer tokenizer = new StringTokenizer(theStringList, " ");
    while (tokenizer.hasMoreTokens()) {
        String image = tokenizer.nextToken();
        v.addElement(image);/*from   w  ww  .  ja va 2s. c om*/
    }
    return v;
}

From source file:com.twitter.hbc.example.FilterStreamExample.java

public static String classifyText(String msg) {

    //Delimeters need to be further extended.
    StringTokenizer st = new StringTokenizer(msg, "[,. #]+");
    int positive = 0, negative = 0, neutral = 0;
    while (st.hasMoreTokens()) {
        String next = st.nextToken().toLowerCase();
        //System.out.println(next);
        positive += (positiveList.contains(next) ? 1 : 0);
        negative += (negativeList.contains(next) ? 1 : 0);

        //See whether neutral adds any value, TODO -
        if (!positiveList.contains(next) && !negativeList.contains(next))
            neutral += (positiveList.contains(next) ? 1 : 0);
    }/*from w w  w  .  j  av a 2s  .com*/
    return (positive == negative) ? "Neutral" : ((positive > negative) ? "Positive" : "Negative");
}

From source file:com.lily.dap.web.util.WebUtils.java

/**
 *  If-None-Match Header,Etag.//from   w w  w  .  j a v a 2 s .co m
 * 
 * Etag,checkIfNoneMatchfalse, 304 not modify status.
 */
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response,
        String etag) {
    String headerValue = request.getHeader("If-None-Match");
    if (headerValue != null) {
        boolean conditionSatisfied = false;
        if (!headerValue.equals("*")) {
            StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ",");

            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(etag)) {
                    conditionSatisfied = true;
                }
            }
        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.setHeader("ETag", etag);
            return false;
        }
    }
    return true;
}

From source file:kr.co.exsoft.eframework.util.LicenseUtil.java

private static byte[] getBytes(String str) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    StringTokenizer st = new StringTokenizer(str, "-", false);

    while (st.hasMoreTokens()) {
        int i = Integer.parseInt(st.nextToken());
        bos.write((byte) i);
    }/*from   ww w.  j a  v  a  2  s  .c o  m*/

    return bos.toByteArray();
}

From source file:net.servicefixture.PluginManager.java

private static List<String[]> parsePluginValue(String value, int numOfTokens) {
    List<String[]> list = new ArrayList<String[]>();
    StringTokenizer pluginTokenizer = new StringTokenizer(value, PLUGIN_DELIMITER);
    while (pluginTokenizer.hasMoreTokens()) {
        String token = pluginTokenizer.nextToken();
        StringTokenizer tokenizer = new StringTokenizer(token, TOKEN_DELIMITER);
        String[] tokens = new String[tokenizer.countTokens()];
        if (tokens.length != numOfTokens) {
            throw new ServiceFixtureException("Invalid plugin value: " + value);
        }/* www . ja  va  2  s .  com*/
        for (int i = 0; i < tokens.length; i++) {
            tokens[i] = tokenizer.nextToken().trim();
        }
        list.add(tokens);
    }
    return list;
}

From source file:com.thruzero.common.core.utils.StringUtilsExt.java

/**
 * Converts the given token stream of keyValuePairs, using the given separator, into a StringMap. Leading and trailing spaces of the keys and values are
 * trimmed./* ww w. j  a v a2 s  .  c  o  m*/
 * <p>
 * Example input: "booleanTrue=true ,booleanFalse=false, integerOne=1,longOne=1234567890"
 */
public static StringMap tokensToMap(final String keyValuePairs, final String separator) {
    StringMap result = new StringMap();

    if (StringUtils.isNotEmpty(keyValuePairs)) {
        StringTokenizer st = new StringTokenizer(keyValuePairs, separator);

        while (st.hasMoreTokens()) {
            String token = st.nextToken();
            StringTokenizer st2 = new StringTokenizer(token, "=");

            result.put(StringUtils.trimToEmpty(st2.nextToken()),
                    st2.hasMoreTokens() ? StringUtils.trimToNull(st2.nextToken()) : null);
        }
    }

    return result;
}