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.sun.faban.harness.webclient.Uploader.java

private void uploadTags(String runId) throws IOException, ClassNotFoundException {
    File file = new File(Config.OUT_DIR + runId + "/META-INF/tags");
    String tags = FileHelper.readContentFromFile(file);
    TagEngine te = TagEngine.getInstance();
    String[] tagsArray;/*from  www. j  a v a  2 s . c  o m*/
    if (tags != null && !"".equals(tags)) {
        StringTokenizer tok = new StringTokenizer(tags, " ");
        tagsArray = new String[tok.countTokens()];
        int count = tok.countTokens();
        int i = 0;
        while (i < count) {
            String nextT = tok.nextToken().trim();
            tagsArray[i] = nextT;
            i++;
        }
        te.add(runId, tagsArray);
    } else {
        te.add(runId, new String[0]);
    }
    te.save();
}

From source file:de.xwic.appkit.webbase.table.DefaultColumnLabelProvider.java

/**
 * @throws IntrospectionException /* ww  w  .  ja v a 2s. c  om*/
 * 
 */
private void buildReadPath(Object element) throws IntrospectionException {
    StringTokenizer stk = new StringTokenizer(column.getPropertyId(), ".");
    readMethods = new Method[stk.countTokens()];

    int idx = 0;
    Class<?> clazz = element.getClass();
    while (stk.hasMoreTokens()) {
        String propertyName = stk.nextToken();

        PropertyDescriptor desc = new PropertyDescriptor(propertyName, clazz, makeGetterName(propertyName),
                null);
        clazz = desc.getPropertyType();
        readMethods[idx++] = desc.getReadMethod();
    }
    propertyEditor = PropertyEditorManager.findEditor(clazz);
    baseClass = element.getClass();
}

From source file:com.javielinux.utils.Utils.java

