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:Utilities.java

/** Construct a new key description from a given universal string
* description./*www  . j  av a 2s. c  o  m*/
* Provides mapping between Emacs-like textual key descriptions and the
* <code>KeyStroke</code> object used in Swing.
* <P>
* This format has following form:
* <P><code>[C][A][S][M]-<em>identifier</em></code>
* <p>Where:
* <UL>
* <LI> <code>C</code> stands for the Control key
* <LI> <code>A</code> stands for the Alt key
* <LI> <code>S</code> stands for the Shift key
* <LI> <code>M</code> stands for the Meta key
* </UL>
* The format also supports two wildcard codes, to support differences in
* platforms.  These are the preferred choices for registering keystrokes,
* since platform conflicts will automatically be handled:
* <UL>
* <LI> <code>D</code> stands for the default menu accelerator - the Control
*  key on most platforms, the Command (meta) key on Macintosh</LI>
* <LI> <code>O</code> stands for the alternate accelerator - the Alt key on
*  most platforms, the Ctrl key on Macintosh (Macintosh uses Alt as a
*  secondary shift key for composing international characters - if you bind
*  Alt-8 to an action, a mac user with a French keyboard will not be able
*  to type the <code>[</code> character, which is a significant handicap</LI>
* </UL>
* If you use the wildcard characters, and specify a key which will conflict
* with keys the operating system consumes, it will be mapped to whichever
* choice can work - for example, on Macintosh, Command-Q is always consumed
* by the operating system, so <code>D-Q</code> will always map to Control-Q.
* <p>
* Every modifier before the hyphen must be pressed.
* <em>identifier</EM> can be any text constant from {@link KeyEvent} but
* without the leading <code>VK_</code> characters. So {@link KeyEvent#VK_ENTER} is described as
* <code>ENTER</code>.
*
* @param s the string with the description of the key
* @return key description object, or <code>null</code> if the string does not represent any valid key
*/
public static KeyStroke stringToKey(String s) {
    StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), "-", true); // NOI18N

    int needed = 0;

    HashMap names = initNameAndValues()[0];

    int lastModif = -1;

    try {
        for (;;) {
            String el = st.nextToken();

            // required key
            if (el.equals("-")) { // NOI18N

                if (lastModif != -1) {
                    needed |= lastModif;
                    lastModif = -1;
                }

                continue;
            }

            // if there is more elements
            if (st.hasMoreElements()) {
                // the text should describe modifiers
                lastModif = readModifiers(el);
            } else {
                // last text must be the key code
                Integer i = (Integer) names.get(el);
                boolean wildcard = (needed & CTRL_WILDCARD_MASK) != 0;

                //Strip out the explicit mask - KeyStroke won't know
                //what to do with it
                needed = needed & ~CTRL_WILDCARD_MASK;

                boolean macAlt = (needed & ALT_WILDCARD_MASK) != 0;
                needed = needed & ~ALT_WILDCARD_MASK;

                if (i != null) {
                    //#26854 - Default accelerator should be Command on mac
                    if (wildcard) {
                        needed |= getMenuShortCutKeyMask();

                        if ((getOperatingSystem() & OS_MAC) != 0) {
                            if (!usableKeyOnMac(i.intValue(), needed)) {
                                needed &= ~getMenuShortCutKeyMask();
                                needed |= KeyEvent.CTRL_MASK;
                            }
                        }
                    }

                    if (macAlt) {
                        if (getOperatingSystem() == OS_MAC) {
                            needed |= KeyEvent.CTRL_MASK;
                        } else {
                            needed |= KeyEvent.ALT_MASK;
                        }
                    }

                    return KeyStroke.getKeyStroke(i.intValue(), needed);
                } else {
                    return null;
                }
            }
        }
    } catch (NoSuchElementException ex) {
        return null;
    }
}

From source file:com.microsoftopentechnologies.windowsazurestorage.service.UploadService.java

@Override
public final int execute() throws WAStorageException {
    if (serviceData.getUploadType() == UploadType.INVALID) {
        // no files are uploaded
        println("Upload type is INVALID, nothing to do.");
        return 0;
    }/*  w  w w.  jav a 2s.  c  o  m*/

    int filesUploaded = 0; // Counter to track no. of files that are uploaded
    try {
        final FilePath workspacePath = serviceData.getRemoteWorkspace();
        println(Messages.WAStoragePublisher_uploading());

        final StringBuilder archiveIncludes = new StringBuilder();

        StringTokenizer strTokens = new StringTokenizer(serviceData.getFilePath(), fpSeparator);
        while (strTokens.hasMoreElements()) {
            String fileName = strTokens.nextToken();
            String embeddedVP = null;

            if (fileName != null && fileName.contains("::")) {
                int embVPSepIndex = fileName.indexOf("::");

                // Separate fileName and Virtual directory name
                if (fileName.length() > embVPSepIndex + 1) {
                    embeddedVP = fileName.substring(embVPSepIndex + 2, fileName.length());

                    if (StringUtils.isBlank(embeddedVP)) {
                        embeddedVP = null;
                    } else if (!embeddedVP.endsWith(Constants.FWD_SLASH)) {
                        embeddedVP = embeddedVP + Constants.FWD_SLASH;
                    }
                }
                fileName = fileName.substring(0, embVPSepIndex);
            }

            // List all the paths without the zip archives.
            FilePath[] paths = workspacePath.list(fileName, excludedFilesAndZip());
            archiveIncludes.append(",").append(fileName);
            filesUploaded += paths.length;

            if (paths.length != 0 && serviceData.getUploadType() != UploadType.ZIP) {
                // the uploadType is either INDIVIDUAL or BOTH, upload included individual files thus.
                uploadIndividuals(embeddedVP, paths);
            }
        }

        // if uploadType is BOTH or ZIP, create an archive.zip and upload
        if (filesUploaded != 0 && (serviceData.getUploadType() != UploadType.INDIVIDUAL)) {
            uploadArchive(archiveIncludes.toString());

        }

    } catch (IOException | InterruptedException e) {
        throw new WAStorageException(e.getMessage(), e.getCause());
    }
    return filesUploaded;
}

From source file:org.aries.maven.plugin.GeneratorMojo.java

protected GenerationContext createGenerationContext() {
    GenerationContext context = new GenerationContext();
    if (!StringUtils.isEmpty(projectName))
        context.setProjectName(projectName);
    if (!StringUtils.isEmpty(templateHome))
        context.setTemplateHome(templateHome);
    if (!StringUtils.isEmpty(templateName))
        context.setTemplateName(templateName);
    if (!StringUtils.isEmpty(targetHome))
        context.setTargetHome(targetHome);
    if (!StringUtils.isEmpty(targetWorkspace))
        context.setTargetWorkspace(targetWorkspace);
    if (!StringUtils.isEmpty(subsetType)) {
        context.getSubsets().clear();//from   ww  w  .  java2s . com
        StringTokenizer tokenizer = new StringTokenizer(subsetType);
        while (tokenizer.hasMoreElements()) {
            String subset = (String) tokenizer.nextElement();
            context.addSubset(subset);
        }
    }
    return context;
}

From source file:org.commoncrawl.util.ArcFileWriter.java

private static NIOHttpHeaders getHeadersFromString(String headers) {

    NIOHttpHeaders headersOut = new NIOHttpHeaders();

    StringTokenizer tokenizer = new StringTokenizer(headers, "\r\n");

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

        if (token != null && token.length() != 0) {
            int colonPos = token.indexOf(':');

            if (colonPos != -1 && colonPos != token.length() - 1) {

                String key = token.substring(0, colonPos);
                String value = token.substring(colonPos + 1);

                if (key.length() != 0 && value.length() != 0) {
                    headersOut.add(key, value);
                }/*from   ww w  . j  ava2 s .com*/
            } else {
                headersOut.add(null, token);
            }

        }
    }
    return headersOut;
}

