Example usage for java.util StringTokenizer StringTokenizer

List of usage examples for java.util StringTokenizer StringTokenizer

Introduction

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

Prototype

public StringTokenizer(String str, String delim) 

Source Link

Document

Constructs a string tokenizer for the specified string.

Usage

From source file:DataFileTest.java

public void readData(BufferedReader in) throws IOException {
    String s = in.readLine();//from  w ww.  j av  a 2  s.c om
    StringTokenizer t = new StringTokenizer(s, "|");

    name = t.nextToken();

    salary = Double.parseDouble(t.nextToken());
}

From source file:com.glaf.core.util.FtpUtils.java

private static void changeToDirectory(String remoteFile) {
    if (!remoteFile.startsWith("/")) {
        throw new RuntimeException(" path must start with '/'");
    }/*from   w w w.j a va2s.co  m*/
    if (remoteFile.startsWith("/") && remoteFile.indexOf("/") > 0) {
        try {
            getFtpClient().changeWorkingDirectory("/");
            String tmp = "";
            remoteFile = remoteFile.substring(0, remoteFile.lastIndexOf("/"));
            StringTokenizer token = new StringTokenizer(remoteFile, "/");
            while (token.hasMoreTokens()) {
                String str = token.nextToken();
                tmp = tmp + "/" + str;
                getFtpClient().changeWorkingDirectory(tmp);
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:Main.java

/**
 * Build schema location map of schemas used in given
 * <code>schemaLocationAttribute</code> and adds them to the given
 * <code>schemaLocationMap</code>.
 * /*from  ww  w .  ja  va 2  s.c o m*/
 * @see <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">XML Schema
 *      Part 0: Primer Second Edition | 5.6 schemaLocation</a>
 * 
 * @param schemaLocationMap
 *          {@link Map} to add schema locations to.
 * @param schemaLocation
 *          attribute value to build schema location map from.
 * @return {@link Map} of schema namespace URIs to location URLs.
 * @since 8.1
 */
static final Map<String, List<String>> buildSchemaLocationMap(Map<String, List<String>> schemaLocationMap,
        final String schemaLocation) {
    if (null == schemaLocation) {
        return schemaLocationMap;
    }

    if (null == schemaLocation || schemaLocation.isEmpty()) {
        // should really ever be null but being safe.
        return schemaLocationMap;
    }

    final StringTokenizer st = new StringTokenizer(schemaLocation, " \n\t\r");
    while (st.hasMoreElements()) {
        final String ns = st.nextToken();
        final String loc = st.nextToken();
        List<String> locs = schemaLocationMap.get(ns);
        if (null == locs) {
            locs = new ArrayList<>();
            schemaLocationMap.put(ns, locs);
        }
        if (!locs.contains(loc)) {
            locs.add(loc);
        }
    }

    return schemaLocationMap;
}

From source file:net.sf.jabref.exporter.layout.WSITools.java

/**
 * @param  vcr       {@link java.util.Vector} of <tt>String</tt>
 * @param  buf       Description of the Parameter
 * @param  delimstr  Description of the Parameter
 * @return           Description of the Return Value
 *///  w  ww .j  a  va  2  s .c o  m
public static boolean tokenize(Vector<String> vcr, String buf, String delimstr) {
    vcr.clear();
    buf = buf + '\n';

    StringTokenizer st = new StringTokenizer(buf, delimstr);

    while (st.hasMoreTokens()) {
        vcr.add(st.nextToken());
    }

    return true;
}

From source file:Main.java

/**
 * Find an element using XPath-quotation expressions. Path must not including
 * the context element, path elements can be separated by / or .,
 * and namespace is NOT supported.//from   www . ja v  a2s.  com
 * @param context Element to start the search from, cannot be null.
 * @param path XPath-quotation expression, cannot be null.
 * @param create if true, new elements are created if necessary.
 * @return the first matched element if there are matches, otherwise
 * return null.
 */
public static Element getElementByPath(Element context, String path, boolean create) {
    Element cur = context;
    StringTokenizer tokens = new StringTokenizer(path, "/");

    while (tokens.hasMoreTokens()) {
        String name = tokens.nextToken();
        Element parent = cur;
        cur = getChildElement(cur, name);
        if (cur == null) {
            if (create) {
                // create the element
                Element newElement = context.getOwnerDocument().createElement(name);
                //context.appendChild(newElement);
                parent.appendChild(newElement);
                cur = newElement;
            } else {
                return null;
            }
        }
    }
    return cur;
}

From source file:com.l2jfree.gameserver.handler.admincommands.AdminContest.java

@Override
public boolean useAdminCommand(String command, L2Player activeChar) {
    StringTokenizer st = new StringTokenizer(command, " ");
    command = st.nextToken();/* w w w.  j  av  a2  s. c om*/
    if (command.startsWith("admin_contest")) {
        if (st.countTokens() == 0) {
            activeChar.sendMessage("Specify clan hall ID (34 - Devastated castle, 64 - Fortress of the Dead)!");
            return false;
        }
        try {
            int hallId = Integer.parseInt(st.nextToken());
            if (command.endsWith("start"))
                ClanHallManager.getInstance().getClanHallById(hallId).getSiege().startSiege();
            else if (command.endsWith("cancel"))
                ClanHallManager.getInstance().getClanHallById(hallId).getSiege().endSiege(null);
            return true;
        } catch (NumberFormatException nfe) {
            activeChar.sendMessage("That's not a clan hall ID.");
        } catch (NullPointerException npe) {
            activeChar.sendMessage("That clan hall doesn't exist/is not contestable.");
        } catch (IndexOutOfBoundsException e) {
            _log.fatal("Caught it!", e);
        }
    }
    return false;
}

From source file:com.github.dozermapper.core.fieldmap.HintContainer.java

public List<Class<?>> getHints() {
    if (hints == null) {
        List<Class<?>> list = new ArrayList<>();
        StringTokenizer st = new StringTokenizer(this.hintName, ",");
        while (st.hasMoreElements()) {
            String theHintName = st.nextToken().trim();

            Class<?> clazz = MappingUtils.loadClass(theHintName, beanContainer);
            list.add(clazz);/*from  w  w w  . j  a  va2  s.  c  om*/
        }
        hints = list;
    }
    return hints;
}

From source file:com.agimatec.annotations.jam.JAMDtoMethod.java

public JField getTypeField(String path) {
    if (path == null || path.length() == 0)
        return null;
    StringTokenizer tokens = new StringTokenizer(path, ".");
    JClass current = jmethod.getReturnType();
    JField field = null;//from   w ww  .  jav a  2 s  .co  m
    while (tokens.hasMoreTokens() && current != null) {
        String each = tokens.nextToken();
        field = findField(current, each);
        current = (field == null) ? null : field.getType();
    }
    return field;
}

From source file:com.dx.ss.plugins.ptree.impl.DefaultShellCallback.java

public File getDirectory(String targetProject, String targetPackage) {
    // targetProject is interpreted as a directory that must exist
    ///*from  ww w. j a  v  a  2  s  .  c o  m*/
    // targetPackage is interpreted as a sub directory, but in package
    // format (with dots instead of slashes). The sub directory will be
    // created
    // if it does not already exist

    File project = new File(targetProject);
    System.out.println(project.getAbsolutePath());

    StringBuilder sb = new StringBuilder();
    if (!StringUtils.isBlank(targetPackage)) {
        StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$
        while (st.hasMoreTokens()) {
            sb.append(st.nextToken());
            sb.append(File.separatorChar);
        }
    }

    File directory = new File(project, sb.toString());
    if (!directory.exists()) {
        boolean rc = directory.mkdirs();
        if (!rc)
            return null;
    }

    return directory;
}