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:gov.nih.nci.ncicb.tcga.dcc.dam.view.request.FilterRequest.java

public String[] getSampleCollectionArray() {
    if (samplesFromDropdowns == null || samplesFromDropdowns.length() == 0) {
        return new String[0];
    }// w w  w.  j  av  a 2  s.  c  o  m
    StringTokenizer st = new StringTokenizer(samplesFromDropdowns, ",");
    String[] ret = new String[st.countTokens()];
    int i = 0;
    while (st.hasMoreTokens()) {
        String s = st.nextToken();
        int pos1 = s.indexOf('-');
        int pos2 = s.indexOf('-', pos1 + 1);
        s = s.substring(pos1 + 1, pos2);
        if (s.equals("*")) {
            s = "";
        }
        ret[i++] = s;
    }
    return ret;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.dam.view.request.FilterRequest.java

public String[] getSamplePatientIdArray() {
    if (samplesFromDropdowns == null || samplesFromDropdowns.length() == 0) {
        return new String[0];
    }/*from   w ww  . j a  v  a2s  . co  m*/
    StringTokenizer st = new StringTokenizer(samplesFromDropdowns, ",");
    String[] ret = new String[st.countTokens()];
    int i = 0;
    while (st.hasMoreTokens()) {
        String s = st.nextToken();
        int pos1 = s.indexOf('-');
        int pos2 = s.indexOf('-', pos1 + 1);
        int pos3 = s.indexOf('-', pos2 + 1);
        s = s.substring(pos2 + 1, pos3);
        if (s.equals("*")) {
            s = "";
        }
        ret[i++] = s;
    }
    return ret;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.dam.view.request.FilterRequest.java

public String[] getSampleSampleTypeArray() {
    if (samplesFromDropdowns == null || samplesFromDropdowns.length() == 0) {
        return new String[0];
    }//from   w ww.jav  a  2s . co m
    StringTokenizer st = new StringTokenizer(samplesFromDropdowns, ",");
    String[] ret = new String[st.countTokens()];
    int i = 0;
    while (st.hasMoreTokens()) {
        String s = st.nextToken();
        int pos1 = s.indexOf('-');
        int pos2 = s.indexOf('-', pos1 + 1);
        int pos3 = s.indexOf('-', pos2 + 1);
        s = s.substring(pos3 + 1);
        if (s.equals("*")) {
            s = "";
        }
        ret[i++] = s;
    }
    return ret;
}

From source file:com.repeatability.pdf.PDFTextStripper.java

/**
 * This method parses the bidi file provided as inputstream.
 * /*ww  w  . j a  va2  s  .c  om*/
 * @param inputStream - The bidi file as inputstream
 * @throws IOException if any line could not be read by the LineNumberReader
 */
private static void parseBidiFile(InputStream inputStream) throws IOException {
    LineNumberReader rd = new LineNumberReader(new InputStreamReader(inputStream));

    do {
        String s = rd.readLine();
        if (s == null) {
            break;
        }

        int comment = s.indexOf('#'); // ignore comments
        if (comment != -1) {
            s = s.substring(0, comment);
        }

        if (s.length() < 2) {
            continue;
        }

        StringTokenizer st = new StringTokenizer(s, ";");
        int nFields = st.countTokens();
        Character[] fields = new Character[nFields];
        for (int i = 0; i < nFields; i++) {
            fields[i] = (char) Integer.parseInt(st.nextToken().trim(), 16);
        }

        if (fields.length == 2) {
            // initialize the MIRRORING_CHAR_MAP
            MIRRORING_CHAR_MAP.put(fields[0], fields[1]);
        }

    } while (true);
}

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

public String[] getDBList() throws Exception {
    try {//  www .  java 2s.  c  o  m
        verifyConfig();
        String dblist = "";
        try {
            dblist = new String(_props.getProperty(Constants.DATABASES_LIST));
        } catch (Exception e) {
            SmartLogger.logThis(Level.ERROR, "Error on Configurator while retriving the databases list "
                    + Constants.DATABASES_LIST + " " + e);
        }

        StringTokenizer st = new StringTokenizer(dblist, Constants.DELIMITER);
        String[] DatabaseList = new String[st.countTokens()];
        int count = 0;
        while (st.hasMoreTokens()) {
            String token = st.nextToken().toString();
            DatabaseList[count] = token;
            count++;
        }
        // fisdb.close();
        return DatabaseList;
    } catch (Exception ex) {
        SmartLogger.logThis(Level.ERROR, "Error on Configurator while retriving the databases list "
                + Constants.DATABASES_LIST + " " + ex);
        return null;
    }
}

From source file:com.m2a.struts.M2AActionBase.java

/**
 * Return array of tokens,//from   w  w w .  j ava  2  s .  c o m
 * using the result of <code>getTokeSep()</code> as the
 * separator.
 * Blanks are trimmed from tokens.
 *
 * @param parameter The string to tokenize into an array
 */
public String[] tokenize(String parameter) {

    StringTokenizer tokenizer = new StringTokenizer(parameter, getTokenSep());
    int i = 0;
    String[] tokens = new String[tokenizer.countTokens()];
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken().trim();
        if ((token == null) || (token.length() == 0))
            continue;
        tokens[i++] = token;
    }
    return tokens;

}

From source file:com.surevine.alfresco.repo.jscript.People.java

/**
 * Get the collection of people stored in the repository.
 * An optional filter query may be provided by which to filter the people collection.
 * Space separate the query terms i.e. "john bob" will find all users who's first or
 * second names contain the strings "john" or "bob".
 * // w  w  w . j  a  va  2 s . c  o  m
 * @param filter filter query string by which to filter the collection of people.
 *          If <pre>null</pre> then all people stored in the repository are returned
 * @param maxResults maximum results to return or all if <= 0
 * 
 * @return people collection as a JavaScript array
 */
public Scriptable getPeople(String filter, int maxResults) {
    Object[] people = null;

    if (filter == null || filter.length() == 0) {
        people = personService.getAllPeople().toArray();
        if (maxResults > 0 && people.length > maxResults) {
            Object[] dest = new Object[maxResults];
            System.arraycopy(people, 0, dest, 0, maxResults);
            people = dest;
        }
    } else {
        filter = filter.trim();
        if (filter.length() != 0) {
            SearchParameters params = new SearchParameters();

            // define the query to find people by their first or last name
            StringBuilder query = new StringBuilder(256);

            query.append("TYPE:\"").append(ContentModel.TYPE_PERSON).append("\" AND (");

            String term = filter.replace("\\", "").replace("\"", "");
            StringTokenizer t = new StringTokenizer(term, " ");
            if (t.countTokens() == 1) {
                int propIndex = term.indexOf(':');
                if (propIndex == -1) {
                    // simple search: first name, last name, username starting with term, or username ending with "-term"
                    query.append("firstName:\"");
                    query.append(term);
                    query.append("*\" lastName:\"");
                    query.append(term);
                    query.append("*\" userName:\"");
                    query.append(term);
                    query.append("*\" userName:\"*-");
                    query.append(term);
                    query.append("*\"");
                } else {
                    // fts-alfresco property search i.e. location:"maidenhead"
                    query.append(term.substring(0, propIndex + 1)).append('"')
                            .append(term.substring(propIndex + 1)).append('"');
                }
            } else {
                // scan for non-fts-alfresco property search tokens
                int nonFtsTokens = 0;
                while (t.hasMoreTokens()) {
                    if (t.nextToken().indexOf(':') == -1)
                        nonFtsTokens++;
                }
                t = new StringTokenizer(term, " ");

                // multiple terms supplied - look for first and second name etc.
                // assume first term is first name, any more are second i.e. "Fraun van de Wiels"
                // also allow fts-alfresco property search to reduce results
                params.setDefaultOperator(SearchParameters.Operator.AND);
                boolean firstToken = true;
                boolean tokenSurname = false;
                boolean propertySearch = false;
                while (t.hasMoreTokens()) {
                    term = t.nextToken();
                    if (!propertySearch && term.indexOf(':') == -1) {
                        if (nonFtsTokens == 1) {
                            // simple search: first name, last name, username starting with term and username ending with "-term"
                            query.append("(firstName:\"");
                            query.append(term);
                            query.append("*\" OR lastName:\"");
                            query.append(term);
                            query.append("*\" OR userName:\"");
                            query.append(term);
                            query.append("*\" OR userName:\"*-");
                            query.append(term);
                            query.append("*\") ");
                        } else {
                            if (firstToken) {
                                query.append("firstName:\"");
                                query.append(term);
                                query.append("*\" ");

                                firstToken = false;
                            } else {
                                if (tokenSurname) {
                                    query.append("OR ");
                                }
                                query.append("lastName:\"");
                                query.append(term);
                                query.append("*\" ");

                                tokenSurname = true;
                            }
                        }
                    } else {
                        // fts-alfresco property search i.e. "location:maidenhead"
                        int propIndex = term.indexOf(':');
                        query.append(term.substring(0, propIndex + 1)).append('"')
                                .append(term.substring(propIndex + 1)).append('"');

                        propertySearch = true;
                    }
                }
            }
            query.append(")");

            // define the search parameters
            params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
            params.addStore(this.storeRef);
            params.setQuery(query.toString());
            if (maxResults > 0) {
                params.setLimitBy(LimitBy.FINAL_SIZE);
                params.setLimit(maxResults);
            }

            ResultSet results = null;
            try {
                results = services.getSearchService().query(params);
                people = results.getNodeRefs().toArray();
            } catch (Throwable err) {
                // hide query parse error from users
                if (logger.isDebugEnabled())
                    logger.debug("Failed to execute people search: " + query.toString(), err);
            } finally {
                if (results != null) {
                    results.close();
                }
            }
        }
    }

    if (people == null) {
        people = new Object[0];
    }

    return Context.getCurrentContext().newArray(getScope(), people);
}

From source file:egovframework.oe1.cms.mrm.web.EgovOe1ResveMtgController.java

/**
* ? .// www  .  j  av  a2 s  .  co m
* @param egovOe1ResveMtgVO    -    VO
* @param status
* @return "forward:/cms/mrm/selectResveMtgList.do"
* @exception Exception
*/
@RequestMapping("/cms/mrm/updateResveMtgOK.do")
public String updateResveMtgOK(final MultipartHttpServletRequest multiRequest,
        @RequestParam("selectedId") String selectedId,
        @ModelAttribute("egovOe1ResveMtgVO") EgovOe1ResveMtgVO egovOe1ResveMtgVO, BindingResult bindingResult,
        Model model, SessionStatus status) throws Exception {

    log.debug(this.getClass().getName() + " ==> ?  ");

    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    if (!isAuthenticated) {
        return "/cms/com/EgovLoginUsr"; //? ??
    }

    //?   ?   ??.
    model.addAttribute("searchMode", egovOe1ResveMtgVO);

    beanValidator.validate(egovOe1ResveMtgVO, bindingResult);
    if (bindingResult.hasErrors()) {
        model.addAttribute("egovOe1ResveMtgVO", egovOe1ResveMtgVO);
        return "/cms/mrm/EgovResveMtgUpdt";
    }

    //
    EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();

    String atchFileId = egovOe1ResveMtgVO.getAtchFileId();

    egovOe1ResveMtgVO.setMtgRoomResId(selectedId);

    final Map<String, MultipartFile> files = multiRequest.getFileMap();
    if (!files.isEmpty()) {
        if ("".equals(atchFileId)) {
            List<EgovOe1FileVO> result = fileUtil.parseFileInf(files, "MTR_", 0, atchFileId, "");
            atchFileId = fileMngService.insertFileInfs(result);
            egovOe1ResveMtgVO.setAtchFileId(atchFileId);
        } else {
            EgovOe1FileVO fvo = new EgovOe1FileVO();
            fvo.setAtchFileId(atchFileId);
            int cnt = fileMngService.getMaxFileSN(fvo);
            List<EgovOe1FileVO> _result = fileUtil.parseFileInf(files, "MTR_", cnt, atchFileId, "");
            fileMngService.updateFileInfs(_result);
        }
    }
    egovOe1ResveMtgVO.setAtchFileId(atchFileId); //? ?? ID  VO? .
    egovOe1ResveMtgVO.setRegisterId(user.getMberId()); //??? ID VO? .

    String shh = egovOe1ResveMtgVO.getStartHh();
    String smm = egovOe1ResveMtgVO.getStartMm();
    String fhh = egovOe1ResveMtgVO.getFinishHh();
    String fmm = egovOe1ResveMtgVO.getFinishMm();

    egovOe1ResveMtgVO.setMtgStartDate(egovOe1ResveMtgVO.getInsRepeatDate()); //??? 
    egovOe1ResveMtgVO.setMtgEndDate(egovOe1ResveMtgVO.getInsRepeatDate()); //???               
    egovOe1ResveMtgVO.setMtgBeginTime(shh + smm); //?
    egovOe1ResveMtgVO.setMtgEndTime(fhh + fmm); //?
    egovOe1ResveMtgService.updateResveMtg(egovOe1ResveMtgVO); //??? .

    egovOe1ResveMtgService.deleteMtGattenInfo(egovOe1ResveMtgVO); //???  . 

    StringTokenizer st = new StringTokenizer(egovOe1ResveMtgVO.getAttendantId(), "|"); //????
    int n = st.countTokens();
    for (int j = 0; j < n; j++) {
        String token = st.nextToken();
        egovOe1ResveMtgVO.setMtgAttenId(token);
        egovOe1ResveMtgService.insertMtGattenInfo(egovOe1ResveMtgVO);
    }

    status.setComplete();

    if (status.isComplete()) {
        model.addAttribute("resultMsg", "?  ");
    } else {
        model.addAttribute("resultMsg", "?  ");
    }

    return "forward:/cms/mrm/selectResveMtgList.do";
}

From source file:org.apache.directory.fortress.core.ant.FortressAntTask.java

public static Properties getProperties(String inputString) {
    Properties props = new Properties();
    if (inputString != null && inputString.length() > 0) {
        StringTokenizer maxTkn = new StringTokenizer(inputString, SEMICOLON);
        if (maxTkn.countTokens() > 0) {
            while (maxTkn.hasMoreTokens()) {
                String val = maxTkn.nextToken();
                int indx = val.indexOf(GlobalIds.PROP_SEP);
                if (indx >= 1) {
                    String name = val.substring(0, indx);
                    String value = val.substring(indx + 1);
                    props.setProperty(name, value);
                }//www.  j a v a 2 s  .  c  om
            }
        }
    }
    return props;
}