From source file:com.quui.chat.Preprocessor.java

/**
 * Tokenizes the user input, then every word thats not in the stopwords-list
 * is stemmed and these are returned./* ww w  .  ja va 2  s. c om*/
 * @param s The input to answer to.
 * @return Returns those words (stemmed) that will be processed
 */
public Vector<String> preProcess(String s) {
    if (s == null) {
        throw new NullPointerException("Word to process is null.");
    }
    StringTokenizer tokenizer = new StringTokenizer(s, " .!?,;:^\"$%&/\\()[]#'+*<>|\t-");
    String[] tokens = new String[tokenizer.countTokens()];
    int i = 0;
    while (tokenizer.hasMoreElements()) {
        tokens[i] = tokenizer.nextToken();
        i++;
    }
    Vector<String> result = new Vector<String>();
    for (String element : tokens) {
        String firstStem = element;
        if (this.isWordNetEnabled) {
            firstStem = WNLookup.getStaticStem(element);
            if (firstStem.equals("")) {
                firstStem = element;
            }
        }
        if (!this.stopwords.contains(firstStem) && firstStem.trim().length() > 1) {
            if (firstStem.trim().equals("")) {
                throw new NullPointerException("Empty token!");
            }
            result.add(firstStem);
        }
    }
    return result;
}

From source file:org.languagetool.tokenizers.WordTokenizer.java

@Override
public List<String> tokenize(String text) {
    List<String> l = new ArrayList<>();
    StringTokenizer st = new StringTokenizer(text, getTokenizingCharacters(), true);
    while (st.hasMoreElements()) {
        l.add(st.nextToken());//from  w  w w  . j  a  va 2s .co  m
    }
    return joinEMailsAndUrls(l);
}

From source file:com.chinamobile.bcbsp.io.titan.TitanRecordWriter.java