public static boolean importSearch(Context cnt, String text) {

    try {//from w  w  w. j a  v  a2s  .co m
        if (text.startsWith("http://bit.ly")) {
            String url = "http://www.longurlplease.com/api/v1.1?q=" + text;

            HttpGet request = new HttpGet(url);
            HttpClient client = new DefaultHttpClient();
            HttpResponse httpResponse;
            try {
                httpResponse = client.execute(request);
                String xml = EntityUtils.toString(httpResponse.getEntity());
                JSONObject jsonObject = new JSONObject(xml);
                String t = jsonObject.getString(text);
                if ((t != null) && t != "")
                    text = t;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        text = text.replace(Utils.URL_QR, "");

        StringTokenizer tokens = new StringTokenizer(text, "||");

        Entity ent = new Entity("search");
        ent.setValue("date_create", Utils.now());
        ent.setValue("last_modified", Utils.now());
        ent.setValue("use_count", 0);

        long icon_id = -1;

        while (tokens.hasMoreTokens()) {

            StringTokenizer hash = new StringTokenizer(tokens.nextToken(), "%%");

            if (hash.countTokens() == 2) {
                String key = hash.nextToken();
                String value = hash.nextToken();
                if (key.equals("name")) {
                    ent.setValue("name", value);
                } else if (key.equals("and")) {
                    ent.setValue("words_and", value);
                } else if (key.equals("or")) {
                    ent.setValue("words_or", value);
                } else if (key.equals("not")) {
                    ent.setValue("words_not", value);
                } else if (key.equals("from")) {
                    ent.setValue("from_user", value);
                } else if (key.equals("to")) {
                    ent.setValue("to_user", value);
                } else if (key.equals("lang")) {
                    ent.setValue("lang", value);
                } else if (key.equals("att")) {
                    ent.setValue("attitude", value);
                } else if (key.equals("filt")) {
                    ent.setValue("filter", value);
                } else if (key.equals("rt")) {
                    ent.setValue("no_retweet", value);
                } else if (key.equals("geo")) {
                    ent.setValue("use_geo", value);
                } else if (key.equals("tgeo")) {
                    ent.setValue("type_geo", value);
                } else if (key.equals("lat")) {
                    ent.setValue("latitude", value);
                } else if (key.equals("long")) {
                    ent.setValue("longitude", value);
                } else if (key.equals("tdist")) {
                    ent.setValue("type_distance", value);
                } else if (key.equals("dist")) {
                    ent.setValue("distance", value);
                } else if (key.equals("icon")) {
                    icon_id = Long.parseLong(value);
                }
            }
        }

        if (icon_id > 1) {
            Entity icon = new Entity("icons", icon_id);
            ent.setValue("icon_big", "drawable/" + icon.getValue("icon"));
            ent.setValue("icon_small", "drawable/" + icon.getValue("icon_small"));
        } else {
            String c = ent.getString("name").substring(0, 1).toLowerCase();
            int id = cnt.getResources().getIdentifier(Utils.packageName + ":drawable/letter_" + c, null, null);
            if (id > 0) {
                ent.setValue("icon_big", "drawable/letter_" + c);
                ent.setValue("icon_small", "drawable/letter_" + c + "_small");
            } else {
                ent.setValue("icon_big", "drawable/letter_az");
                ent.setValue("icon_small", "drawable/letter_az_small");
            }
        }

        ent.save();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:iha_au.ppmonitor.Services.BleService.java

/**
 * broadcaster modtaget string fra onCharacteristicChanged(...), som et PressureSensorData objekt.
 * @param value/* w  ww . j  av a 2 s.  c om*/
 */
public void broadCastValue(String value) {
    try {
        // StringTokenizer afkoder en string til "tokenz" ( mindre del elementer). Den sepere via en dilimeter ":".
        // Hver token udgr en vrdi til en sensor.
        // og de skal derfor sttes ind i deres, matchende sensor. token 1's vrdi, gemmes i sensor 1.
        StringTokenizer tokens = new StringTokenizer(value, ":");
        int count = tokens.countTokens();
        for (int i = 0; i < count; i++) {
            String s = tokens.nextToken();
            int v = Integer.parseInt(s);
            sensors.getSensor(i).addValue(v);
        }
        // Intent med filter VALUE_RESULT. indeholdende PressureSensorData objekt, med de sensorer som er blevet opdateret.
        Intent bI = new Intent(VALUE_RESULT);
        bI.putExtra("sensors", (Serializable) sensors);
        LocalBroadcastManager.getInstance(this).sendBroadcast(bI);
    } catch (Exception e) {
        Log.v("DEBUG", "error in broadcast value " + e.toString());
    }
}

From source file:JarEntryOutputStream.java

/**
 * Returns a list of entries that are//from  w w w .ja  va 2s  . c  o  m
 * immediately below the entry named by entryName in the jar's directory
 * structure.
 *
 * @param entryName the name of the directory entry name
 * @return List a list of java.util.jar.JarEntry objects that are
 * immediately below the entry named by entryName in the jar's directory
 * structure.
 */
public List listSubEntries(String entryName) {
    Enumeration entries = jar.entries();
    List subEntries = new ArrayList();

    while (entries.hasMoreElements()) {
        JarEntry nextEntry = (JarEntry) entries.nextElement();

        if (nextEntry.getName().startsWith(entryName)) {
            // the next entry name starts with the entryName so it
            // is a potential sub entry

            // tokenize the rest of the next entry name to see how
            // many tokens exist
            StringTokenizer tokenizer = new StringTokenizer(nextEntry.getName().substring(entryName.length()),
                    EnhancedJarFile.JAR_DELIMETER);

            if (tokenizer.countTokens() == 1) {
                // only 1 token exists, so it is a sub-entry
                subEntries.add(nextEntry);
            }
        }
    }

    return subEntries;
}

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();/*ww  w . ja  va  2s.c o m*/
    } 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.ambraproject.action.article.EmailArticleAction.java

private boolean checkEmails(String emailList) {
    if (StringUtils.isBlank(emailList)) {
        addFieldError("emailTo", "This field is required.");
        return false;
    } else {/*from   w  ww  . j  a va2  s  . c om*/
        final StringTokenizer emailTokens = new StringTokenizer(emailList, " \t\n\r\f,");
        if (emailTokens.countTokens() > MAX_TO_EMAIL) {
            addFieldError("emailTo", "Maximum of " + MAX_TO_EMAIL + " email addresses");
            return false;
        }
        EmailValidator validator = EmailValidator.getInstance();
        ArrayList<String> invalidEmails = new ArrayList<String>();

        while (emailTokens.hasMoreTokens()) {
            String email = emailTokens.nextToken();
            if (!validator.isValid(email)) {
                invalidEmails.add(email);
            }
        }
        final int numInvalid = invalidEmails.size();
        if (numInvalid != 0) {
            StringBuilder errorMsg = new StringBuilder("Invalid e-mail address");
            if (numInvalid > 1) {
                errorMsg.append("es: ");
            } else {
                errorMsg.append(": ");
            }
            Iterator<String> iter = invalidEmails.iterator();
            while (iter.hasNext()) {
                errorMsg.append(iter.next());
                if (iter.hasNext()) {
                    errorMsg.append(", ");
                }
            }
            addFieldError("emailTo", errorMsg.toString());
        }
        return (numInvalid == 0);
    }
}

From source file:de.tudarmstadt.ukp.clarin.webanno.automation.util.AutomationUtil.java

public static void addTabSepTrainDocument(MiraTemplate aTemplate, RepositoryService aRepository,
        AutomationService aAutomationService)
        throws IOException, UIMAException, ClassNotFoundException, AutomationException {
    File miraDir = aAutomationService.getMiraDir(aTemplate.getTrainFeature());
    if (!miraDir.exists()) {
        FileUtils.forceMkdir(miraDir);//from   w  w  w .  j av  a2 s . c  om
    }

    AutomationStatus status = aAutomationService.getAutomationStatus(aTemplate);

    boolean documentChanged = false;
    for (SourceDocument document : aAutomationService
            .listTabSepDocuments(aTemplate.getTrainFeature().getProject())) {
        if (!document.isProcessed()) {
            documentChanged = true;
            break;
        }
    }
    if (!documentChanged) {
        return;
    }

    for (SourceDocument sourceDocument : aAutomationService
            .listTabSepDocuments(aTemplate.getTrainFeature().getProject())) {
        if (sourceDocument.getFeature() != null) { // This is a target layer train document
            continue;
        }
        File trainFile = new File(miraDir,
                sourceDocument.getId() + sourceDocument.getProject().getId() + ".train");
        BufferedWriter trainOut = new BufferedWriter(new FileWriter(trainFile));
        File tabSepFile = new File(aRepository.getDocumentFolder(sourceDocument), sourceDocument.getName());
        LineIterator it = IOUtils.lineIterator(new FileReader(tabSepFile));
        while (it.hasNext()) {
            String line = it.next();
            if (line.trim().equals("")) {
                trainOut.append("\n");
            } else {
                StringTokenizer st = new StringTokenizer(line, "\t");
                if (st.countTokens() != 2) {
                    trainOut.close();
                    throw new AutomationException("This is not a valid TAB-SEP document");
                }
                trainOut.append(getMiraLineForTabSep(st.nextToken(), st.nextToken()));
            }
        }
        sourceDocument.setProcessed(false);
        status.setTrainDocs(status.getTrainDocs() - 1);
        trainOut.close();
    }

}

From source file:com.octo.captcha.engine.bufferedengine.manager.QuartzBufferedEngineManager.java

/**
 * @see com.octo.captcha.engine.bufferedengine.manager.BufferedEngineContainerManager#getLocaleFromName
 */// ww w .j av a2s.  c o  m
protected Locale getLocaleFromName(String localeName) {
    StringTokenizer tokenizer = new StringTokenizer(localeName, "_");
    int count = tokenizer.countTokens();
    switch (count) {
    case 2:
        return new Locale(tokenizer.nextToken(), tokenizer.nextToken());
    case 3:
        return new Locale(tokenizer.nextToken(), tokenizer.nextToken(), tokenizer.nextToken());
    default:
        return Locale.getDefault();
    }
    /*
     * JDK 1.4 String[] localeTab = localeName.split("_"); switch (localeTab.length) { case 1:
     * return new Locale(localeTab[0]); case 2: return new Locale(localeTab[0], localeTab[1]);
     * case 3: return new Locale(localeTab[0], localeTab[1], localeTab[2]); default: return
     * Locale.getDefault(); }
     */
}

From source file:edu.ucla.stat.SOCR.chart.SuperYIntervalChart.java

public void setDataTable(String input) {
    hasExample = true;/*from ww w.j av a2 s.  co m*/
    StringTokenizer lnTkns = new StringTokenizer(input, "#");
    String line;
    int rowCt = lnTkns.countTokens();
    resetTableRows(rowCt);
    resetTableColumns(2);
    int r = 0;
    while (lnTkns.hasMoreTokens()) {
        line = lnTkns.nextToken();

        //   String tb[] =line.split("\t");
        StringTokenizer pairTkns = new StringTokenizer(line, ";");// IE use "space" Mac use tab as cell separator
        int cellCnt = pairTkns.countTokens();
        for (int i = 0; i < cellCnt; i++) {
            dataTable.setValueAt(pairTkns.nextToken(), r, i);
        }
        r++;
    }

    // this will update the mapping panel     
    resetTableColumns(dataTable.getColumnCount());
}