List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:cat.albirar.framework.sets.SetUtils.java
/** * Check if path is correct for the indicated model. * @param model The model//from w w w .jav a 2 s .c o m * @param propertyPath The property path, required * @return true if correct and false if not * @throws IllegalArgumentException If model is null or if the property path is null or empty or only whitespace or not correct format */ public static boolean checkPathForModel(Class<?> model, String propertyPath) { StringTokenizer stk; ModelDescriptor pathFollower; PropertyDescriptor pdesc; String ppath; Assert.hasText(propertyPath, "The property path is required and cannot be empty or only whitespace"); // Check pattern if (!pathPattern.matcher(propertyPath).matches()) { throw new IllegalArgumentException(String.format("The property path '%s' is incorrect!", propertyPath)); } stk = new StringTokenizer(propertyPath, "."); pathFollower = new ModelDescriptor(model); while (stk.hasMoreTokens()) { ppath = stk.nextToken(); if ((pdesc = pathFollower.getProperties().get(ppath)) != null) { if (stk.hasMoreTokens()) { pathFollower = new ModelDescriptor(pdesc.getPropertyType()); } } else { // Error return false; } } return true; }
From source file:bioLockJ.AppController.java
/** * Populate args to pass to ProcessUtil. * @param command// w w w . ja v a 2s.co m * @param filePath * @return */ private static String[] getArgs(final String command, final String filePath) { final StringTokenizer sToken = new StringTokenizer(command + " " + filePath); final List<String> list = new ArrayList<>(); while (sToken.hasMoreTokens()) { list.add(sToken.nextToken()); } final String[] args = new String[list.size()]; for (int x = 0; x < list.size(); x++) { args[x] = list.get(x); } return args; }
From source file:fr.ign.cogit.geoxygene.datatools.ojb.GeOxygeneBrokerHelper.java
/** * splits up the name string and extract db url, user name and password and * build a new PBKey instance - the token '#' is used to separate the * substrings.//from w ww.j a va 2s . c o m * @throws PersistenceBrokerException if given name was <code>null</code> */ public static PBKey extractAllTokens(String name) { if (name == null) { throw new PersistenceBrokerException("Could not extract PBKey, given argument is 'null'"); //$NON-NLS-1$ } String user = null; String passwd = null; StringTokenizer tok = new StringTokenizer(name, GeOxygeneBrokerHelper.REPOSITORY_NAME_SEPARATOR); String dbName = tok.nextToken(); if (tok.hasMoreTokens()) { user = tok.nextToken(); if (user != null && user.trim().equals("")) { //$NON-NLS-1$ user = null; } } if (tok.hasMoreTokens()) { if (user != null) { passwd = tok.nextToken(); } } if (user != null && passwd == null) { passwd = ""; //$NON-NLS-1$ } PBKey key = new PBKey(dbName, user, passwd); return key; }
From source file:com.salesmanager.core.util.ShippingUtil.java
/** * Strip a map of configuration if built as <ID>|<SHIPPING * LABEL>;<ID>|<SHIPPING LABEL> * //from w w w .j a v a 2 s .co m * @param packageline * @return */ public static Map getConfigurationValuesMap(String packageline, String moduleid, Locale locale) { ResourceBundle bundle = ResourceBundle.getBundle(moduleid, locale); Map returnmap = new HashMap(); StringTokenizer st = new StringTokenizer(packageline, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); StringTokenizer stst = new StringTokenizer(token, "|"); int i = 0; String key = null; while (stst.hasMoreTokens()) { String ptoken = stst.nextToken(); if (i == 0) { key = ptoken; } // get value from bundle String value = bundle.getString("shipping.quote.services.label." + key); if (i == 1 && token.contains("|")) { returnmap.put(key, value); } else { returnmap.put(key, value); } i++; } } return returnmap; }
From source file:com.salesmanager.core.util.ShippingUtil.java
/** * Strip a map of configuration if built as <ID>|<VALUE>;<ID>|<VALUE> * //from w w w.j a v a 2 s. c o m * @param packageline * @return */ public static Map getConfigurationMap(String line, String mainDelimiter, String innerDelimiter) { Map returnmap = new HashMap(); if (StringUtils.isBlank(line)) { return returnmap; } StringTokenizer st = new StringTokenizer(line, mainDelimiter); while (st.hasMoreTokens()) { String token = st.nextToken(); StringTokenizer stst = new StringTokenizer(token, innerDelimiter); int i = 0; String key = null; while (stst.hasMoreTokens()) { String ptoken = stst.nextToken(); if (i == 0) { key = ptoken; } if (i == 1) { returnmap.put(key, ptoken); } i++; } } return returnmap; }
From source file:keel.Algorithms.Neural_Networks.NNEP_Clas.KEELWrapperClas.java
/** * <p>// w w w .ja v a2s. co m * Reads schema from the KEEL file * * @param jobFilename Name of the KEEL dataset file * </p> */ private static byte[] readSchema(String fileName) throws IOException, DatasetException { KeelDataSet dataset = new KeelDataSet(fileName); dataset.open(); File file = new File(fileName); List<String> inputIds = new ArrayList<String>(); List<String> outputIds = new ArrayList<String>(); Reader reader = new BufferedReader(new FileReader(file)); String line = ((BufferedReader) reader).readLine(); line = line.replace("real[", "real ["); line = line.replace("integer[", "integer ["); line = line.replace("{", " {"); StringTokenizer elementLine = new StringTokenizer(line); String element = elementLine.nextToken(); while (!element.equalsIgnoreCase("@data")) { if (element.equalsIgnoreCase("@inputs")) { while (elementLine.hasMoreTokens()) { StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ","); while (commaTokenizer.hasMoreTokens()) inputIds.add(commaTokenizer.nextToken()); } } else if (element.equalsIgnoreCase("@outputs")) { while (elementLine.hasMoreTokens()) { StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ","); while (commaTokenizer.hasMoreTokens()) outputIds.add(commaTokenizer.nextToken()); } } // Next line of the file line = ((BufferedReader) reader).readLine(); while (line.startsWith("%") || line.equalsIgnoreCase("")) line = ((BufferedReader) reader).readLine(); line = line.replace("real[", "real ["); line = line.replace("integer[", "integer ["); line = line.replace("{", " {"); elementLine = new StringTokenizer(line); element = elementLine.nextToken(); } IMetadata metadata = dataset.getMetadata(); byte[] schema = new byte[metadata.numberOfAttributes()]; if (inputIds.isEmpty() || outputIds.isEmpty()) { for (int i = 0; i < schema.length; i++) { if (i != (schema.length - 1)) schema[i] = 1; else { IAttribute outputAttribute = metadata.getAttribute(i); schema[i] = 2; consoleReporter.setOutputAttribute(outputAttribute); } } } else { for (int i = 0; i < schema.length; i++) { if (inputIds.contains(metadata.getAttribute(i).getName())) schema[i] = 1; else if (outputIds.contains(metadata.getAttribute(i).getName())) { IAttribute outputAttribute = metadata.getAttribute(i); schema[i] = 2; consoleReporter.setOutputAttribute(outputAttribute); } else schema[i] = -1; } } StringBuffer header = new StringBuffer(); header.append("@relation " + dataset.getName() + "\n"); for (int i = 0; i < metadata.numberOfAttributes(); i++) { IAttribute attribute = metadata.getAttribute(i); header.append("@attribute " + attribute.getName() + " "); if (attribute.getType() == AttributeType.Categorical) { CategoricalAttribute catAtt = (CategoricalAttribute) attribute; Interval interval = catAtt.intervalValues(); header.append("{"); for (int j = (int) interval.getLeft(); j <= interval.size() + 1; j++) { header.append(catAtt.show(j) + (j != interval.size() + 1 ? "," : "}\n")); } } else if (attribute.getType() == AttributeType.IntegerNumerical) { IntegerNumericalAttribute intAtt = (IntegerNumericalAttribute) attribute; header.append("integer[" + (int) intAtt.intervalValues().getLeft() + "," + (int) intAtt.intervalValues().getRight() + "]\n"); } else if (attribute.getType() == AttributeType.DoubleNumerical) { RealNumericalAttribute doubleAtt = (RealNumericalAttribute) attribute; header.append("real[" + doubleAtt.intervalValues().getLeft() + "," + doubleAtt.intervalValues().getRight() + "]\n"); } } header.append("@data\n"); consoleReporter.setHeader(header.toString()); dataset.close(); return schema; }
From source file:keel.Algorithms.Neural_Networks.NNEP_Regr.KEELWrapperRegr.java
/** * <p>// w w w . ja v a 2 s. c om * Reads schema from the KEEL file * </p> * @param jobFilename Name of the KEEL dataset file */ private static byte[] readSchema(String fileName) throws IOException, DatasetException { KeelDataSet dataset = new KeelDataSet(fileName); dataset.open(); File file = new File(fileName); List<String> inputIds = new ArrayList<String>(); List<String> outputIds = new ArrayList<String>(); Reader reader = new BufferedReader(new FileReader(file)); String line = ((BufferedReader) reader).readLine(); line = line.replace("real[", "real ["); line = line.replace("integer[", "integer ["); line = line.replace("{", " {"); StringTokenizer elementLine = new StringTokenizer(line); String element = elementLine.nextToken(); while (!element.equalsIgnoreCase("@data")) { if (element.equalsIgnoreCase("@inputs")) { while (elementLine.hasMoreTokens()) { StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ","); while (commaTokenizer.hasMoreTokens()) inputIds.add(commaTokenizer.nextToken()); } } else if (element.equalsIgnoreCase("@outputs")) { while (elementLine.hasMoreTokens()) { StringTokenizer commaTokenizer = new StringTokenizer(elementLine.nextToken(), ","); while (commaTokenizer.hasMoreTokens()) outputIds.add(commaTokenizer.nextToken()); } } // Next line of the file line = ((BufferedReader) reader).readLine(); while (line.startsWith("%") || line.equalsIgnoreCase("")) line = ((BufferedReader) reader).readLine(); line = line.replace("real[", "real ["); line = line.replace("integer[", "integer ["); line = line.replace("{", " {"); elementLine = new StringTokenizer(line); element = elementLine.nextToken(); } IMetadata metadata = dataset.getMetadata(); byte[] schema = new byte[metadata.numberOfAttributes()]; if (inputIds.isEmpty() || outputIds.isEmpty()) { for (int i = 0; i < schema.length; i++) { if (i != (schema.length - 1)) schema[i] = 1; else { IAttribute outputAttribute = metadata.getAttribute(i); schema[i] = 2; consoleReporter.setOutputAttribute(outputAttribute); } } } else { for (int i = 0; i < schema.length; i++) { if (inputIds.contains(metadata.getAttribute(i).getName())) schema[i] = 1; else if (outputIds.contains(metadata.getAttribute(i).getName())) { IAttribute outputAttribute = metadata.getAttribute(i); schema[i] = 2; consoleReporter.setOutputAttribute(outputAttribute); } else schema[i] = -1; } } StringBuffer header = new StringBuffer(); header.append("@relation " + dataset.getName() + "\n"); for (int i = 0; i < metadata.numberOfAttributes(); i++) { IAttribute attribute = metadata.getAttribute(i); header.append("@attribute " + attribute.getName() + " "); if (attribute.getType() == AttributeType.Categorical) { CategoricalAttribute catAtt = (CategoricalAttribute) attribute; Interval interval = catAtt.intervalValues(); header.append("{"); for (int j = (int) interval.getLeft(); j <= interval.size() + 1; j++) { header.append(catAtt.show(j) + (j != interval.size() + 1 ? "," : "}\n")); } } else if (attribute.getType() == AttributeType.IntegerNumerical) { IntegerNumericalAttribute intAtt = (IntegerNumericalAttribute) attribute; header.append("integer[" + (int) intAtt.intervalValues().getLeft() + "," + (int) intAtt.intervalValues().getRight() + "]\n"); } else if (attribute.getType() == AttributeType.DoubleNumerical) { RealNumericalAttribute doubleAtt = (RealNumericalAttribute) attribute; header.append("real[" + doubleAtt.intervalValues().getLeft() + "," + doubleAtt.intervalValues().getRight() + "]\n"); } } header.append("@data\n"); consoleReporter.setHeader(header.toString()); dataset.close(); return schema; }
From source file:eionet.cr.web.util.JstlFunctions.java
/** * Parses the given string with a whitespace tokenizer and looks up the first token whose length exceeds <tt>cutAtLength</tt>. * If such a token is found, returns the given string's <code>substring(0, i + cutAtLength) + "..."</code>, where <code>i</code> * is the start index of the found token. If no tokens are found that exceed the length of <tt>cutAtLength</tt>, then this * method simply return the given string. * * @return/*from w ww .ja va 2 s .c o m*/ */ public static java.lang.String cutAtFirstLongToken(java.lang.String str, int cutAtLength) { if (str == null) { return ""; } String firstLongToken = null; StringTokenizer st = new StringTokenizer(str); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.length() > cutAtLength) { firstLongToken = token; break; } } if (firstLongToken != null) { int i = str.indexOf(firstLongToken); StringBuffer buf = new StringBuffer(str.substring(0, i + cutAtLength)); return buf.append("...").toString(); } else { return str; } }
From source file:net.sf.jhylafax.fax.HylaFAXClientHelper.java
static int parseDuration(String s) { StringTokenizer t = new StringTokenizer(s, ":"); int duration = 0; while (t.hasMoreTokens()) { int n = Integer.parseInt(t.nextToken()); duration = duration * 60 + n;/* w w w . j av a 2 s . co m*/ } return duration; }
From source file:gmgen.util.MiscUtilities.java
/** * Converts an internal version number (build) into a `human-readable' form. * *@param build The build number/* w w w . ja v a 2 s .c o m*/ *@return The Formatted Version Number */ public static String buildToVersion(String build) { StringTokenizer bt = new StringTokenizer(build, "."); // First 2 chars are the major version number int major = 0; if (bt.hasMoreTokens()) { major = Integer.parseInt(bt.nextToken()); } // Second 2 are the minor number int minor = 0; if (bt.hasMoreTokens()) { minor = Integer.parseInt(bt.nextToken()); } // Then the pre-release status int beta = 0; if (bt.hasMoreTokens()) { beta = Integer.parseInt(bt.nextToken()); } // Finally the bug fix release int rc = 0; if (bt.hasMoreTokens()) { rc = Integer.parseInt(bt.nextToken()); } // Finally the bug fix release int bugfix = 0; if (bt.hasMoreTokens()) { bugfix = Integer.parseInt(bt.nextToken()); } return "" + major + "." + minor + ((beta != 99) ? ("pre" + beta) : ((rc != 99) ? ("rc" + rc) : ((bugfix != 0) ? ("." + bugfix) : "final"))); }