Example usage for java.util StringTokenizer nextToken

List of usage examples for java.util StringTokenizer nextToken

Introduction

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

Prototype

public String nextToken() 

Source Link

Document

Returns the next token from this string tokenizer.

Usage

From source file:edu.umd.cfar.lamp.viper.geometry.Circle.java

/**
 * Creates a new <code>Circle</code> from the string.
 * @param S a string in the form <em>x y radius</em>
 * @return new <code>Circle</code> from the string
 * @throws BadAttributeDataException upon a parse error
 *//*from  w w w.ja va2  s  . co m*/
public static Circle valueOf(String S) {
    try {
        StringTokenizer st = new StringTokenizer(S);
        return new Circle(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()),
                Integer.parseInt(st.nextToken()));
    } catch (NoSuchElementException e1) {
        throw new BadAttributeDataException("Not enough integers for circle: " + S);
    } catch (NumberFormatException e2) {
        throw new BadAttributeDataException("Malformed circle string: " + S);
    }
}

From source file:ca.uhn.fhir.rest.method.QualifiedParamList.java

public static QualifiedParamList splitQueryStringByCommasIgnoreEscape(String theQualifier, String theParams) {
    QualifiedParamList retVal = new QualifiedParamList();
    retVal.setQualifier(theQualifier);/* ww  w. j av a 2 s.c o m*/

    StringTokenizer tok = new StringTokenizer(theParams, ",", true);
    String prev = null;
    while (tok.hasMoreElements()) {
        String str = tok.nextToken();
        if (isBlank(str)) {
            prev = null;
            continue;
        }

        if (str.equals(",")) {
            if (countTrailingSlashes(prev) % 2 == 1) {
                int idx = retVal.size() - 1;
                String existing = retVal.get(idx);
                prev = existing.substring(0, existing.length() - 1) + ',';
                retVal.set(idx, prev);
            } else {
                prev = null;
            }
            continue;
        }

        if (prev != null && prev.length() > 0 && prev.charAt(prev.length() - 1) == ',') {
            int idx = retVal.size() - 1;
            String existing = retVal.get(idx);
            prev = existing + str;
            retVal.set(idx, prev);
        } else {
            retVal.add(str);
            prev = str;
        }

    }

    return retVal;
}

From source file:com.salesmanager.core.util.MerchantConfigurationUtil.java

/**
 * Strips all delimiters// w w  w  .  j av a2 s  .c  o  m
 * 
 * @param configurationLine
 * @return
 */
public static Collection getConfigurationList(String configurationLine, String delimiter) {

    List returnlist = new ArrayList();
    StringTokenizer st = new StringTokenizer(configurationLine, delimiter);
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        returnlist.add(token);
    }
    return returnlist;
}

From source file:Main.java

private static String getPathBeforeLastInPathElement(String path) {
    StringTokenizer st = new StringTokenizer(path, ".");
    StringBuffer sb = new StringBuffer();
    int cpt = st.countTokens();
    //      if (cpt==1)
    //         return root;
    int i = cpt - 1;
    for (int j = 0; j < i; j++) {
        String token = st.nextToken();
        sb.append(token);//from ww  w.j ava  2  s .  c o  m
        if (j != i - 1)
            sb.append(".");
    }
    return sb.toString();
    //      String last = getLastInPathElement(path);
    //      path = StringUtils.substringBefore(path, last);
    //      return 
}

From source file:Main.java

public static String xmlEncoding(String input, String delimiter) {
    if (input == null || input.equals(""))
        return input;

    delimiter += '&';

    StringTokenizer tmpst = new StringTokenizer(input, delimiter, true);
    StringBuffer tmpsb = new StringBuffer(input.length() + 100);
    String tmps = null;//w  w  w .  j a  v a 2s  . com
    while (tmpst.hasMoreTokens()) {
        tmps = tmpst.nextToken();
        if (tmps.length() == 1 && delimiter.indexOf(tmps) >= 0) {
            switch (tmps.charAt(0)) {
            case '<':
                tmpsb.append("&lt;");
                break;
            case '>':
                tmpsb.append("&gt;");
                break;
            case '&':
                tmpsb.append("&amp;");
                break;
            case '\'':
                tmpsb.append("&apos;");
                break;
            case '\"':
                tmpsb.append("&quot;");
                break;
            case '\n':
                tmpsb.append("&#10;");
                break;
            case '\r':
                tmpsb.append("&#13;");
                break;
            case '\t':
                tmpsb.append("&#9;");
                break;
            }
        } else {
            tmpsb.append(tmps);
        }
    }

    return tmpsb.toString();
}

From source file:Main.java

