List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:org.sonar.server.charts.deprecated.BarChart.java
private void addMeasures(String values) { if (values != null && values.length() > 0) { // Values StringTokenizer stValues = new StringTokenizer(values, ","); int nbValues = stValues.countTokens(); // Categories String categoriesParam = params.get(BaseChartWeb.CHART_PARAM_CATEGORIES); String[] categoriesSplit; if (categoriesParam != null && categoriesParam.length() > 0) { categoriesSplit = categoriesParam.split(","); } else {/*from www. j a va2 s . c o m*/ categoriesSplit = new String[1]; categoriesSplit[0] = BaseChartWeb.DEFAULT_NAME_CATEGORY; } // Series String seriesParam = params.get(BaseChartWeb.CHART_PARAM_SERIES); String[] seriesSplit = null; if (seriesParam != null && seriesParam.length() > 0) { seriesSplit = seriesParam.split(","); } else { seriesSplit = new String[nbValues]; for (int i = 0; i < nbValues; i++) { seriesSplit[i] = BaseChartWeb.DEFAULT_NAME_SERIE + i; } } for (String currentCategory : categoriesSplit) { for (String currentSerie : seriesSplit) { double currentValue = 0.0; if (stValues.hasMoreTokens()) { try { currentValue = Double.parseDouble(stValues.nextToken()); } catch (NumberFormatException e) { // ignore } } dataset.addValue(currentValue, currentSerie, currentCategory); } } } }
From source file:net.java.sen.tools.DictionaryMaker.java
public void build() { int size = 0; // iterate variation for (Iterator i = ruleSet.iterator(); i.hasNext();) { ruleList.setSize(size + 1);/*from ww w . j a va 2 s .c om*/ String str = (String) i.next(); rule2IdHash.put(str, new Integer(size)); // tokenList: split valiation information. StringTokenizer st = new StringTokenizer(str, ","); int len = st.countTokens(); String tokenList[] = new String[len]; for (int j = 0; j < len; j++) { tokenList[j] = st.nextToken(); } ruleList.set(size, tokenList); // System.out.println("tokenList="+tokenList[len-1]); if (tokenList[len - 1].charAt(0) != '*') isLexcalized.put(tokenList[len - 1], "1"); size++; } // System.out.println("size="+size); // System.out.println("ruleList size="+ruleList.size()); // System.out.println("test"); ruleSet.clear(); idList.setSize(ruleList.size()); for (int i = 0; i < ruleList.size(); i++) { Vector v = new Vector(); idList.set(i, v); getIdList((String[]) ruleList.get(i), (Vector) idList.get(i), 0); } }
From source file:de.suse.swamp.core.filter.ContentFilter.java
private String getDatabitName() { StringTokenizer st = new StringTokenizer(databitPath, "."); String databitName = ""; while (st.countTokens() > 0) { databitName = st.nextToken();/*from w w w . j ava 2 s .c o m*/ } return databitName; }
From source file:com.netspective.medigy.ant.DiagramGeneratorTask.java
protected void generateModelDiagrams(final HibernateConfiguration hibernateConfiguration) throws IOException { String systemFileSep = System.getProperty("file.separator"); final File outDir = new File(outputDir); final String dialectName = hibernateConfiguration.getProperties().getProperty(Environment.DIALECT); final String dialectShortName = dialectName.substring(dialectName.lastIndexOf('.') + 1); int i = 0;/*www .j a va2 s .c o m*/ final StringTokenizer tokenizer = new StringTokenizer(outputFileTypes, ","); final String[] typeList = new String[tokenizer.countTokens()]; while (tokenizer.hasMoreTokens()) { typeList[i++] = tokenizer.nextToken(); } // Generate a DOT (GraphViz) diagram so we can visualize the DDL // the first version is good for software engineers generateDiagram(hibernateConfiguration, outDir.getAbsolutePath() + systemFileSep + diagramNamePrefix + dialectShortName + "-se", new HibernateDiagramFilter(true, true, true, true), typeList); // Generate a DOT (GraphViz) diagram so we can visualize the DDL // the second version is good for software engineers looking for general table structure (no column information) generateDiagram(hibernateConfiguration, outDir.getAbsolutePath() + systemFileSep + diagramNamePrefix + dialectShortName + "-set", new HibernateDiagramFilter(false, true, true, true), typeList); // the third version is good for database administrators (simple ERD) generateDiagram(hibernateConfiguration, outDir.getAbsolutePath() + systemFileSep + diagramNamePrefix + dialectShortName + "-erd", new HibernateDiagramFilter(true, false, false, false), typeList); }
From source file:op.tools.SYSCalendar.java
/** * erkennt Uhrzeiten im Format HH:MM und erstellt einen GregorianCalendar basierend auf ref *///from w ww .j ava2s . com public static GregorianCalendar parseTime(String input, GregorianCalendar gc) throws NumberFormatException { if (input == null || input.equals("")) { throw new NumberFormatException("leere Eingabe"); } StringTokenizer st = new StringTokenizer(input, ":,."); if (st.countTokens() > 3) { throw new NumberFormatException("falsches Format"); } String sStunde = "00"; String sMinute = "00"; String sSekunde = "00"; if (st.countTokens() == 1) { // maybe a simple hour sStunde = st.nextToken(); } else if (st.countTokens() == 2) { // maybe a simple hour sStunde = st.nextToken(); sMinute = st.nextToken(); } else { sStunde = st.nextToken(); sMinute = st.nextToken(); sSekunde = st.nextToken(); } int stunde, minute, sekunde; GregorianCalendar now = (GregorianCalendar) gc.clone(); try { stunde = Integer.parseInt(sStunde); } catch (NumberFormatException nfe) { throw new NumberFormatException("stunde"); } try { minute = Integer.parseInt(sMinute); } catch (NumberFormatException nfe) { throw new NumberFormatException("minute"); } try { sekunde = Integer.parseInt(sSekunde); } catch (NumberFormatException nfe) { throw new NumberFormatException("Sekunde"); } if (stunde < 0) { throw new NumberFormatException("stunde"); } if (stunde > 23) { throw new NumberFormatException("stunde"); } if (minute < 0 || minute > 59) { throw new NumberFormatException("minute"); } if (sekunde < 0 || sekunde > 59) { throw new NumberFormatException("Sekunde"); } now.set(GregorianCalendar.HOUR_OF_DAY, stunde); now.set(GregorianCalendar.MINUTE, minute); now.set(GregorianCalendar.SECOND, sekunde); return now; }
From source file:com.projity.graphic.configuration.BarStyles.java
protected void initZoomX() { if (zoomRatioX == null) { if (zoomX == null) return; StringTokenizer st = new StringTokenizer(zoomX, ",;:|"); zoomRatioX = new double[st.countTokens()]; int index = 0; while (st.hasMoreTokens()) { String s = st.nextToken(); if ("*".equals(s)) defaultZoomIndexX = index; else/* ww w . java 2s .c o m*/ zoomRatioX[index++] = Double.parseDouble(s); } } }
From source file:com.projity.graphic.configuration.BarStyles.java
protected void initZoomY() { if (zoomRatioY == null) { if (zoomY == null) return; StringTokenizer st = new StringTokenizer(zoomY, ",;:|"); zoomRatioY = new double[st.countTokens()]; int index = 0; while (st.hasMoreTokens()) { String s = st.nextToken(); if ("*".equals(s)) defaultZoomIndexY = index; else//from w w w . jav a 2s .co m zoomRatioY[index++] = Double.parseDouble(s); } } }
From source file:org.openbaton.nfvo.cli.OpenbatonCLI.java
private void changeLog(String line) { StringTokenizer stringTokenizer = new StringTokenizer(line, " "); if (stringTokenizer.countTokens() == 3) { stringTokenizer.nextToken();/*from w w w .j a v a 2 s.c om*/ ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(stringTokenizer.nextToken())) .setLevel(Level.toLevel(stringTokenizer.nextToken())); } else if (stringTokenizer.countTokens() == 2) { stringTokenizer.nextToken(); ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.openbaton")) .setLevel(Level.toLevel(stringTokenizer.nextToken())); } else { System.out.println("usage: changeLog [<package>] <level>"); System.out.println("where <package> default is: org.openbaton"); System.out.println("where <level> is:"); System.out.println("\t * INFO"); System.out.println("\t * DEBUG"); System.out.println("\t * TRACE"); } }
From source file:ObservableProperties.java
/** * Get this property as a String array. By convention, properties that are get * as string arrays should be encoded as a <strong>|</strong> separated list * of Strings./* w ww. jav a2s .c o m*/ * * @param name * The property's name. * @param def * The default value (if undefined). * @return A String array, or <strong>null</strong> if the property is * undefined. */ public String[] getStringArray(String name, String def[]) { String v = getProperty(name, null); if (v == null) return def; // Parse the property value: StringTokenizer st = new StringTokenizer(v, "|"); int len = st.countTokens(); String ret[] = new String[len]; for (int i = 0; i < ret.length; i++) { ret[i] = st.nextToken(); } return ret; }
From source file:edu.umass.cs.msocket.proxy.console.commands.StartWatchdog.java
@Override public void parse(String commandText) throws Exception { if (module.getProxyGroupGuid() == null) { console.printString("You have to connect to a proxy group first.\n"); return;//from w ww . j av a2s.c om } // Check if we already have a watchdog with that name running try { StringTokenizer st = new StringTokenizer(commandText); if (st.countTokens() != 5) { console.printString("Bad number of arguments (expected 5 instead of " + st.countTokens() + ")\n"); return; } String targetList = st.nextToken(); String watchdogName = st.nextToken(); long lookupIntervalInMs = Long.parseLong(st.nextToken()); long suspiciousTimeoutInMs = Long.parseLong(st.nextToken()); long failureTimeoutInMs = Long.parseLong(st.nextToken()); if (!"proxy".equalsIgnoreCase(targetList) && !"location".equalsIgnoreCase(targetList) && !"watchdog".equalsIgnoreCase(targetList) && !"all".equalsIgnoreCase(targetList)) { console.printString( "Invalid list '" + targetList + "'. You must pick one of proxy, location, watchdog or all"); return; } if (suspiciousTimeoutInMs <= 0 || failureTimeoutInMs <= 0 || failureTimeoutInMs < suspiciousTimeoutInMs) { console.printString( "Timeouts must have positive values and failure timeout must be greater than suspicious timeout."); return; } if (lookupIntervalInMs <= 0) { console.printString("Lookup interval must be a positive number."); return; } if (!module.isSilent()) console.printString("Looking for watchdog " + watchdogName + " GUID and certificates...\n"); GuidEntry myGuid = KeyPairUtils.getGuidEntryFromPreferences( module.getGnsClient().getGnsHost() + ":" + module.getGnsClient().getGnsPort(), watchdogName); final UniversalGnsClient gnsClient = module.getGnsClient(); if (myGuid == null) { if (!module.isSilent()) console.printString( "No keys found for watchdog " + watchdogName + ". Generating new GUID and keys\n"); myGuid = gnsClient.guidCreate(module.getAccountGuid(), watchdogName); } if (myGuid == null) { console.printString( "No keys found for watchdog " + watchdogName + ". Cannot connect without the key\n"); return; } if (!module.isSilent()) console.printString("Watchdog has guid " + myGuid.getGuid()); // Make sure we advertise ourselves as a watchdog (readable for everyone) gnsClient.fieldReplaceOrCreate(myGuid.getGuid(), GnsConstants.SERVICE_TYPE_FIELD, new JSONArray().put(GnsConstants.WATCHDOG_SERVICE), myGuid); gnsClient.aclAdd(AccessType.READ_WHITELIST, myGuid, GnsConstants.SERVICE_TYPE_FIELD, null); // Check if we are a member of the group final String groupGuid = module.getProxyGroupGuid().getGuid(); JSONArray members = gnsClient.groupGetMembers(groupGuid, myGuid); boolean isVerified = false; for (int i = 0; i < members.length(); i++) { if (myGuid.getGuid().equals(members.get(i))) { isVerified = true; break; } } if (!isVerified) { console.printString( "This watchdog has not been verified yet, it will stay in the unverified list until it gets added to the proxy group"); } // And now start 3 watchdogs: 1 for proxies, 1 for location services and 1 // for other watchdogs if ("proxy".equalsIgnoreCase(targetList) || "all".equalsIgnoreCase(targetList)) { Watchdog proxyWatchdog = new Watchdog(gnsClient, myGuid, groupGuid, lookupIntervalInMs, GnsConstants.ACTIVE_PROXY_FIELD, GnsConstants.SUSPICIOUS_PROXY_FIELD, GnsConstants.INACTIVE_PROXY_FIELD, suspiciousTimeoutInMs, failureTimeoutInMs); module.setRunningProxyWatchdog(proxyWatchdog); proxyWatchdog.start(); } if ("location".equalsIgnoreCase(targetList) || "all".equalsIgnoreCase(targetList)) { Watchdog locationWatchdog = new Watchdog(gnsClient, myGuid, groupGuid, lookupIntervalInMs, GnsConstants.ACTIVE_LOCATION_FIELD, GnsConstants.SUSPICIOUS_LOCATION_FIELD, GnsConstants.INACTIVE_LOCATION_FIELD, suspiciousTimeoutInMs, failureTimeoutInMs); module.setRunningLocationWatchdog(locationWatchdog); locationWatchdog.start(); } if ("watchdog".equalsIgnoreCase(targetList) || "all".equalsIgnoreCase(targetList)) { Watchdog watchdogWatchdog = new Watchdog(gnsClient, myGuid, groupGuid, lookupIntervalInMs, GnsConstants.ACTIVE_WATCHDOG_FIELD, GnsConstants.SUSPICIOUS_WATCHDOG_FIELD, GnsConstants.INACTIVE_WATCHDOG_FIELD, suspiciousTimeoutInMs, failureTimeoutInMs); module.setRunningWatchdogWatchdog(watchdogWatchdog); watchdogWatchdog.start(); } } catch (Exception e) { console.printString("Failed to coonect to start watchdog service ( " + e + ")\n"); } }