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.bizosys.dataservice.util.StringUtils.java

/**
 * returns an arraylist of strings  //from  w w w .  j  a  v a 2s.  co m
 * @param str the delimiter seperated string values
 * @param delimiter
 * @return the arraylist of the comma seperated string values
 */
public static String[] getStrings(String str, String delimiter) {
    if (isEmpty(str))
        return null;
    StringTokenizer tokenizer = new StringTokenizer(str, delimiter);
    List<String> values = new ArrayList<String>();
    while (tokenizer.hasMoreTokens()) {
        values.add(tokenizer.nextToken());
    }
    return (String[]) values.toArray(new String[values.size()]);
}

From source file:Arguments.java

/**
 * Make an ordered list of Strings based on the input, none of which is longer than the given
 * length. It assumes the String is broken up by spaces. This is helpful when printing blocks of
 * text that can not be too long.//from  w  ww .  jav  a2 s .  com
 */
private static List<String> restricLineLength(String in, int length) {
    List<String> ret = new ArrayList<String>();
    StringBuilder buf = new StringBuilder();
    if (in != null) {
        StringTokenizer toks = new StringTokenizer(in);
        while (toks.hasMoreTokens()) {
            String tok = toks.nextToken();
            if (buf.length() + tok.length() < length) {
                buf.append(" " + tok);
            } else {
                ret.add(buf.toString().trim());
                buf.setLength(0);
                buf.append(tok);
            }
        }
        if (buf.length() > 0) {
            ret.add(buf.toString().trim());
        }
    }
    return ret;
}

From source file:com.basho.riak.client.http.util.ClientUtils.java

/**
 * Extract X-Riak-Index-* headers and create {@link List} of
 * {@link RiakIndex}es from them//w w  w  .  j a va  2s.com
 * 
 * @param headers
 *            The full HTTP headers from the response
 * @return a List of RiakIndexs
 */
@SuppressWarnings("rawtypes")
public static List<RiakIndex> parseIndexHeaders(Map<String, String> headers) {
    final List<RiakIndex> indexes = new ArrayList<RiakIndex>();
    if (headers != null) {
        for (Entry<String, String> e : headers.entrySet()) {
            String header = e.getKey();
            if (header != null && header.toLowerCase().startsWith(Constants.HDR_SEC_INDEX_PREFIX)) {
                String name = header.substring(Constants.HDR_SEC_INDEX_PREFIX.length());
                String value = e.getValue();
                StringTokenizer st = new StringTokenizer(value, COMMA);

                if (name.endsWith(BinIndex.SUFFIX)) {
                    while (st.hasMoreTokens()) {
                        indexes.add(new BinIndex(name, st.nextToken().trim()));
                    }
                } else if (name.endsWith(IntIndex.SUFFIX)) {
                    while (st.hasMoreElements()) {
                        indexes.add(new IntIndex(name, Long.parseLong(st.nextToken().trim())));
                    }
                }
            }
        }
    }
    return indexes;
}

From source file:com.jaspersoft.studio.server.WSClientHelper.java

private static void addDataSource(MServerProfile sp, ResourceDescriptor r) {
    String url = r.getUriString();
    StringTokenizer st = new StringTokenizer(url, "/");
    String turl = "/";
    ANode parent = sp;//  w w  w  .  java  2  s.  c o m
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        String sf = turl + token;
        if (sf.equals(url)) {
            ResourceFactory.getResource(parent, r, -1);
            break;
        }
        MResource child = null;
        for (INode node : parent.getChildren()) {
            if (node instanceof MResource) {
                MResource mr = (MResource) node;
                if (mr.getValue().getUriString().equals(sf)) {
                    child = mr;
                    break;
                }
            }
        }
        if (child == null) {
            ResourceDescriptor rd = new ResourceDescriptor();
            rd.setName(token);
            rd.setLabel(token);
            rd.setUriString(sf);
            rd.setWsType(ResourceDescriptor.TYPE_FOLDER);
            child = ResourceFactory.getResource(parent, rd, -1);
            child.removeChildren();
        }
        parent = child;
        turl = sf + "/";
    }

}

From source file:com.sun.faban.harness.webclient.ResultAction.java

/**
 * This method is responsible for uploading the runs to repository.
 * @param uploadSet/*from  www  . j a v a  2  s. co m*/
 * @param replaceSet
 * @return HashSet
 * @throws java.io.IOException
 */
