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:org.pdfgal.pdfgalweb.services.impl.SplitServiceImpl.java

/**
 * This method splits the file, each new file will start at each one of the
 * pages.//ww  w.  j a va  2  s.c  om
 * 
 * @param file
 * @param pages
 * @return The list of URIs where files are saved.
 * @throws NumberFormatException
 * @throws IOException
 * @throws COSVisitorException
 */
private List<String> splitConcretePages(final MultipartFile file, final String pages, final String inputUri,
        final String outputUri) throws NumberFormatException, COSVisitorException, IOException {

    final List<Integer> pagesList = new ArrayList<Integer>();

    final StringTokenizer stringTokenizer = new StringTokenizer(pages, ",");

    while (stringTokenizer.hasMoreElements()) {
        pagesList.add(Integer.parseInt((String) stringTokenizer.nextElement()));
    }

    // File is splitted
    return this.pdfGal.split(inputUri, outputUri, pagesList);
}

From source file:org.pdfgal.pdfgalweb.services.impl.WatermarkServiceImpl.java

/**
 * Gets the pages from a string with tokens.
 * //from   w w  w.  j a v a2s .  c  o m
 * @param pages
 * @return
 */
private List<Integer> getPages(final String pages) {

    final List<Integer> result = new ArrayList<Integer>();

    final StringTokenizer st = new StringTokenizer(pages, ",");

    while (st.hasMoreElements()) {

        final String token = (String) st.nextElement();

        try {
            final Integer page = Integer.parseInt(token);
            result.add(page);

        } catch (final Exception e) {

            final StringTokenizer secondSt = new StringTokenizer(token, "-");
            if (secondSt.countTokens() != 2) {
                throw new IllegalArgumentException();
            }

            final String secondTokenFirst = (String) secondSt.nextElement();
            final String secondTokenLast = (String) secondSt.nextElement();
            try {
                final Integer firstPage = Integer.parseInt(secondTokenFirst);
                final Integer lastPage = Integer.parseInt(secondTokenLast);
                for (int i = firstPage; i <= lastPage; i++) {
                    result.add(i);
                }

            } catch (final Exception e2) {
                throw new IllegalArgumentException();
            }
        }
    }

    return result;
}

From source file:org.xwiki.rendering.internal.macro.script.DefaultAttachmentClassLoaderFactory.java

/**
 * @param jarURLs the comma-separated list of JARs locations, specified using either an already registered
 *        protocol (such as {@code http}) or using the format {@code attach:(wiki):(space).(page)@(filename)}.
 * @return the list of URIs//from  ww  w.  j ava 2  s  .c om
 * @throws URISyntaxException in case of an invalid URI 
 */
private Set<URI> extractURIs(String jarURLs) throws URISyntaxException {
    // Parse the passed JAR URLs to tokenize it.
    Set<URI> uris = new LinkedHashSet<URI>();
    if (StringUtils.isNotEmpty(jarURLs)) {
        StringTokenizer tokenizer = new StringTokenizer(jarURLs, ",");
        while (tokenizer.hasMoreElements()) {
            String token = tokenizer.nextToken().trim();
            if (token.startsWith(ATTACHMENT_PREFIX)) {
                uris.add(createURI(token));
            } else {
                uris.add(new URI(token));
            }
        }
    }

    return uris;
}

From source file:io.hops.leaderElection.experiments.ExperimentDriver.java

private void calculateNumbers(int numProcesses, String outputFileName)
        throws FileNotFoundException, IOException {
    if (!new File(outputFileName).exists()) {
        LOG.error("File " + outputFileName + " does not exists");
        return;//from  www.j a  v a 2 s  .c o  m
    }
    String marker = "DataPoints: ";
    String line;
    DescriptiveStatistics failOverStats = new DescriptiveStatistics();
    DescriptiveStatistics tpStats = new DescriptiveStatistics();
    BufferedReader br = new BufferedReader(new FileReader(outputFileName));
    while ((line = br.readLine()) != null) {
        if (!line.startsWith(marker)) {
            continue;
        }

        boolean tpStatRecorded = false;
        String numbers = line.substring(marker.length(), line.length());
        StringTokenizer st = new StringTokenizer(numbers, ",[] ");
        while (st.hasMoreElements()) {
            double point = Double.parseDouble(st.nextToken());
            if (!tpStatRecorded) {
                tpStats.addValue(point);
                tpStatRecorded = true;
            } else {
                failOverStats.addValue(point);
            }
        }
    }
    br.close();
    writeMessageToFile(numProcesses, failOverStats, tpStats);

}

From source file:com.todev.rabbitmqmanagement.data.network.serialization.UserTagsDeserializer.java

@Override
public List<User.Tag> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    String serialized = p.getText().trim();
    StringTokenizer tokenizer = new StringTokenizer(serialized, ",");
    List<User.Tag> result = new ArrayList<>();
    User.Tag tag = User.Tag.NONE;//from w  w w  .  ja v a  2  s. com

    while (tokenizer.hasMoreElements()) {
        String token = tokenizer.nextToken();

        try {
            tag = User.Tag.valueOf(token.toUpperCase());
        } catch (IllegalArgumentException e) {
            // Leave none type as default.
        }

        if (!result.contains(tag)) {
            result.add(tag);
        }
    }

    return result;
}

