List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheetModel.java
public static String[] convertActions(String actionList) { if (actionList == null) return null; StringTokenizer st = new StringTokenizer(actionList, ",;:|"); String[] actions = new String[st.countTokens()]; for (int i = 0; i < actions.length; i++) actions[i] = st.nextToken();//from w w w.jav a2 s. c om return actions; }
From source file:de.kapsi.net.daap.DaapUtil.java
/** * This method tries the determinate the protocol version * and returns it or {@see #NULL} if version could not be * estimated.../*from ww w . j a v a 2 s .c o m*/ */ public static int getProtocolVersion(DaapRequest request) { if (request.isUnknownRequest()) return DaapUtil.NULL; Header header = request.getHeader(CLIENT_DAAP_VERSION); if (header == null && request.isSongRequest()) { header = request.getHeader(USER_AGENT); } if (header == null) return DaapUtil.NULL; String name = header.getName(); String value = header.getValue(); // Unfortunately song requests do not have a Client-DAAP-Version // header. As a workaround we can estimate the protocol version // by User-Agent but that is weak an may break with non iTunes // hosts... if (request.isSongRequest() && name.equals(USER_AGENT)) { // Note: the protocol version of a Song request is estimated // by the server with the aid of the sessionId, i.e. this block // is actually never touched... if (value.startsWith("iTunes/4.5") || value.startsWith("iTunes/4.6")) return DaapUtil.VERSION_3; else if (value.startsWith("iTunes/4.2") || value.startsWith("iTunes/4.1")) return DaapUtil.VERSION_2; else if (value.startsWith("iTunes/4.0")) return DaapUtil.VERSION_1; else return DaapUtil.NULL; } else { StringTokenizer tokenizer = new StringTokenizer(value, "."); int count = tokenizer.countTokens(); if (count >= 2 && count <= 3) { try { int major = DaapUtil.NULL; int minor = DaapUtil.NULL; int patch = DaapUtil.NULL; major = Integer.parseInt(tokenizer.nextToken()); minor = Integer.parseInt(tokenizer.nextToken()); if (count == 3) patch = Integer.parseInt(tokenizer.nextToken()); return DaapUtil.toVersion(major, minor, patch); } catch (NumberFormatException err) { } } } return DaapUtil.NULL; }
From source file:gmgen.plugin.PlayerCharacterOutput.java
private static String getWeaponType(Equipment eq, boolean primary) { StringBuilder sb = new StringBuilder(); StringTokenizer aTok = new StringTokenizer(SettingsHandler.getGame().getWeaponTypes(), "|", false); while (aTok.countTokens() >= 2) { final String aType = aTok.nextToken(); final String abbrev = aTok.nextToken(); if (eq.isType(aType, true)) { sb.append(abbrev);/*from ww w. j a v a 2s . c o m*/ } } return sb.toString(); }
From source file:com.stratelia.webactiv.util.FileRepositoryManager.java
/** * to create the array of the string this array represents the repertories where the files must be * stored./* w w w . ja v a 2 s. c o m*/ * * @param str : type String: the string of repertories * @return */ public static String[] getAttachmentContext(String str) { String strAt = "Attachment " + CONTEXT_TOKEN; if (str != null) { strAt = strAt.concat(str); } StringTokenizer strToken = new StringTokenizer(strAt, CONTEXT_TOKEN); // number of elements int nElt = strToken.countTokens(); // to init array String[] context = new String[nElt]; int k = 0; while (strToken.hasMoreElements()) { context[k] = ((String) strToken.nextElement()).trim(); k++; } return context; }
From source file:hudson.plugins.testlink.util.TestLinkHelper.java
/** * Maybe adds a system property if it is in format <key>=<value>. * //from w ww . jav a 2s .co m * @param systemProperty System property entry in format <key>=<value>. * @param listener Jenkins Build listener */ public static void maybeAddSystemProperty(String systemProperty, BuildListener listener) { final StringTokenizer tokenizer = new StringTokenizer(systemProperty, "=:"); if (tokenizer.countTokens() == 2) { final String key = tokenizer.nextToken(); final String value = tokenizer.nextToken(); if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(value)) { if (key.contains(BASIC_HTTP_PASSWORD)) { listener.getLogger().println(Messages.TestLinkBuilder_SettingSystemProperty(key, "********")); } else { listener.getLogger().println(Messages.TestLinkBuilder_SettingSystemProperty(key, value)); } try { System.setProperty(key, value); } catch (SecurityException se) { se.printStackTrace(listener.getLogger()); } } } }
From source file:StringUtil.java
/** * Splits the provided text into a list, based on a given separator. * The separator is not included in the returned String array. * The maximum number of splits to perfom can be controlled. * A null separator will cause parsing to be on whitespace. * * <p>This is useful for quickly splitting a string directly into * an array of tokens, instead of an enumeration of tokens (as * <code>StringTokenizer</code> does). * * @param str The string to parse./*from w w w. j a v a2 s. c o m*/ * @param separator Characters used as the delimiters. If * <code>null</code>, splits on whitespace. * @param max The maximum number of elements to include in the * list. A zero or negative value implies no limit. * @return an array of parsed Strings */ public static String[] split(String str, String separator, int max) { StringTokenizer tok = null; if (separator == null) { // Null separator means we're using StringTokenizer's default // delimiter, which comprises all whitespace characters. tok = new StringTokenizer(str); } else { tok = new StringTokenizer(str, separator); } int listSize = tok.countTokens(); if (max > 0 && listSize > max) { listSize = max; } String[] list = new String[listSize]; int i = 0; int lastTokenBegin = 0; int lastTokenEnd = 0; while (tok.hasMoreTokens()) { if (max > 0 && i == listSize - 1) { // In the situation where we hit the max yet have // tokens left over in our input, the last list // element gets all remaining text. String endToken = tok.nextToken(); lastTokenBegin = str.indexOf(endToken, lastTokenEnd); list[i] = str.substring(lastTokenBegin); break; } else { list[i] = tok.nextToken(); lastTokenBegin = str.indexOf(list[i], lastTokenEnd); lastTokenEnd = lastTokenBegin + list[i].length(); } i++; } return list; }
From source file:hudson.plugins.testlink.util.TestLinkHelper.java
/** * <p>Defines TestLink Java API Properties. Following is the list of available * properties.</p>/* w w w.j ava 2 s . c o m*/ * * <ul> * <li>xmlrpc.basicEncoding</li> * <li>xmlrpc.basicPassword</li> * <li>xmlrpc.basicUsername</li> * <li>xmlrpc.connectionTimeout</li> * <li>xmlrpc.contentLengthOptional</li> * <li>xmlrpc.enabledForExceptions</li> * <li>xmlrpc.encoding</li> * <li>xmlrpc.gzipCompression</li> * <li>xmlrpc.gzipRequesting</li> * <li>xmlrpc.replyTimeout</li> * <li>xmlrpc.userAgent</li> * </ul> * * @param testLinkJavaAPIProperties * @param listener Jenkins Build listener */ public static void setTestLinkJavaAPIProperties(String testLinkJavaAPIProperties, BuildListener listener) { if (StringUtils.isNotBlank(testLinkJavaAPIProperties)) { final StringTokenizer tokenizer = new StringTokenizer(testLinkJavaAPIProperties, ","); if (tokenizer.countTokens() > 0) { while (tokenizer.hasMoreTokens()) { String systemProperty = tokenizer.nextToken(); maybeAddSystemProperty(systemProperty, listener); } } } }
From source file:hudson.plugins.testlink.util.TestLinkHelper.java
/** * <p>Formats a custom field into an environment variable. It appends * TESTLINK_TESTCASE in front of the environment variable name.</p> * //from www . j a v a 2s .co m * <p>So, for example, the custom field which name is Sample Custom Field and * value is <b>Sample Value</b>, will be added into the environment variables * as TESTLINK_TESTCASE_SAMPLE__CUSTOM_FIELD="Sample Value" (note for the double spaces).</p> * * <p>If the custom's value contains commas (,), then this method splits the * value and, for each token found, it creates a new environment variable * appending a numeric index after its name</p> * * <p>So, for example, the custom field which name is Sample Custom Field and * value is <b>Sample Value 1, Sample Value 2</b>, will generate three * environment variables: TESTLINK_TESTCASE_SAMPLE_CUSTOM_FIELD="Sample Value 1, Sample Value 2", * TESTLINK_TESTCASE_SAMPLE_CUSTOM_FIELD_0="Sample Value 1" and * TESTLINK_TESTCASE_SAMPLE_CUSTOM_FIELD_1="Sample Value 2".</p> * * @param customField The custom field * @param testLinkEnvVar TestLink envVars */ public static void addCustomFieldEnvironmentVariableName(CustomField customField, Map<String, String> testLinkEnvVar) { String customFieldName = customField.getName(); String customFieldValue = customField.getValue(); customFieldName = customFieldName.toUpperCase(); // uppercase customFieldName = customFieldName.trim(); // trim customFieldName = TESTLINK_TESTCASE_PREFIX + customFieldName; // add prefix customFieldName = customFieldName.replaceAll("\\s+", "_"); // replace white spaces testLinkEnvVar.put(customFieldName, customFieldValue); if (StringUtils.isNotBlank(customFieldValue)) { StringTokenizer tokenizer = new StringTokenizer(customFieldValue, ","); if (tokenizer.countTokens() > 1) { int index = 0; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); token = token.trim(); customFieldName = customField.getName(); customFieldName = customFieldName.toUpperCase(); // uppercase customFieldName = customFieldName.trim(); // trim String tokenName = TESTLINK_TESTCASE_PREFIX + customFieldName + "_" + index; // add prefix tokenName = tokenName.replaceAll("\\s+", "_"); // replace white spaces testLinkEnvVar.put(tokenName, token); ++index; } } } }
From source file:jenkins.plugins.testopia.TestopiaBuilder.java
/** * <p>Define properties. Following is the list of available properties.</p> * // w w w.j a v a 2s .co m * <ul> * <li>xmlrpc.basicEncoding</li> * <li>xmlrpc.basicPassword</li> * <li>xmlrpc.basicUsername</li> * <li>xmlrpc.connectionTimeout</li> * <li>xmlrpc.contentLengthOptional</li> * <li>xmlrpc.enabledForExceptions</li> * <li>xmlrpc.encoding</li> * <li>xmlrpc.gzipCompression</li> * <li>xmlrpc.gzipRequesting</li> * <li>xmlrpc.replyTimeout</li> * <li>xmlrpc.userAgent</li> * </ul> * * @param properties List of comma separated properties * @param listener Jenkins Build listener */ public static void setProperties(String properties, BuildListener listener) { if (StringUtils.isNotBlank(properties)) { final StringTokenizer tokenizer = new StringTokenizer(properties, ","); if (tokenizer.countTokens() > 0) { while (tokenizer.hasMoreTokens()) { String systemProperty = tokenizer.nextToken(); maybeAddSystemProperty(systemProperty, listener); } } } }
From source file:com.kcs.core.utilities.Utility.java
public static String[] split(String value, String delim) { if (value == null) { return new String[0]; }//from w ww. j a v a 2 s . c o m if (value.trim().equals("")) { return new String[0]; } String[] ret = null; if (value.indexOf(delim) == -1) { ret = new String[1]; ret[0] = value; } else { StringTokenizer stoken = new StringTokenizer(value, delim); ret = new String[stoken.countTokens()]; int i = 0; while (stoken.hasMoreTokens()) { ret[i] = stoken.nextToken(); i++; } } return ret; }