public static HashSet<String> uploadRuns(String[] runIds, HashSet<File> uploadSet, HashSet<String> replaceSet)
        throws IOException {
    // 3. Upload the run
    HashSet<String> duplicates = new HashSet<String>();

    // Prepare run id set for cross checking.
    HashSet<String> runIdSet = new HashSet<String>(runIds.length);
    for (String runId : runIds) {
        runIdSet.add(runId);
    }

    // Prepare the parts for the request.
    ArrayList<Part> params = new ArrayList<Part>();
    params.add(new StringPart("host", Config.FABAN_HOST));
    for (String replaceId : replaceSet) {
        params.add(new StringPart("replace", replaceId));
    }
    for (File jarFile : uploadSet) {
        params.add(new FilePart("jarfile", jarFile));
    }
    Part[] parts = new Part[params.size()];
    parts = params.toArray(parts);

    // Send the request for each reposotory.
    for (URL repository : Config.repositoryURLs) {
        URL repos = new URL(repository, "/controller/uploader/upload_runs");
        PostMethod post = new PostMethod(repos.toString());
        post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));

        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        int status = client.executeMethod(post);

        if (status == HttpStatus.SC_FORBIDDEN)
            logger.warning("Server denied permission to upload run !");
        else if (status == HttpStatus.SC_NOT_ACCEPTABLE)
            logger.warning("Run origin error!");
        else if (status != HttpStatus.SC_CREATED)
            logger.warning(
                    "Server responded with status code " + status + ". Status code 201 (SC_CREATED) expected.");
        for (File jarFile : uploadSet) {
            jarFile.delete();
        }

        String response = post.getResponseBodyAsString();

        if (status == HttpStatus.SC_CREATED) {

            StringTokenizer t = new StringTokenizer(response.trim(), "\n");
            while (t.hasMoreTokens()) {
                String duplicateRun = t.nextToken().trim();
                if (duplicateRun.length() > 0)
                    duplicates.add(duplicateRun.trim());
            }

            for (Iterator<String> iter = duplicates.iterator(); iter.hasNext();) {
                String runId = iter.next();
                if (!runIdSet.contains(runId)) {
                    logger.warning("Unexpected archive response from " + repos + ": " + runId);
                    iter.remove();
                }
            }
        } else {
            logger.warning("Message from repository: " + response);
        }
    }
    return duplicates;
}

From source file:eionet.cr.web.action.admin.harvestscripts.HarvestScriptParser.java

/**
 *
 * @param str/*from w  w w .ja v  a2 s .c  o  m*/
 * @param token
 * @return
 */
public static boolean containsToken(String str, String token) {

    if (str == null || str.trim().length() == 0 || token == null || token.trim().length() == 0) {
        return false;
    }

    StringTokenizer st = new StringTokenizer(str, " \t\n\r\f", true);
    ArrayList<String> upperCaseTokens = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String nextToken = st.nextToken();
        upperCaseTokens.add(nextToken.toUpperCase());
    }

    return upperCaseTokens.contains(token.toUpperCase());
}

From source file:gate.DocumentFormat.java

/**
  * Return the fileSuffix or null if the url doesn't have a file suffix
  * If the url is null then the file suffix will be null also
  *//*ww w.j  a v a 2s .  co  m*/
@SuppressWarnings("unused")
private static String getFileSuffix(URL url) {
    String fileName = null;
    String fileSuffix = null;

    // GIGO test  (garbage in garbage out)
    if (url != null) {
        // get the file name from the URL
        fileName = url.getFile();

        // tokenize this file name with "." as separator...
        // the last token will be the file suffix
        StringTokenizer st = new StringTokenizer(fileName, ".");

        // fileSuffix is the last token
        while (st.hasMoreTokens())
            fileSuffix = st.nextToken();
        // here fileSuffix is the last token
    } // End if
    return fileSuffix;
}

From source file:net.jradius.packet.attribute.AttributeFactory.java

public static void loadAttributesFromString(AttributeList list, String src, String delim, boolean beStrinct)
        throws RadiusException {
    StringTokenizer st = new StringTokenizer(src, delim);
    while (st.hasMoreTokens()) {
        try {/*from   www .j ava  2s . c  om*/
            list.add(attributeFromString(st.nextToken()));
        } catch (RadiusException e) {
            if (beStrinct)
                throw (e);
        }
    }
}

From source file:com.sfs.DataFilter.java

/**
 * Parse the user's search box input into a Set of String tokens.
 *
 * @param searchText the search text//w  w  w  .j  ava  2s.  co m
 *
 * @return Set of Strings, one for each word in searchText; here "word" is
 *         defined as either a lone word surrounded by whitespace, or as a
 *         series of words surrounded by double quotes, "like this"; also,
 *         very common words (and, the, etc.) do not qualify as possible
 *         search targets.
 */
public static HashSet<String> parseSearchText(final String searchText) {
    HashSet<String> result = new HashSet<String>();

    boolean returnTokens = true;
    String currentDelims = WHITESPACE_AND_QUOTES;
    StringTokenizer parser = new StringTokenizer(searchText, currentDelims, returnTokens);

    String token = null;
    while (parser.hasMoreTokens()) {
        token = parser.nextToken(currentDelims);
        if (!isDoubleQuote(token)) {
            addNonTrivialWordToResult(token, result);
        } else {
            currentDelims = flipDelimiters(currentDelims);
        }
    }
    return result;
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagUtil.java

/**
 * Parses a list of style classes into a string array
 * @param styles list of style classes separated by "|"
 * @return array of sytles//w ww . j a va  2 s  .co  m
 */
public static String[] parseStyles(String styles) {
    List tmp = new LinkedList();
    StringTokenizer strtok = new StringTokenizer(styles, "|");
    while (strtok.hasMoreTokens()) {
        tmp.add(strtok.nextToken().trim());
    }
    String[] retval = null;
    if (tmp.size() == 0) {
        retval = new String[0];
    } else {
        retval = new String[tmp.size()];
        tmp.toArray(retval);
    }
    return retval;
}