List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:com.silverpeas.form.displayers.CheckBoxDisplayer.java
@Override public int getNbHtmlObjectsDisplayed(FieldTemplate template, PagesContext pagesContext) { String keys = ""; String values = ""; Map<String, String> parameters = template.getParameters(pagesContext.getLanguage()); if (parameters.containsKey("keys")) { keys = parameters.get("keys"); }//from ww w.j a v a2s. com if (parameters.containsKey("values")) { values = parameters.get("values"); } // if either keys or values is not filled // take the same for keys and values if (keys.equals("") && !values.equals("")) { keys = values; } // Calculate numbers of html elements StringTokenizer stKeys = new StringTokenizer(keys, "##"); return stKeys.countTokens(); }
From source file:com.fizzed.rocker.compiler.RockerOptions.java
/** * Create an array of sub-strings from a given comma-separated string. * The contents of each string in the returned array will be trimmed of leading and trailing spaces. * @param value the original string, containing individual comma-separated tokens * @return an array of /*www . j a va2s . c om*/ * @throws TokenException */ private String[] parseStringArrayFromList(String value) throws TokenException { if (value == null) { throw new TokenException("List of strings cannot be null"); } StringTokenizer st = new StringTokenizer(value, ","); String[] tokens = new String[st.countTokens()]; int i = 0; while (st.hasMoreTokens()) { tokens[i++] = st.nextToken().trim(); } return tokens; }
From source file:org.grails.plugins.elasticsearch.conversion.unmarshall.DomainClassUnmarshaller.java
private void populateProperty(String path, Map<String, Object> rebuiltProperties, Object value) { String last = null;//from w w w . j ava2s . c o m Object currentProperty = rebuiltProperties; StringTokenizer st = new StringTokenizer(path, "/"); int size = st.countTokens(); int index = 0; while (st.hasMoreTokens()) { String part = st.nextToken(); if (index < size - 1) { try { if (currentProperty instanceof Collection) { //noinspection unchecked currentProperty = DefaultGroovyMethods.getAt( ((Collection<Object>) currentProperty).iterator(), DefaultGroovyMethods.toInteger(part)); } else { currentProperty = DefaultGroovyMethods.getAt(currentProperty, part); } } catch (Exception e) { LOG.warn("/!\\ Error when trying to populate " + path); LOG.warn("Cannot get " + part + " on " + currentProperty + " from " + rebuiltProperties); e.printStackTrace(); } } if (!st.hasMoreTokens()) { last = part; } index++; } try { Integer.parseInt(last); ((Collection) currentProperty).add(value); } catch (NumberFormatException e) { DefaultGroovyMethods.putAt(currentProperty, last, value); } }
From source file:com.l2jfree.gameserver.datatables.EnchantHPBonusData.java
private EnchantHPBonusData() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);//from w w w . jav a 2s. c o m factory.setIgnoringComments(true); File file = new File(Config.DATAPACK_ROOT, "data/enchantHPBonus.xml"); Document doc = null; try { doc = factory.newDocumentBuilder().parse(file); } catch (Exception e) { _log.warn("", e); return; } for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) { if ("list".equalsIgnoreCase(n.getNodeName())) { for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) { if ("enchantHP".equalsIgnoreCase(d.getNodeName())) { NamedNodeMap attrs = d.getAttributes(); Node att; boolean fullArmor; att = attrs.getNamedItem("grade"); if (att == null) { _log.warn("[EnchantHPBonusData] Missing grade, skipping"); continue; } int grade = Integer.parseInt(att.getNodeValue()); att = attrs.getNamedItem("fullArmor"); if (att == null) { _log.warn("[EnchantHPBonusData] Missing fullArmor, skipping"); continue; } fullArmor = Boolean.valueOf(att.getNodeValue()); att = attrs.getNamedItem("values"); if (att == null) { _log.warn("[EnchantHPBonusData] Missing bonus id: " + grade + ", skipping"); continue; } StringTokenizer st = new StringTokenizer(att.getNodeValue(), ","); int tokenCount = st.countTokens(); Integer[] bonus = new Integer[tokenCount]; for (int i = 0; i < tokenCount; i++) { Integer value = Integer.decode(st.nextToken().trim()); if (value == null) { _log.warn("[EnchantHPBonusData] Bad Hp value!! grade: " + grade + " FullArmor? " + fullArmor + " token: " + i); value = 0; } bonus[i] = value; } if (fullArmor) _fullArmorHPBonus.set(grade, bonus); else _singleArmorHPBonus.set(grade, bonus); } } } } if (_fullArmorHPBonus.isEmpty() && _singleArmorHPBonus.isEmpty()) return; int count = 0; for (L2Item item0 : ItemTable.getInstance().getAllTemplates()) { if (!(item0 instanceof L2Equip)) continue; final L2Equip item = (L2Equip) item0; if (item.getCrystalType() == L2Item.CRYSTAL_NONE) continue; boolean shouldAdd = false; // normally for armors if (item instanceof L2Armor) { switch (item.getBodyPart()) { case L2Item.SLOT_CHEST: case L2Item.SLOT_FEET: case L2Item.SLOT_GLOVES: case L2Item.SLOT_HEAD: case L2Item.SLOT_LEGS: case L2Item.SLOT_BACK: case L2Item.SLOT_FULL_ARMOR: case L2Item.SLOT_UNDERWEAR: case L2Item.SLOT_L_HAND: shouldAdd = true; break; } } // shields in the weapons table else if (item instanceof L2Weapon) { switch (item.getBodyPart()) { case L2Item.SLOT_L_HAND: shouldAdd = true; break; } } if (shouldAdd) { count++; item.attach(new FuncTemplate(null, "EnchantHp", Stats.MAX_HP, 0x60, 0)); } } _log.info("Enchant HP Bonus registered for " + count + " items!"); }
From source file:org.apache.cayenne.tools.NamePatternMatcher.java
/** * Returns an array of valid regular expressions. Takes a comma-separated list of * patterns, attempting to convert them to the java.util.regex.Pattern syntax. E.g. * <p>//from w w w. ja va 2s . c om * <code>"billing_*,user?"</code> will become an array of two expressions: * <p> * <code>^billing_.*$</code><br> * <code>^user.?$</code><br> */ public String[] tokenizePattern(String pattern) { if (pattern != null && pattern.length() > 0) { StringTokenizer toks = new StringTokenizer(pattern, ","); int len = toks.countTokens(); if (len == 0) { return new String[0]; } List<String> patterns = new ArrayList<String>(len); for (int i = 0; i < len; i++) { String nextPattern = toks.nextToken(); StringBuilder buffer = new StringBuilder(); // convert * into regex syntax // e.g. abc*x becomes ^abc.*x$ // or abc?x becomes ^abc.?x$ buffer.append("^"); for (int j = 0; j < nextPattern.length(); j++) { char nextChar = nextPattern.charAt(j); if (nextChar == '*' || nextChar == '?') { buffer.append('.'); } buffer.append(nextChar); } buffer.append("$"); patterns.add(buffer.toString()); } return patterns.toArray(new String[patterns.size()]); } else { return new String[0]; } }
From source file:hydrograph.ui.dataviewer.filter.FilterValidator.java
/** * Validate data based on types./* w w w. j a v a 2 s.com*/ * * @param type * the type * @param value * the value * @param conditionalOperator * the conditional operator * @param debugDataViewer * the debug data viewer * @param fieldName * the field name * @return true, if successful */ public boolean validateDataBasedOnTypes(String type, String value, String conditionalOperator, DebugDataViewer debugDataViewer, String fieldName) { try { if (FilterConstants.IN.equalsIgnoreCase(conditionalOperator) || FilterConstants.NOT_IN.equalsIgnoreCase(conditionalOperator)) { if (value.contains(FilterConstants.DELIM_COMMA)) { StringTokenizer tokenizer = new StringTokenizer(value, FilterConstants.DELIM_COMMA); int numberOfTokens = tokenizer.countTokens(); for (int index = 0; index < numberOfTokens; index++) { validate(type, tokenizer.nextToken(), debugDataViewer, fieldName); } } else { validate(type, value, debugDataViewer, fieldName); } } else if (FilterConstants.BETWEEN.equalsIgnoreCase(conditionalOperator)) { validate(type, value, debugDataViewer, fieldName); } else { validate(type, value, debugDataViewer, fieldName); } } catch (Exception exception) { logger.trace("value can not be converted to {}", new Object[] { type }); return false; } return true; }
From source file:de.suse.swamp.core.data.Dataset.java
/** * @return attached dataset of the given name *///from www .j ava 2 s .co m public Dataset getDataset(String datasetName) { Dataset dSet = null; StringTokenizer st = new StringTokenizer(datasetName, "."); if (st.countTokens() == 0) { Logger.BUG("Requesting empty dsetname in dset: " + this.getId()); } else if (st.countTokens() == 1) { dSet = DatasetCache.getInstance().getByName(this.dataSetIdCache, datasetName); if (dSet == null) { // Set not yet in idcache or global cache, load + store it dSet = DataManager.loadChildDataset(getId(), datasetName); if (dSet != null) { this.dataSetIdCache.add(new Integer(dSet.getId())); } } } else if (st.countTokens() > 1) { String firstSet = st.nextToken(); String targetSet = datasetName.substring(firstSet.length() + 1); // redirecting request to the next dataset dSet = getDataset(firstSet); dSet = dSet.getDataset(targetSet); } return dSet; }
From source file:de.suse.swamp.core.data.Dataset.java
/** Searches for the requested Databit. * @param field the path of the databit, relative to this dataset * @return the requested Databit if found, null if not *///from w w w. j a va2 s. co m public Databit getDatabit(String field) { Databit dbit = null; // query the databit-cache if (dataBitCache.containsKey(field)) { dbit = (Databit) dataBitCache.get(field); } else { // Logger.DEBUG("Looking for Databit in fieldpath " + field); StringTokenizer st = new StringTokenizer(field, "."); if (st.countTokens() == 0) { Logger.BUG("Requesting empty fieldname in set: " + this.name); } else if (st.countTokens() == 1) { // the databit is located in this dataset String databitName = st.nextToken(); dbit = DataManager.loadDatabit(this.getId(), databitName); dataBitCache.put(field, dbit); } else if (st.countTokens() > 1) { String datasetName = st.nextToken(); // redirecting request to the next dataset Dataset dataset = (Dataset) getDataset(datasetName); String newField = field.substring(datasetName.length() + 1); if (dataset != null) { dbit = dataset.getDatabit(newField); } } } return dbit; }
From source file:com.joliciel.talismane.machineLearning.maxent.custom.RealValueFileEventStream2.java
@Override public Event next() { StringTokenizer st = new StringTokenizer(line); String outcome = st.nextToken(); if (outcome.equals("&null;")) outcome = ""; else if (outcome.equals("&space;")) outcome = " "; int count = st.countTokens(); // Assaf update: read real values from file boolean hasValues = line.contains("="); String[] context = new String[count]; float[] values = null; if (hasValues) values = new float[count]; for (int ci = 0; ci < count; ci++) { String token = st.nextToken(); if (hasValues) { int equalsPos = token.lastIndexOf('='); if (equalsPos < 0) { LOG.error("Missing value"); LOG.error("Line: " + line); LOG.error("Token: " + token); throw new RuntimeException("Missing value, on token \"" + token + "\""); }/*from www.j a va 2 s.c om*/ context[ci] = token.substring(0, equalsPos); values[ci] = Float.parseFloat(token.substring(equalsPos + 1)); } else { context[ci] = token; } } Event event = null; if (hasValues) event = new Event(outcome, context, values); else event = new Event(outcome, context); return event; }
From source file:asia.stampy.common.parsing.StompMessageParser.java
private <MSG extends StampyMessage<?>> void addHeaders(MSG message, List<String> headers) throws UnparseableException { for (String header : headers) { StringTokenizer st = new StringTokenizer(header, ":"); if (st.countTokens() < 1) { log.error("Cannot parse STOMP header {}", header); throw new UnparseableException("Cannot parse STOMP header " + header); }/*from w w w . j a v a 2 s .com*/ String value = ""; String key = st.nextToken(); if (st.hasMoreTokens()) { value = header.substring(key.length() + 1); } message.getHeader().addHeader(key, value); } }