List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:hudson.plugins.testlink.AbstractTestLinkBuilder.java
/** * Creates array of custom fields names using the Job configuration data. * @param variableResolver Jenkins variable resolver * @param envVars Jenkins environment variables * //from www .ja v a 2 s . c om * @return Array of custom fields names. */ protected String[] createArrayOfCustomFieldsNames(final VariableResolver<String> variableResolver, final EnvVars envVars) { String[] customFieldNamesArray = new String[0]; String customFields = expandVariable(variableResolver, envVars, this.getCustomFields()); if (StringUtils.isNotBlank(customFields)) { StringTokenizer tokenizer = new StringTokenizer(customFields, COMMA); if (tokenizer.countTokens() > 0) { customFieldNamesArray = new String[tokenizer.countTokens()]; int index = 0; while (tokenizer.hasMoreTokens()) { String customFieldName = tokenizer.nextToken(); customFieldName = customFieldName.trim(); customFieldNamesArray[index] = customFieldName; index = index + 1; } } } return customFieldNamesArray; }
From source file:org.eclipse.virgo.ide.bundlor.jdt.core.ArtifactAnalyserTypeVisitor.java
private String recordFullyQualifiedName(String fqn) { if (!"void".equals(fqn)) { if (this.typePackage == null) { this.referencedTypes.add(fqn); return fqn; } else if (fqn != null && !this.typePackage.equals(getPackageName(fqn))) { // This is required to get FQCNs of the form // org.springframework.util.ReflectionUtils.MethodCallback correctly detected StringTokenizer segments = new StringTokenizer(fqn, "."); if (segments.countTokens() > 1) { List<String> newSegments = new ArrayList<String>(); while (segments.hasMoreTokens()) { String segment = segments.nextToken(); newSegments.add(segment); if (!Character.isLowerCase(segment.charAt(0))) { break; }/*from ww w. j a v a 2 s.c o m*/ } fqn = StringUtils.join(newSegments, "."); } this.partialManifest.recordReferencedType(fqn); return fqn; } } return ""; }
From source file:edu.stanford.muse.index.Summarizer.java
private String cardStats(List<Card> clouds) { if (clouds == null) return "No top terms"; StringBuilder sb = new StringBuilder(); sb.append("Top terms: " + clouds.size() + " superdocs, "); int nWords = 0, nTags = 0; Map<Integer, Integer> colorFreq = new LinkedHashMap<Integer, Integer>(); // count of how many times a color occurs int nMultipleColorTags = 0; // docs with at least one term pointing to them Set<Document> docsCoveredByColors = new LinkedHashSet<Document>(); for (Card tc : clouds) { for (CardTerm tct : tc.terms) { // count # of words StringTokenizer st = new StringTokenizer(tct.lookupTerm); int count = st.countTokens(); nWords += count;//w w w . j a va 2s . com nTags++; int color = tct.bestColor(); if (color != -1) { Collection<Document> docsWithPhrase = indexer.docsForQuery(tct.lookupTerm, new Indexer.QueryOptions()); docsCoveredByColors.addAll(docsWithPhrase); } if (tct.colorWeights != null && tct.colorWeights.size() > 1) nMultipleColorTags++; // update color freqs Integer I = colorFreq.get(color); if (I == null) colorFreq.put(color, 1); else colorFreq.put(color, I + 1); } } sb.append(nTags + " phrases with " + nWords + " words\n"); sb.append(nMultipleColorTags + " phrases with possibly multiple colors\n"); sb.append(docsCoveredByColors.size() + " docs are pointed to by at least one term\n"); sb.append("Color histogram for selected terms:\n"); // idea: show this as a protovis graph for (int c = -1; c < 100; c++) // randomly picking 100, should go to max # colors. TOFIX { Integer I = colorFreq.get(c); if (I != null) sb.append("Color: " + c + " : " + I + "\n"); } return sb.toString(); }
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_vertical.java
public void setDataTable(String input) { hasExample = true;//from w ww .jav a2s.c o m StringTokenizer lnTkns = new StringTokenizer(input, "#"); String line; int lineCt = lnTkns.countTokens(); int r = 0; while (lnTkns.hasMoreTokens()) { line = lnTkns.nextToken(); // String tb[] =line.split("\t"); StringTokenizer cellTkns = new StringTokenizer(line, " \t\f,");// IE use "space" Mac use tab as cell separator int cellCnt = cellTkns.countTokens(); String tb[] = new String[cellCnt]; int r1 = 0; while (cellTkns.hasMoreTokens()) { tb[r1] = cellTkns.nextToken(); r1++; } //System.out.println("tb.length="+tb.length); int colCt = tb.length; resetTableColumns(lineCt + 1); resetTableRows(colCt); for (int i = 0; i < tb.length; i++) { //System.out.println(tb[i]); if (tb[i].length() == 0) tb[i] = "0"; dataTable.setValueAt(tb[i], i, r + 1); dataTable.setValueAt(Integer.toString(i), i, 0); //the first column is line count } r++; } // this will update the mapping panel resetTableColumns(dataTable.getColumnCount()); }
From source file:net.jawr.web.resource.bundle.generator.validator.CommonsValidatorGenerator.java
private void createValidatorResources(String path, JawrConfig config) { ValidatorResources validatorResources = null; String configPaths = config.getConfigProperties().getProperty(path); StringTokenizer st = new StringTokenizer(configPaths, ","); InputStream[] inputStreams = new InputStream[st.countTokens()]; int pos = 0;/*from w w w. j a v a2 s. co m*/ try { while (st.hasMoreTokens()) { String validatorRules = st.nextToken().trim(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Validation rules file from '" + validatorRules + "'"); } InputStream is = null; try { is = ClassLoaderResourceUtils.getResourceAsStream(validatorRules, this); } catch (FileNotFoundException fos) { is = config.getContext().getResourceAsStream(validatorRules); } inputStreams[pos] = is; pos++; } validatorResources = new ValidatorResources(inputStreams); } catch (SAXException ex) { throw new BundlingProcessException(ex); } catch (IOException e) { throw new BundlingProcessException(e); } validatorResourcesMap.put(path, validatorResources); }
From source file:edu.stanford.muse.util.EmailUtils.java
public static String normalizePersonNameForLookup(String name) { if (name == null) return null; String originalName = name;/* w w w.j av a 2 s . c o m*/ name = cleanPersonName(name); //cleanPersonName returns null for singlw word names for some reason if (name == null) { if (originalName.indexOf(' ') == -1) { name = originalName; name = name.toLowerCase(); name = name.replaceAll("^\\W+|\\W+$", ""); return name; } return null; } // remove all periods and commas // in future: consider removing all non-alpha, non-number chars. // but should we also remove valid quote chars in names like O'Melveny // also be careful of foreign names name = name.replaceAll("\\.", " "); // make sure to escape the period, replaceAll's first param is a regex! name = name.replaceAll(",", " "); StringTokenizer st = new StringTokenizer(name); if (st.countTokens() <= 1) { return name; } // gather all the words in the name into tokens and sort it List<String> tokens = new ArrayList<String>(); while (st.hasMoreTokens()) tokens.add(st.nextToken().toLowerCase()); if (tokens.size() > 2) { int nOneLetterTokens = 0, nMultiLetterTokens = 0; for (String t : tokens) { if (t.length() > 1) nMultiLetterTokens++; else nOneLetterTokens++; } // if we have at least 2 multi-letter names, then ignore initials if (nMultiLetterTokens >= 2 && nOneLetterTokens >= 1) for (Iterator<String> it = tokens.iterator(); it.hasNext();) { String t = it.next(); if (t.length() == 1) it.remove(); // this is an initial, remove it. } } Collections.sort(tokens); // enable variants tokens = tokens.stream().map(Variants.nameVariants::getCanonicalVariant).collect(Collectors.toList()); // cat all the tokens, one space in between, no space at the end String cname = Util.join(tokens, " "); /* * StringBuilder sb = new StringBuilder(); * for (int i = 0; i < tokens.size(); i++) * { * sb.append(tokens.get(i)); * if (i < tokens.size()-1) * sb.append (" "); * } */ if (Util.nullOrEmpty(cname)) { // unlikely case, but can happen if input string was "" or just periods and commas // we don't know whats going in in that case, just be safe and return the original name // better to return the original name than cause merging and confusion with an empty normalized name return originalName; } return cname; }
From source file:gda.function.lookup.LookupTable.java
/** * Takes a string of comma, space or tab separated values and parses it into an array of doubles * //www. ja va 2 s . co m * @param string * the input string * @return an array of doubles found in the string */ private double[] stringToDoubleArray(String string) { double[] values; StringTokenizer strtok = new StringTokenizer(string, ", \t"); values = new double[strtok.countTokens()]; int i = 0; while (strtok.hasMoreTokens()) { values[i] = Double.valueOf(strtok.nextToken()).doubleValue(); i++; } return values; }
From source file:edu.ucla.stat.SOCR.chart.SuperXYChart_QQ_DD.java
public void setDataTable(String input) { hasExample = true;/* w w w . j av a 2s. c om*/ StringTokenizer lnTkns = new StringTokenizer(input, "#"); String line; int lineCt = lnTkns.countTokens(); resetTableRows(0); resetTableColumns(lineCt); int r = 0; while (lnTkns.hasMoreTokens()) { line = lnTkns.nextToken(); // String tb[] =line.split("\t"); StringTokenizer cTkns = new StringTokenizer(line, ";"); if (r == 0) { domainLabel = cTkns.nextToken(); } if (r == 1) { rangeLabel = cTkns.nextToken(); } StringTokenizer cellTkns = new StringTokenizer(cTkns.nextToken(), ","); int cellCnt = cellTkns.countTokens(); String tb[] = new String[cellCnt]; int r1 = 0; while (cellTkns.hasMoreTokens()) { tb[r1] = cellTkns.nextToken(); r1++; } //System.out.println("tb.length="+tb.length); int colCt = tb.length; // System.out.println("rowCount="+dataTable.getRowCount()+" input count="+colCt); if (dataTable.getRowCount() < colCt) resetTableRows(colCt); for (int i = 0; i < tb.length; i++) { dataTable.setValueAt(tb[i], i, r); } r++; } // this will update the mapping panel resetTableColumns(dataTable.getColumnCount()); TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(0).setHeaderValue(domainLabel); columnModel.getColumn(1).setHeaderValue(rangeLabel); }
From source file:com.qframework.core.ItemFactory.java
public void setTexture(String strType, String strData) { // get object GameonModel model = mModels.get(strType); if (model == null) { return;/* w w w . j av a2 s . c o m*/ } int offsetx = 0, offsety = 0; String texture = null; StringTokenizer tok = new StringTokenizer(strData, ";"); if (tok.countTokens() == 1) { // no offset texture = strData; } else { texture = tok.nextToken(); String offset = tok.nextToken(); StringTokenizer tok2 = new StringTokenizer(offset, ","); offsetx = Integer.parseInt(tok2.nextToken()); offsety = Integer.parseInt(tok2.nextToken()); } model.mTextureID = mApp.textures().getTexture(texture); model.setTextureOffset(offsetx, offsety); }
From source file:org.alfresco.web.app.servlet.BaseTemplateContentServlet.java
/** * Processes the template request using the current context i.e. no * authentication checks are made, it is presumed they have already * been done./*from w w w . ja v a2s .c o m*/ * * @param req The HTTP request * @param res The HTTP response * @param redirectToLogin Flag to determine whether to redirect to the login * page if the user does not have the correct permissions */ protected void processTemplateRequest(HttpServletRequest req, HttpServletResponse res, boolean redirectToLogin) throws ServletException, IOException { Log logger = getLogger(); String uri = req.getRequestURI(); if (logger.isDebugEnabled()) { String queryString = req.getQueryString(); logger.debug("Processing URL: " + uri + ((queryString != null && queryString.length() > 0) ? ("?" + queryString) : "")); } uri = uri.substring(req.getContextPath().length()); StringTokenizer t = new StringTokenizer(uri, "/"); int tokenCount = t.countTokens(); t.nextToken(); // skip servlet name NodeRef nodeRef = null; NodeRef templateRef = null; try { String contentPath = req.getParameter(ARG_CONTEXT_PATH); if (contentPath != null && contentPath.length() != 0) { // process the name based path to resolve the NodeRef PathRefInfo pathInfo = resolveNamePath(getServletContext(), contentPath); nodeRef = pathInfo.NodeRef; } else if (tokenCount > 3) { // get NodeRef to the content from the URL elements StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken()); nodeRef = new NodeRef(storeRef, t.nextToken()); } // get NodeRef to the template if supplied String templatePath = req.getParameter(ARG_TEMPLATE_PATH); if (templatePath != null && templatePath.length() != 0) { // process the name based path to resolve the NodeRef PathRefInfo pathInfo = resolveNamePath(getServletContext(), templatePath); templateRef = pathInfo.NodeRef; } else if (tokenCount >= 7) { StoreRef storeRef = new StoreRef(t.nextToken(), t.nextToken()); templateRef = new NodeRef(storeRef, t.nextToken()); } } catch (AccessDeniedException err) { if (redirectToLogin) { if (logger.isDebugEnabled()) logger.debug("Redirecting to login page..."); redirectToLoginPage(req, res, getServletContext()); } else { if (logger.isDebugEnabled()) logger.debug("Returning 403 Forbidden error..."); res.sendError(HttpServletResponse.SC_FORBIDDEN); } return; } // if no context is specified, use the template itself // TODO: should this default to something else? if (nodeRef == null && templateRef != null) { nodeRef = templateRef; } if (nodeRef == null) { throw new TemplateException("Not enough elements supplied in URL or no 'path' argument specified."); } // get the services we need to retrieve the content ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext()); NodeService nodeService = serviceRegistry.getNodeService(); TemplateService templateService = serviceRegistry.getTemplateService(); PermissionService permissionService = serviceRegistry.getPermissionService(); // check that the user has at least READ access on any nodes - else redirect to the login page if (permissionService.hasPermission(nodeRef, PermissionService.READ) == AccessStatus.DENIED || (templateRef != null && permissionService.hasPermission(templateRef, PermissionService.READ) == AccessStatus.DENIED)) { if (redirectToLogin) { if (logger.isDebugEnabled()) logger.debug("Redirecting to login page..."); redirectToLoginPage(req, res, getServletContext()); } else { if (logger.isDebugEnabled()) logger.debug("Returning 403 Forbidden error..."); res.sendError(HttpServletResponse.SC_FORBIDDEN); } return; } String mimetype = MIMETYPE_HTML; if (req.getParameter(ARG_MIMETYPE) != null) { mimetype = req.getParameter(ARG_MIMETYPE); } res.setContentType(mimetype); try { UserTransaction txn = null; try { txn = serviceRegistry.getTransactionService().getUserTransaction(true); txn.begin(); // if template not supplied, then use the default against the node if (templateRef == null) { if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TEMPLATABLE)) { templateRef = (NodeRef) nodeService.getProperty(nodeRef, ContentModel.PROP_TEMPLATE); } if (templateRef == null) { throw new TemplateException( "Template reference not set against node or not supplied in URL."); } } // create the model - put the supplied noderef in as space/document as appropriate Map<String, Object> model = getModel(serviceRegistry, req, templateRef, nodeRef); // process the template against the node content directly to the response output stream // assuming the repo is capable of streaming in chunks, this should allow large files // to be streamed directly to the browser response stream. try { templateService.processTemplate(templateRef.toString(), model, res.getWriter()); // commit the transaction txn.commit(); } catch (SocketException e) { if (e.getMessage().contains("ClientAbortException")) { // the client cut the connection - our mission was accomplished apart from a little error message logger.error("Client aborted stream read:\n node: " + nodeRef + "\n template: " + templateRef); try { if (txn != null) { txn.rollback(); } } catch (Exception tex) { } } else { throw e; } } finally { res.getWriter().close(); } } catch (Throwable txnErr) { try { if (txn != null) { txn.rollback(); } } catch (Exception tex) { } throw txnErr; } } catch (Throwable err) { throw new AlfrescoRuntimeException("Error during template servlet processing: " + err.getMessage(), err); } }