List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:cn.com.sunjiesh.xcutils.common.VersionUtil.java
/** * /*w w w . j a v a 2 s. c om*/ * @param version1 * @param version2 * @return */ public static int compareVersion(String version1, String version2) { StringTokenizer version1Tokenizer = new StringTokenizer(version1, "."); StringTokenizer version2Tokenizer = new StringTokenizer(version2, "."); if (version1.equals(version2)) { return 0; } else { while (version1Tokenizer.hasMoreTokens() && version2Tokenizer.hasMoreTokens()) { String version1Token = version1Tokenizer.nextToken(); String Version2Token = version2Tokenizer.nextToken(); if (StringUtils.isNotBlank(version1Token)) { version1Token = version1Token.replace("-", ""); } if (StringUtils.isNotBlank(Version2Token)) { Version2Token = Version2Token.replace("-", ""); } if (StringUtils.isNotBlank(version1Token)) { version1Token = version1Token.replace("0", ""); if (version1Token.equals("")) { version1Token = "0"; } } if (StringUtils.isNotBlank(Version2Token)) { Version2Token = Version2Token.replace("0", ""); if (Version2Token.equals("")) { Version2Token = "0"; } } if (NumberUtils.isDigits(version1Token) && NumberUtils.isDigits(Version2Token)) {//??? if (Integer.parseInt(version1Token) < Integer.parseInt(Version2Token)) { return -1; } if (Integer.parseInt(version1Token) > Integer.parseInt(Version2Token)) { return 1; } } } } return 0; }
From source file:com.salesmanager.core.util.MerchantConfigurationUtil.java
public static IntegrationProperties getIntegrationProperties(String configurationValue, String delimiter) { if (configurationValue == null) return new IntegrationProperties(); StringTokenizer st = new StringTokenizer(configurationValue, delimiter); int i = 1;/*from w ww. j a v a 2 s . c om*/ IntegrationProperties keys = new IntegrationProperties(); while (st.hasMoreTokens()) { String value = st.nextToken(); if (i == 1) { keys.setProperties1(value); } else if (i == 2) { keys.setProperties2(value); } else if (i == 3) { keys.setProperties3(value); } else if (i == 4) { keys.setProperties4(value); } else { keys.setProperties5(value); } i++; } return keys; }
From source file:com.fiveamsolutions.nci.commons.web.struts2.validator.HibernateValidator.java
private static Set<String> parseList(String list) { if (StringUtils.isBlank(list)) { return null; }/* w w w .j a v a2 s.c o m*/ HashSet<String> names = new HashSet<String>(); StringTokenizer st = new StringTokenizer(list, ","); while (st.hasMoreTokens()) { String n = st.nextToken().trim(); if (StringUtils.isNotBlank(n)) { names.add(n); } } return !names.isEmpty() ? names : null; }
From source file:com.validation.manager.core.tool.Tool.java
public static TCEExtraction extractTCE(Object key) { TestCaseExecutionServer tce = null;/* w ww . j av a 2 s . c o m*/ TestCaseServer tcs = null; if (key instanceof String) { String item = (String) key; StringTokenizer st = new StringTokenizer(item, "-"); st.nextToken();//Ignore the tce part String tceIdS = st.nextToken(); try { int tceId = Integer.parseInt(tceIdS); LOG.log(Level.FINE, "{0}", tceId); tce = new TestCaseExecutionServer(tceId); } catch (NumberFormatException nfe) { LOG.log(Level.WARNING, "Unable to find TCE: " + tceIdS, nfe); } try { int tcId = Integer.parseInt(st.nextToken()); int tcTypeId = Integer.parseInt(st.nextToken()); LOG.log(Level.FINE, "{0}", tcId); tcs = new TestCaseServer(new TestCasePK(tcId, tcTypeId)); } catch (NumberFormatException nfe) { LOG.log(Level.WARNING, "Unable to find TCE: " + tceIdS, nfe); } } else if (key instanceof TestCaseExecution) { //It is a TestCaseExecution tce = new TestCaseExecutionServer((TestCaseExecution) key); } else { LOG.log(Level.SEVERE, "Unexpected key: {0}", key); tce = null; } return new TCEExtraction(tce, tcs); }
From source file:TextUtilities.java
/** * Returns an array of the tokens produced by the specified string with the * specified delimiter characters.//from w ww .j a va2s .c o m */ public static String[] getTokens(String text, String delimiters) { StringTokenizer tokenizer = new StringTokenizer(text, delimiters); String[] tokens = new String[tokenizer.countTokens()]; for (int i = 0; i < tokens.length; i++) tokens[i] = tokenizer.nextToken(); return tokens; }
From source file:com.intel.chimera.codec.OpensslCipher.java
private static Transform tokenizeTransformation(String transformation) throws NoSuchAlgorithmException { if (transformation == null) { throw new NoSuchAlgorithmException("No transformation given."); }/* www . j a v a 2 s. c o m*/ /* * Array containing the components of a Cipher transformation: * * index 0: algorithm (e.g., AES) * index 1: mode (e.g., CTR) * index 2: padding (e.g., NoPadding) */ String[] parts = new String[3]; int count = 0; StringTokenizer parser = new StringTokenizer(transformation, "/"); while (parser.hasMoreTokens() && count < 3) { parts[count++] = parser.nextToken().trim(); } if (count != 3 || parser.hasMoreTokens()) { throw new NoSuchAlgorithmException("Invalid transformation format: " + transformation); } return new Transform(parts[0], parts[1], parts[2]); }
From source file:com.salesmanager.core.util.MerchantConfigurationUtil.java
public static IntegrationKeys getIntegrationKeys(String configvalue, String delimiter) throws Exception { if (configvalue == null) return new IntegrationKeys(); StringTokenizer st = new StringTokenizer(configvalue, delimiter); int i = 1;/*from w w w . java2 s . c o m*/ int j = 1; IntegrationKeys keys = new IntegrationKeys(); while (st.hasMoreTokens()) { String value = st.nextToken(); if (i == 1) { // decrypt keys.setUserid(value); } else if (i == 2) { // decrypt keys.setPassword(value); } else if (i == 3) { // decrypt keys.setTransactionKey(value); } else { if (j == 1) { keys.setKey1(value); } else if (j == 2) { keys.setKey2(value); } else if (j == 3) { keys.setKey3(value); } j++; } i++; } return keys; }
From source file:LocaleMap.java
public static Locale parseLocale(String localeString) { StringTokenizer localeParser = new StringTokenizer(localeString, "-_"); String lang = null, country = null, variant = null; if (localeParser.hasMoreTokens()) lang = localeParser.nextToken(); if (localeParser.hasMoreTokens()) country = localeParser.nextToken(); if (localeParser.hasMoreTokens()) variant = localeParser.nextToken(); if (lang != null && country != null && variant != null) return new Locale(lang, country, variant); else if (lang != null && country != null) return new Locale(lang, country); else if (lang != null) return new Locale(lang); else//w ww . j a v a2 s .c o m return new Locale(""); }
From source file:cn.com.qiqi.order.utils.Servlets.java
/** * ?? If-None-Match Header, Etag?./* ww w . java 2 s. c om*/ * * Etag, checkIfNoneMatchfalse, 304 not modify status. * * @param etag ETag. */ public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) { String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH); if (headerValue != null) { boolean conditionSatisfied = false; if (!"*".equals(headerValue)) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader(HttpHeaders.ETAG, etag); return false; } } return true; }
From source file:com.cburch.logisim.util.LocaleManager.java
private static HashMap<Character, String> fetchReplaceAccents() { HashMap<Character, String> ret = null; String val; try {/*from www . j av a 2s.co m*/ val = LocaleString.getUtilLocaleManager().locale.getString("accentReplacements"); } catch (MissingResourceException e) { return null; } StringTokenizer toks = new StringTokenizer(val, "/"); while (toks.hasMoreTokens()) { String tok = toks.nextToken().trim(); char c = '\0'; String s = null; if (tok.length() == 1) { c = tok.charAt(0); s = ""; } else if (tok.length() >= 2 && tok.charAt(1) == ' ') { c = tok.charAt(0); s = tok.substring(2).trim(); } if (s != null) { if (ret == null) ret = new HashMap<Character, String>(); ret.put(new Character(c), s); } } return ret; }