From source file:com.liusoft.dlog4j.velocity.DLOG_Music_VelocityTool.java

/**
 * ?/*from w  w  w  .j  av  a2s .c o  m*/
 * @param mids
 * @return
 */
public List list_songs(String mids) {
    if (mids == null)
        return null;
    StringTokenizer st = new StringTokenizer(mids, ",");
    List ids = new ArrayList();
    while (st.hasMoreElements()) {
        String sid = st.nextToken();
        try {
            ids.add(new Integer(sid));
        } catch (Exception e) {
        }
    }
    return MusicDAO.listSongs(ids);
}

From source file:com.chinamobile.bcbsp.examples.bytearray.pagerank.PRVertexLiteNew.java

@Override
public void fromString(String vertexData) throws Exception {
    String[] buffer = new String[2];
    StringTokenizer str = new StringTokenizer(vertexData, Constants.KV_SPLIT_FLAG);
    if (str.hasMoreElements()) {
        buffer[0] = str.nextToken();//from   w  ww  .  j a  v a2s .  c om
    } else {
        throw new Exception();
    }
    if (str.hasMoreElements()) {
        buffer[1] = str.nextToken();
    }
    str = new StringTokenizer(buffer[0], Constants.SPLIT_FLAG);
    if (str.countTokens() != 2) {
        throw new Exception();
    }
    this.vertexID = Integer.valueOf(str.nextToken());
    this.vertexValue = Float.valueOf(str.nextToken());
    if (buffer[1].length() > 0) { // There has edges.
        str = new StringTokenizer(buffer[1], Constants.SPACE_SPLIT_FLAG);
        while (str.hasMoreTokens()) {
            PREdgeLiteNew edge = new PREdgeLiteNew();
            edge.fromString(str.nextToken());
            this.edgesList.add(edge);
        }
    }
}

From source file:org.apache.jcs.access.monitor.MonitorAccess.java

/**
 * Removes all.//from w  w  w  .  j  av  a2 s  .  c  o m
 * <p>
 * @param cacheName
 * @param key
 * @return an informative message about what was deleted.
 */
public String delete(String cacheName, String key) {
    // some junk to return for a synchronous call
    String result = "";

    try {
        ICache cache = this.cacheMgr.getCache(cacheName);

        if (key != null) {
            if (key.toUpperCase().equals("ALL")) {
                cache.removeAll();

                if (log.isDebugEnabled()) {
                    log.debug("Removed all elements from " + cacheName);
                }
                result = "key = " + key;
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("key = " + key);
                }
                result = "key = " + key;
                StringTokenizer toke = new StringTokenizer(key, "_");

                while (toke.hasMoreElements()) {
                    String temp = (String) toke.nextElement();
                    cache.remove(key);

                    if (log.isDebugEnabled()) {
                        log.debug("Removed " + temp + " from " + cacheName);
                    }
                }
            }
        } else {
            result = "key is null";
        }

    } catch (Exception e) {
        log.error(e);
    }

    return result;
}

From source file:gtu._work.ui.StringArrayMakerUI.java

private void jButton1ActionPerformed(ActionEvent evt) {
    try {/* ww  w  .  ja va2s.c  o  m*/
        DefaultListModel model = JListUtil.createModel();
        String text = ClipboardUtil.getInstance().getContents();
        Validate.notEmpty(text, "");
        StringBuilder pattern = new StringBuilder();
        if (jCheckBox1.isSelected()) {
            pattern.append("\n");
        }
        if (jCheckBox2.isSelected()) {
            pattern.append("\t");
        }
        StringTokenizer tok = new StringTokenizer(text, pattern.toString());
        while (tok.hasMoreElements()) {
            String val = (String) tok.nextElement();
            model.addElement(val);
        }
        jList1.setModel(model);
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}

From source file:org.apache.sling.testing.junit.rules.util.IgnoreTestsConfig.java

private IgnoreTestsConfig() {
    for (int i = 0; i <= numberOfIgnoreLists; i++) {
        StringTokenizer st = new StringTokenizer(System.getProperty(IGNORE_LIST_PROP, ""), ",");
        while (st.hasMoreElements()) {
            String token = st.nextToken();
            String[] pair = token.split(":");

            // Split by ":" and get the ignore (partial) java FQDN and a reason
            // Ex: org.apache.sling.tests.*:SLING-4242
            //     org.apache.sling.tests.MyTest:SLING-555
            String ignoreToken = (pair.length > 0) ? pair[0] : "";
            String reason = (pair.length > 1) ? pair[1] : "";

            // Add to ignore token map
            ignoreTokens.put(ignoreToken.trim(), reason.trim());
        }/*from   w  w w.j a  va  2 s .  c o  m*/
    }
    this.runIgnoreList = System.getProperty(RUN_IGNORE_LIST_PROP) != null;
}