List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:blue.noteProcessor.TempoMapper.java
public static TempoMapper createTempoMapper(String timeWarpString) { TempoMapper tm = new TempoMapper(); StringTokenizer st = new StringTokenizer(timeWarpString); String time, tempo;/* w w w . j a v a 2 s.c o m*/ BeatTempoPair temp; if (st.countTokens() % 2 != 0) { // not an even amount of tokens! return null; } tm.timeMap = new BeatTempoPair[st.countTokens() / 2]; int index = 0; BeatTempoPair[] tMap = tm.timeMap; while (st.hasMoreTokens()) { try { time = st.nextToken(); tempo = st.nextToken(); temp = new BeatTempoPair(); temp.beat = Float.parseFloat(time); temp.tempo = Float.parseFloat(tempo); if (temp.beat < 0.0f || temp.tempo <= 0.0f) { return null; } tMap[index] = temp; if (index > 0) { float factor1 = 60.0f / tMap[index - 1].tempo; float factor2 = 60.0f / tMap[index].tempo; float deltaBeat = tMap[index].beat - tMap[index - 1].beat; float acceleration = 0.0f; if (deltaBeat >= 0.0f) { acceleration = (factor2 - factor1) / (tMap[index].beat - tMap[index - 1].beat); } if (tMap[index].beat == tMap[index - 1].beat) { tMap[index].accumulatedTime = tMap[index - 1].accumulatedTime; } else { tMap[index].accumulatedTime = tMap[index - 1].accumulatedTime + getAreaUnderCurve(factor1, deltaBeat, acceleration); } } index++; } catch (Exception e) { // if there's any errors whatsoever, return null // and let the calling procedure handle it return null; } } return tm; }
From source file:Main.java
/** * Given an {@link NNTPClient} instance, and an integer range of messages, return * an array of {@link Article} instances. * @param client //w ww . ja v a 2s. c o m * @param lowArticleNumber * @param highArticleNumber * @return Article[] An array of Article * @throws IOException */ public static Article[] getArticleInfo(NNTPClient client, int lowArticleNumber, int highArticleNumber) throws IOException { Reader reader = null; Article[] articles = null; reader = (DotTerminatedMessageReader) client.retrieveArticleInfo(lowArticleNumber, highArticleNumber); if (reader != null) { String theInfo = readerToString(reader); StringTokenizer st = new StringTokenizer(theInfo, "\n"); // Extract the article information // Mandatory format (from NNTP RFC 2980) is : // Subject\tAuthor\tDate\tID\tReference(s)\tByte Count\tLine Count int count = st.countTokens(); articles = new Article[count]; int index = 0; while (st.hasMoreTokens()) { StringTokenizer stt = new StringTokenizer(st.nextToken(), "\t"); Article article = new Article(); article.setArticleNumber(Integer.parseInt(stt.nextToken())); article.setSubject(stt.nextToken()); article.setFrom(stt.nextToken()); article.setDate(stt.nextToken()); article.setArticleId(stt.nextToken()); article.addHeaderField("References", stt.nextToken()); articles[index++] = article; } } else { return null; } return articles; }
From source file:XMLUtils.java
public static QName getNamespace(Map<String, String> namespaces, String str, String defaultNamespace) { String prefix = null;//w ww . java 2s . c o m String localName = null; StringTokenizer tokenizer = new StringTokenizer(str, ":"); if (tokenizer.countTokens() == 2) { prefix = tokenizer.nextToken(); localName = tokenizer.nextToken(); } else if (tokenizer.countTokens() == 1) { localName = tokenizer.nextToken(); } String namespceURI = defaultNamespace; if (prefix != null) { namespceURI = (String) namespaces.get(prefix); } return new QName(namespceURI, localName); }
From source file:org.apache.axis2.jaxws.util.WSToolingUtils.java
/** * Answer if the input version number is 2.1.6 or later. Version 2.1.6 is the Sun RI version that changed * the WebMethod annotation semantics./*from w w w .j ava 2 s . co m*/ * * @param wsGenVersion A version number separated by "." Up to the first 3 values will be checked. * @return true if the version number is 2.1.6 or later, false otherwise. */ public static boolean isValidVersion(String wsGenVersion) { if (log.isDebugEnabled()) { log.debug("Start isValidVersion(String)"); } if (log.isDebugEnabled()) { log.debug("isValidVersion: Determining if WsGen version: " + wsGenVersion + " is appropriate version for using new SUN RI behavior"); } if (wsGenVersion == null) { return false; } /* * This algorithm is improvement over the old algorithm we had to validate the * version. In this algorithm we don't assume that the format will be x.x.x. * This algorithm looks for versionNumbers in a String token delimited by a * ".", the idea is to look for the first digit in each token and compare that * with the version validation requirements. * we return false if version is less that 2.1.6. * possible input version strings could be "JAX-WS RI 2.2-b05-", "2.1.6" "2.1.0" etc. */ // Minimum version required is 2.1.6 final int minimumVersionRequired[] = { 2, 1, 6 }; String version = wsGenVersion.trim(); StringTokenizer st = new StringTokenizer(version, "."); if (st.countTokens() <= 0) { if (log.isDebugEnabled()) { log.debug("No Tokens to validate the tooling version, Input version String is invalid."); } return false; } // Check up to as many version values as we have values in the minimum required version boolean lastCheckEqual = false; int tokenCnt = 0; for (; tokenCnt < minimumVersionRequired.length && st.hasMoreTokens(); tokenCnt++) { String token = st.nextToken(); if (token == null) { return false; } int versionNumber = getIntegerValue(token); int minimumVersionNumber = minimumVersionRequired[tokenCnt]; if (versionNumber < minimumVersionNumber) { // The version number is too low, so it is invalid if (log.isDebugEnabled()) { log.debug("Validation failed on tokenCnt = " + tokenCnt); log.debug("Input VersionNumber =" + versionNumber); log.debug("Minimum Version Number required = " + minimumVersionNumber); } return false; } else if (versionNumber > minimumVersionNumber) { // The version number is higher than required, so it passes validation. if (log.isDebugEnabled()) { log.debug("Validation passed on tokenCnt = " + tokenCnt); log.debug("Input VersionNumber = " + versionNumber); log.debug("Minimum Version Number required = " + minimumVersionNumber); } return true; } else { // The version number sub-value matches exactly, so we need to check the next sub-value.s if (log.isDebugEnabled()) { log.debug("Validation unresolved on tokenCnt = " + tokenCnt); log.debug("Input VersionNumber = " + versionNumber); log.debug("Minimum Version Number required = " + minimumVersionNumber); } lastCheckEqual = true; continue; } } if (log.isDebugEnabled()) { log.debug("Exit isValidVersion(String)"); } // If the version numbers we checked so far were equal to the minimum version BUT it was shorter // in length, then return false. For example if the input is "2.1", that is actually "2.1.0" // which would be less than "2.1.6". if (lastCheckEqual && tokenCnt < minimumVersionRequired.length) { return false; } return true; }
From source file:com.emc.plants.utils.Util.java
/** * Method readTokens.//w w w. ja v a 2 s.c om * @param text * @param token * @return list */ public static String[] readTokens(String text, String token) { StringTokenizer parser = new StringTokenizer(text, token); int numTokens = parser.countTokens(); String[] list = new String[numTokens]; for (int i = 0; i < numTokens; i++) { list[i] = parser.nextToken(); } return list; }
From source file:io.github.bonigarcia.wdm.Downloader.java
public static Proxy createProxy() { String proxyString = System.getenv("HTTPS_PROXY"); if (proxyString == null || proxyString.length() < 1) proxyString = System.getenv("HTTP_PROXY"); if (proxyString == null || proxyString.length() < 1) { return null; }/*from w w w . j av a 2 s . c o m*/ proxyString = proxyString.replace("http://", ""); proxyString = proxyString.replace("https://", ""); StringTokenizer st = new StringTokenizer(proxyString, ":"); if (st.countTokens() != 2) return null; String host = st.nextToken(); String portString = st.nextToken(); try { int port = Integer.parseInt(portString); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); } catch (NumberFormatException e) { return null; } }
From source file:I18NUtil.java
/** * Factory method to create a Locale from a <tt>lang_country_variant</tt> string. * //ww w . j a v a2 s. c o m * @param localeStr e.g. fr_FR * @return Returns the locale instance, or the {@link Locale#getDefault() default} if the * string is invalid */ public static Locale parseLocale(String localeStr) { if (localeStr == null) { return null; } Locale locale = Locale.getDefault(); StringTokenizer t = new StringTokenizer(localeStr, "_"); int tokens = t.countTokens(); if (tokens == 1) { locale = new Locale(t.nextToken()); } else if (tokens == 2) { locale = new Locale(t.nextToken(), t.nextToken()); } else if (tokens == 3) { locale = new Locale(t.nextToken(), t.nextToken(), t.nextToken()); } return locale; }
From source file:de.kapsi.net.daap.DaapUtil.java
/** * Splits a meta String ("foo,bar,alice,bob") and stores the data * in an ArrayList/*www .ja v a 2 s .co m*/ * * @param meta a meta String * @return the splitten meta String as ArrayList */ public static final ArrayList parseMeta(String meta) { StringTokenizer tok = new StringTokenizer(meta, ","); ArrayList list = new ArrayList(tok.countTokens()); boolean flag = false; while (tok.hasMoreTokens()) { String token = tok.nextToken(); // Must be te fist! See DAAP documentation // for more info! if (!flag && token.equals("dmap.itemkind")) { list.add(0, token); flag = true; } else { list.add(token); } } return list; }
From source file:com.izforge.izpack.util.IoHelper.java
/** * Extracts a long value from a string in a special manner. The string will be broken into * tokens with a standard StringTokenizer. Around the assumed place (with the given half range) * the tokens are scanned reverse for a token which represents a long. if useNotIdentifier is not * null, tokens which are contains this string will be ignored. The first founded long returns. * * @param in the string which should be parsed * @param assumedPlace token number which should contain the value * @return founded long//from w w w. java2 s . c o m */ private static long extractLong(String in, int assumedPlace) { long ret = -1; StringTokenizer st = new StringTokenizer(in); int length = st.countTokens(); int i; int currentRange = 0; String[] interestedEntries = new String[3 + 3]; for (i = 0; i < length - 3 + assumedPlace; ++i) { st.nextToken(); // Forget this entries. } for (i = 0; i < 3 + 3; ++i) { // Put the interesting Strings into an intermediate array. if (st.hasMoreTokens()) { interestedEntries[i] = st.nextToken(); currentRange++; } } for (i = currentRange - 1; i >= 0; --i) { if (interestedEntries[i].contains("%")) { continue; } try { ret = Long.parseLong(interestedEntries[i]); } catch (NumberFormatException nfe) { continue; } break; } return ret; }
From source file:net.sf.jasperreports.charts.util.ChartUtil.java
private static int[] getCoordinates(ChartEntity entity) { int[] coordinates = null; String shapeCoords = entity.getShapeCoords(); if (shapeCoords != null && shapeCoords.length() > 0) { StringTokenizer tokens = new StringTokenizer(shapeCoords, ","); coordinates = new int[tokens.countTokens()]; int idx = 0; while (tokens.hasMoreTokens()) { String coord = tokens.nextToken(); coordinates[idx] = Integer.parseInt(coord); ++idx;/*from ww w. ja v a 2 s . co m*/ } } return coordinates; }