List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:com.amazonaws.services.s3.util.Mimetypes.java
/** * Reads and stores the mime type setting corresponding to a file extension, * by reading text from an InputStream. If a mime type setting already * exists when this method is run, the mime type value is replaced with the * newer one.//from w ww .ja v a2 s.co m * * @param is the input stream. * @throws IOException */ public void loadAndReplaceMimetypes(InputStream is) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(is, StringUtils.UTF8)); String line = null; while ((line = br.readLine()) != null) { line = line.trim(); if (line.startsWith("#") || line.length() == 0) { // Ignore comments and empty lines. log.debug("Ignoring comments and empty lines."); } else { StringTokenizer st = new StringTokenizer(line, " \t"); if (st.countTokens() > 1) { String mimetype = st.nextToken(); while (st.hasMoreTokens()) { String extension = st.nextToken(); extensionToMimetypeMap.put(StringUtils.lowerCase(extension), mimetype); if (log.isDebugEnabled()) { log.debug("Setting mime type for extension '" + StringUtils.lowerCase(extension) + "' to '" + mimetype + "'"); } } } else { if (log.isDebugEnabled()) { log.debug("Ignoring mimetype with no associated file extensions: '" + line + "'"); } } } } }
From source file:edu.ucla.stat.SOCR.chart.SuperDotChart.java
public void setDataTable(String input) { hasExample = true;/*from w ww .j ava 2s . co m*/ StringTokenizer lnTkns = new StringTokenizer(input, "#;,"); String line; int lineCt = lnTkns.countTokens(); resetTableRows(lineCt); 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(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], r, i); } r++; } // this will update the mapping panel resetTableColumns(dataTable.getColumnCount()); }
From source file:org.ambraproject.article.action.EmailArticleAction.java
private boolean checkEmails(String emailList) { if (StringUtils.isBlank(emailList)) { addFieldError("emailTo", "To e-mail address cannot be empty"); return false; } else {//from ww w. j a va 2s .c o m 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:org.solmix.runtime.support.spring.AbstractBeanDefinitionParser.java
/**id ?*/ protected String getIdOrName(Element elem) { String id = elem.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE); //ID,name//from ww w . ja va 2s . c om if (null == id || "".equals(id)) { String names = elem.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE); if (null != names) { StringTokenizer st = new StringTokenizer(names, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS); //? if (st.countTokens() > 0) { id = st.nextToken(); } } } return id; }
From source file:com.heneryh.aquanotes.ui.livestock.ContentFragment.java
boolean processDrop(DragEvent event, ImageView imageView) { // Attempt to parse clip data with expected format: category||entry_id. // Ignore event if data does not conform to this format. ClipData data = event.getClipData(); if (data != null) { if (data.getItemCount() > 0) { Item item = data.getItemAt(0); String textData = (String) item.getText(); if (textData != null) { StringTokenizer tokenizer = new StringTokenizer(textData, "||"); if (tokenizer.countTokens() != 2) { return false; }/*from ww w .j ava 2 s. c om*/ int category = -1; int entryId = -1; try { category = Integer.parseInt(tokenizer.nextToken()); entryId = Integer.parseInt(tokenizer.nextToken()); } catch (NumberFormatException exception) { return false; } updateContentAndRecycleBitmap(category, entryId); // Update list fragment with selected entry. // TitlesFragment titlesFrag = (TitlesFragment) // getFragmentManager().findFragmentById(R.id.titles_frag); // titlesFrag.selectPosition(entryId); return true; } } } return false; }
From source file:TaskManager.java
private void addTaskDefinition(String taskLine) { StringTokenizer taskTok = new StringTokenizer(taskLine, DELIM); if (taskTok.countTokens() != TOKEN_NUM) { System.err.println("Invalid task definition: " + taskLine); return;/*from w w w.j a v a 2 s . c o m*/ } Class taskClass = null; String taskClassName = taskTok.nextToken(); try { taskClass = Class.forName(taskClassName); } catch (ClassNotFoundException cnfX) { System.err.println("Class '" + taskClassName + "' not found: " + cnfX); return; } boolean taskEnabled = false; if (taskTok.nextToken().equalsIgnoreCase("enabled")) { taskEnabled = true; } String taskName = taskTok.nextToken(); TaskDefinition def = new TaskDefinition(taskName, taskClass, taskEnabled); taskDefs.add(def); }
From source file:com.silverpeas.ical.ImportIcalManager.java
/** * Add or update categories of the event * @param eventIcal/*from ww w.j ava2 s. c om*/ * @param idEvent * @throws Exception */ private void processCategories(Component eventIcal, String idEvent) throws Exception { if (eventIcal.getProperty(Property.CATEGORIES) != null) { String categories = eventIcal.getProperty(Property.CATEGORIES).getValue(); StringTokenizer st = new StringTokenizer(categories, ","); String[] categoryIds = new String[st.countTokens()]; int j = 0; boolean addCategoryToEvent = false; while (st.hasMoreTokens()) { String categIcal = st.nextToken(); // Agenda Categories for (Category category : agendaSessionController.getAllCategories()) { if (categIcal.equals(EncodeHelper.htmlStringToJavaString(category.getName()))) { addCategoryToEvent = true; categoryIds[j++] = category.getId(); } } } if (addCategoryToEvent) { agendaSessionController.setJournalCategories(idEvent, categoryIds); } } }
From source file:eu.stratosphere.pact.test.pactPrograms.KMeansIterationITCase.java
@Override protected void postSubmit() throws Exception { Comparator<String> deltaComp = new Comparator<String>() { private final double DELTA = 0.1; @Override/*from www . jav a 2s . c o m*/ public int compare(String o1, String o2) { StringTokenizer st1 = new StringTokenizer(o1, "|"); StringTokenizer st2 = new StringTokenizer(o2, "|"); if (st1.countTokens() != st2.countTokens()) { return st1.countTokens() - st2.countTokens(); } // first token is ID String t1 = st1.nextToken(); String t2 = st2.nextToken(); if (!t1.equals(t2)) { return t1.compareTo(t2); } while (st1.hasMoreTokens()) { t1 = st1.nextToken(); t2 = st2.nextToken(); double d1 = Double.parseDouble(t1); double d2 = Double.parseDouble(t2); if (Math.abs(d1 - d2) > DELTA) { return d1 < d2 ? -1 : 1; } } return 0; } }; // Test results compareResultsByLinesInMemory(NEWCLUSTERCENTERS, resultPath, deltaComp); // clean up file getFilesystemProvider().delete(dataPath, true); getFilesystemProvider().delete(clusterPath, true); getFilesystemProvider().delete(resultPath, true); }
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_StatA.java
public void setDataTable(String input) { hasExample = true;/*from w ww. j a v a 2s. c o m*/ StringTokenizer lnTkns = new StringTokenizer(input, "#"); String line; int lineCt = lnTkns.countTokens(); resetTableRows(lineCt); int r = 0; while (lnTkns.hasMoreTokens()) { line = lnTkns.nextToken(); // String tb[] =line.split("\t"); StringTokenizer cellTkns = new StringTokenizer(line, ";");// 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(colCt * 2 - 1); for (int i = 0; i < tb.length; i++) { //System.out.println(tb[i]); if (tb[i].length() == 0) tb[i] = "0"; if (i == 0) dataTable.setValueAt(tb[i], r, i); else { StringTokenizer cTkns = new StringTokenizer(tb[i], ","); int cCnt = cTkns.countTokens(); String ctb[] = new String[cCnt]; int r2 = 0; while (cTkns.hasMoreTokens()) { ctb[r2] = cTkns.nextToken(); r2++; } for (int j = 0; j < ctb.length; j++) { dataTable.setValueAt(ctb[j], r, (i - 1) * 2 + j + 1); } } } r++; } // this will update the mapping panel resetTableColumns(dataTable.getColumnCount()); }
From source file:com.l2jfree.gameserver.handler.admincommands.AdminSkill.java
private void adminAddSkill(L2Player activeChar, String val) { L2Object target = activeChar.getTarget(); L2Player player = null;/* ww w . ja va 2 s . c om*/ if (target instanceof L2Player) player = (L2Player) target; else { activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET); return; } StringTokenizer st = new StringTokenizer(val); if (st.countTokens() != 2) { showMainPage(activeChar); } else { L2Skill skill = null; try { String id = st.nextToken(); String level = st.nextToken(); int idval = Integer.parseInt(id); int levelval = Integer.parseInt(level); skill = SkillTable.getInstance().getInfo(idval, levelval); } catch (Exception e) { } if (skill != null) { String name = skill.getName(); player.sendMessage("Admin gave you the skill " + name + "."); player.addSkill(skill, true); //Admin information activeChar.sendMessage("You gave the skill " + name + " to " + player.getName() + "."); if (_log.isDebugEnabled()) _log.debug("[GM]" + activeChar.getName() + " gave skill " + name + " to " + player.getName() + "."); player.sendSkillList(); } else activeChar.sendMessage("Error: there is no such skill."); showMainPage(activeChar); //Back to start } }