Example usage for java.util StringTokenizer countTokens

List of usage examples for java.util StringTokenizer countTokens

Introduction

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

Prototype

public int countTokens() 

Source Link

Document

Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.

Usage

From source file:com.smartmarmot.orabbix.Configurator.java

private static Query[] getQueries(String parameter, Properties _propsq) throws Exception {
    try {/*from www .  j  a  va  2 s.co m*/
        StringTokenizer stq = new StringTokenizer(_propsq.getProperty(parameter), Constants.DELIMITER);
        String[] QueryLists = new String[stq.countTokens()];
        int count = 0;
        while (stq.hasMoreTokens()) {
            String token = stq.nextToken().toString().trim();
            QueryLists[count] = token;
            count++;
        }

        Collection<Query> Queries = new ArrayList<Query>();
        for (int i = 0; i < QueryLists.length; i++) {
            try {
                Query q = getQueryProperties(_propsq, QueryLists[i]);
                Queries.add(q);
            } catch (Exception e1) {
                SmartLogger.logThis(Level.ERROR,
                        "Error on Configurator on reading query " + QueryLists[i] + e1);
                SmartLogger.logThis(Level.INFO, "Query " + QueryLists[i] + " skipped due to error " + e1);

            }
        }
        Query[] queries = (Query[]) Queries.toArray(new Query[0]);
        return queries;
    } catch (Exception ex) {

        SmartLogger.logThis(Level.ERROR,
                "Error on Configurator on reading properties file " + _propsq.toString() + " getQueries("
                        + parameter + "," + _propsq.toString() + ") " + ex.getMessage());
        return null;
    }

}

From source file:cn.fql.utility.StringUtility.java

/**
 * Convert String to Map, "A=B&C=D" -> [A=B, C=D]
 *
 * @param srcStr   string to convert/*from   w w  w .  jav  a2  s.c  o m*/
 * @param sperator sperator for split <code>srcStr</code>
 * @return <code>Map</code>
 */
public static Map convertStringToMap(String srcStr, String sperator) {
    StringTokenizer st1 = new StringTokenizer(srcStr, sperator);
    Map result = new HashMap();
    while (st1.hasMoreTokens()) {
        String field = st1.nextToken();
        StringTokenizer st2 = new StringTokenizer(field, "=");
        String key;
        String value = null;
        if (st2.countTokens() == 2) {
            key = st2.nextToken();
            value = st2.nextToken();
        } else {
            key = st2.nextToken();
        }
        result.put(key, value);
    }
    return result;
}

From source file:com.espertech.esper.regression.dataflow.MyTokenizerCounter.java

public void onInput(String line) {
    StringTokenizer tokenizer = new StringTokenizer(line, " \t");
    int wordCount = tokenizer.countTokens();
    int charCount = 0;
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        charCount += token.length();/*ww  w  . j  a  va2  s.  c  o  m*/
    }
    log.debug("Submitting stat words[" + wordCount + "] chars[" + charCount + "] for line '" + line + "'");
    graphContext.submit(new Object[] { 1, wordCount, charCount });
}

From source file:com.chinamobile.bcbsp.examples.simrank.SRRecordParse.java

/**
 * This method is used to parse a record and obtain VertexID .
 * @param key The key of the vertex record
 * @return the vertex id//from   w  w w.  j  a  v  a 2  s  .  co m
 */
public Text getVertexID(Text key) {
    try {
        StringTokenizer str = new StringTokenizer(key.toString(), ":");
        if (str.countTokens() != 3) {
            return null;
        }
        return new Text(str.nextToken());
    } catch (Exception e) {
        return null;
    }
}

From source file:com.agloco.util.StringUtil.java

public static String[] split(String seperators, String list, boolean include) {
    StringTokenizer tokens = new StringTokenizer(list, seperators, include);
    String[] result = new String[tokens.countTokens()];
    int i = 0;/* www  .j  a  va2  s . com*/
    while (tokens.hasMoreTokens()) {
        result[i++] = tokens.nextToken();
    }
    return result;
}

From source file:netflow.Main.java

public String[] parseLine(String s) {
    StringTokenizer st = new StringTokenizer(s, " ");
    int size = st.countTokens();
    String[] result = new String[size];
    int i = 0;//  w ww  .j  a v  a2 s  .c o m
    while (st.hasMoreTokens()) {
        result[i++] = st.nextToken();
    }
    return result;
}

From source file:com.chinamobile.bcbsp.partition.RecordParseDefault.java

/**
 * This method is used to parse a record and obtain VertexID .
 * @param key The key of the vertex record
 * @return the vertex id// w w  w.  ja  va  2  s.  co  m
 */
@Override
public Text getVertexID(Text key) {
    try {
        StringTokenizer str = new StringTokenizer(key.toString(), Constants.SPLIT_FLAG);
        if (str.countTokens() != 2) {
            return null;
        }
        return new Text(str.nextToken());
    } catch (Exception e) {
        return null;
    }
}

From source file:com.chinamobile.bcbsp.ml.RecordParseML.java

/**
 * This method is used to parse a record and obtain VertexID .
 * @param key The key of the vertex record
 * @return the vertex id//w w  w  .  j av a 2s .com
 */
@Override
public Text getVertexID(Text key) {
    try {
        StringTokenizer str = new StringTokenizer(key.toString(), Constants.SPLIT_FLAG);
        if (str.countTokens() < 1) {
            return null;
        }
        return new Text(str.nextToken());
    } catch (Exception e) {
        return null;
    }
}

From source file:net.sf.jasperreports.engine.xml.TextLineBreakOffsetsRule.java

@Override
public void body(String namespace, String name, String text) throws Exception {
    if (text != null) {
        StringTokenizer tokenizer = new StringTokenizer(text, JRXmlConstants.LINE_BREAK_OFFSET_SEPARATOR);
        int tokenCount = tokenizer.countTokens();
        short[] offsets;
        if (tokenCount == 0) {
            //use the zero length array singleton
            offsets = JRPrintText.ZERO_LINE_BREAK_OFFSETS;
        } else {//from w  w w  .j a v  a2  s  . com
            offsets = new short[tokenCount];
            for (int i = 0; i < offsets.length; i++) {
                String token = tokenizer.nextToken();
                offsets[i] = Short.parseShort(token);
            }
        }

        JRPrintText printText = (JRPrintText) getDigester().peek();
        printText.setLineBreakOffsets(offsets);
    }
}

From source file:org.globus.security.authorization.xml.AbstractBeanDefinitionParser.java

protected String getIdOrName(Element elem) {
    String id = elem.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);

    if (null == id || "".equals(id)) {
        String names = elem.getAttribute("name");
        if (null != names) {
            StringTokenizer st = new StringTokenizer(names, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
            if (st.countTokens() > 0) {
                id = st.nextToken();/* w  w  w  .  jav a2s. c  o  m*/
            }
        }
    }
    return id;
}