public static String getThreadName(Thread thr) {
    if (thr == null)
        return "null";

    // This depends on the formatting in SelectReaderThread and CorbaConnectionImpl.
    // Pattern for SelectReaderThreads:
    // SelectReaderThread CorbaConnectionImpl[ <host> <post> <state>]
    // Any other pattern in the Thread's name is just returned.
    String name = thr.getName();/*from w  ww. j a v  a 2s . co m*/
    StringTokenizer st = new StringTokenizer(name);
    int numTokens = st.countTokens();
    if (numTokens != 5)
        return name;

    String[] tokens = new String[numTokens];
    for (int ctr = 0; ctr < numTokens; ctr++)
        tokens[ctr] = st.nextToken();

    if (!tokens[0].equals("SelectReaderThread"))
        return name;

    return "SelectReaderThread[" + tokens[2] + ":" + tokens[3] + "]";
}

From source file:Main.java

public static String[] getTokens(String line, String delim) {
    if (line == null || line.equals("")) {
        return null;
    }//from w  w  w.j ava  2  s .  c o m
    if (line.indexOf(delim) < 0) {

        if (delim.length() > 1 && !"\r\n".equals(delim)) {
            String regex = "^.*[" + delim + "].*";
            if (!line.matches(regex)) {
                return new String[] { line };
            }
        } else {
            return new String[] { line };
        }
    }

    StringTokenizer st = new StringTokenizer(line, delim);
    int length = st.countTokens();
    String[] tokens = new String[length];
    for (int i = 0; i < length; i++) {
        tokens[i] = st.nextToken();
    }
    return tokens;
}

From source file:com.salesmanager.core.util.StringUtil.java

public static Map deformatUrlResponse(String payload) throws Exception {
    HashMap nvp = new HashMap();
    StringTokenizer stTok = new StringTokenizer(payload, "&");
    while (stTok.hasMoreTokens()) {
        StringTokenizer stInternalTokenizer = new StringTokenizer(stTok.nextToken(), "=");
        if (stInternalTokenizer.countTokens() == 2) {
            String key = URLDecoder.decode(stInternalTokenizer.nextToken(), "UTF-8");
            String value = URLDecoder.decode(stInternalTokenizer.nextToken(), "UTF-8");
            nvp.put(key.toUpperCase(), value);
        }//from w w w . j ava  2  s  .  c  om
    }
    return nvp;
}

From source file:fr.paris.lutece.plugins.updater.util.sql.SqlUtils.java

/**
 * Executes an SQL script/*from   w  w  w  .  j  av  a2s . c o m*/
 * @param strScript An SQL script
 * @param plugin The plugin
 * @throws SQLException If an SQL exception occurs
 */
public static void executeSqlScript(String strScript, Plugin plugin) throws SQLException {
    String strCleanScript = strScript.substring(0, strScript.lastIndexOf(";"));
    StringTokenizer st = new StringTokenizer(strCleanScript, ";");

    Transaction transaction = new Transaction();

    try {
        while (st.hasMoreTokens()) {
            String strSQL = st.nextToken();
            transaction.prepareStatement(strSQL);
            transaction.executeStatement();
        }

        transaction.commit();
    } catch (SQLException ex) {
        transaction.rollback(ex);
        AppLogService.error("Execute SQL script error : " + ex.getMessage() + " - transaction rolled back.",
                ex);
        throw ex;
    }
}

From source file:edu.uci.ics.jung.io.PartitionDecorationReader.java

public static void loadCounts(Graph bg, Reader count_reader, Predicate partition, Object count_key,
        UserData.CopyAction copyact, int num_types) {
    StringLabeller id_label = StringLabeller.getLabeller(bg, partition);
    try {//w ww  .j ava  2  s .co  m
        BufferedReader br = new BufferedReader(count_reader);

        while (br.ready()) {
            String curLine = br.readLine();
            if (curLine == null || curLine.equals("end_of_file"))
                break;
            if (curLine.trim().length() == 0)
                continue;

            StringTokenizer st = new StringTokenizer(curLine);
            String entity_id = st.nextToken();
            int type_id = new Integer(st.nextToken()).intValue() - 1;
            int count = new Integer(st.nextToken()).intValue();

            Vertex v = id_label.getVertex(entity_id);

            if (v == null)
                throw new IllegalArgumentException("Unrecognized vertex " + entity_id);

            double[] counts = (double[]) v.getUserDatum(count_key);
            if (counts == null) {
                counts = new double[num_types];
                v.addUserDatum(count_key, counts, copyact);
            }
            counts[type_id] = count;
        }
        br.close();
    } catch (IOException ioe) {
        throw new FatalException("Error in loading counts from " + count_reader);
    }
}