@Override
public void write(Text keyValue) throws IOException, InterruptedException {
    Text key = new Text();
    Text value = new Text();
    StringTokenizer str1 = new StringTokenizer(keyValue.toString(), "\t");
    if (str1.hasMoreElements()) {
        key.set(str1.nextToken());//from   ww  w  .  ja v a 2 s  .c om
    }
    if (str1.hasMoreElements()) {
        value.set(str1.nextToken());
    }
    if (key == new Text()) {
        return;
    }
    String[] vertexInfo = key.toString().split(":");
    String vertexID = vertexInfo[0];
    String vertexValue = vertexInfo[1];
    if (value == new Text()) {
        try {
            if (!hasVertex(vertexID)) {
                client.execute("g.addVertex([vertexID:'" + vertexID + "', value:'" + vertexValue + "'])");
            } else {
                client.execute(
                        "g.V('vertexID','" + vertexID + "').sideEffect{it.value = '" + vertexValue + "'}");
            }
        } catch (RexProException e) {
            LOG.error("Can not write record to database!");
            return;
        }
        return;
    }
    String[] strs = value.toString().split(" ");
    String[] outgoingVertexIDs = new String[strs.length];
    String[] weights = new String[strs.length];
    for (int i = 0; i < strs.length; i++) {
        String[] str = strs[i].split(":");
        outgoingVertexIDs[i] = str[0];
        weights[i] = str[1];
    }
    try {
        if (!hasVertex(vertexID)) {
            client.execute("g.addVertex([vertexID:'" + vertexID + "', value:'" + vertexValue + "'])");
        } else {
            client.execute("g.V('vertexID','" + vertexID + "').sideEffect{it.value = '" + vertexValue + "'}");
        }
        for (int i = 0; i < outgoingVertexIDs.length; i++) {
            if (!hasVertex(outgoingVertexIDs[i])) {
                client.execute("g.addVertex([vertexID:'" + outgoingVertexIDs[i] + "', value:''])");
            } /*
               * else { client.execute("g.V('vertexID','" + outgoingVertexIDs[i] +
               * "')"); }
               */
            client.execute("g.addEdge(g.V('vertexID','" + vertexID + "').next(), g.V('vertexID','"
                    + outgoingVertexIDs[i] + "').next(), 'outgoing', [weight:" + weights[i] + "])");
        }
    } catch (RexProException e) {
        LOG.error("Can not write record to database!");
        return;
    }
}

From source file:de.juwimm.cms.search.res.HtmlDocumentLocator.java

private Document parseHtml(Document resource, HTMLParser parser) throws IOException, InterruptedException {
    Reader reader = parser.getReader();
    StringWriter sw = new StringWriter();
    org.apache.commons.io.IOUtils.copy(reader, sw);
    String sresult = sw.toString();

    if (log.isDebugEnabled())
        log.debug("Saving tokenized HTML value into searchengine: " + sresult);
    resource.add(/* w  w  w . j  a  v  a 2s . c o m*/
            new Field("contents", stripNonValidXMLCharacters(sresult), Field.Store.YES, Field.Index.ANALYZED));

    Properties prop = parser.getMetaTags();
    Collection metafields = prop.values();
    String metadata = "";
    Iterator it = metafields.iterator();
    while (it.hasNext()) {
        StringTokenizer st = new StringTokenizer((String) it.next(), ",");
        while (st.hasMoreElements()) {
            String token = st.nextToken().trim();
            metadata += token + " ";
        }
    }
    // tidy the metadata
    metadata = XercesHelper.html2utf8string(metadata);
    resource.add(new Field("metadata", metadata, Field.Store.YES, Field.Index.ANALYZED));

    // Add the summary as a field that is stored and returned with
    // hit documents for display.
    resource.add(new Field("summary", parser.getSummary(), Field.Store.YES, Field.Index.ANALYZED_NO_NORMS));

    // Add the title as a field that it can be searched and that is stored.
    resource.add(new Field("title", parser.getTitle(), Field.Store.YES, Field.Index.ANALYZED));
    reader.close();
    return resource;
}

From source file:org.eclipse.ocl.examples.build.utilities.BackportToXtext_2_3_1.java

@Override
protected void invokeInternal(final WorkflowContext model, final ProgressMonitor monitor, final Issues issues) {
    if (directory != null) {
        final StringTokenizer st = new StringTokenizer(directory, ",");
        while (st.hasMoreElements()) {
            final String dir = st.nextToken().trim();
            final File f = new File(dir);
            if (f.exists() && f.isDirectory()) {
                LOG.info("Backporting " + f.getAbsolutePath());
                try {
                    cleanFolder(f.getAbsolutePath());
                } catch (FileNotFoundException e) {
                    issues.addError(e.getMessage());
                }// ww  w.j a va  2  s .co m
            }
        }
    }
}