List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:Main.java
private static String getElementInPathAtPosixFromEnd(String path, int posix) { StringTokenizer st = new StringTokenizer(path, "."); int cpt = st.countTokens(); // if (cpt==1) // return root; int i = cpt - posix; for (int j = 0; j < i; j++) { st.nextToken(); }//from ww w . j av a 2s . c o m return (String) st.nextToken(); }
From source file:Main.java
public static int[] decodeMultiIntegerField(String field) throws NumberFormatException { StringTokenizer fieldTokens = new StringTokenizer(field, ";"); int[] result = new int[fieldTokens.countTokens()]; int counter = 0; while (fieldTokens.hasMoreTokens()) { String fieldToken = fieldTokens.nextToken(); result[counter++] = Integer.valueOf(fieldToken); }/* www . j a va2 s . co m*/ return result; }
From source file:keel.Algorithms.Genetic_Rule_Learning.Bojarczuk_GP.Main.java
/** * <p>/*from w w w . jav a2 s . c o m*/ * Configure the execution of the algorithm. * * @param jobFilename Name of the KEEL file with properties of the execution * </p> */ private static void configureJob(String jobFilename) { Properties props = new Properties(); try { InputStream paramsFile = new FileInputStream(jobFilename); props.load(paramsFile); paramsFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } // Files training and test String trainFile; String testFile; StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData")); tokenizer.nextToken(); trainFile = tokenizer.nextToken(); trainFile = trainFile.substring(1, trainFile.length() - 1); testFile = tokenizer.nextToken(); testFile = testFile.substring(1, testFile.length() - 1); tokenizer = new StringTokenizer(props.getProperty("outputData")); String reportTrainFile = tokenizer.nextToken(); reportTrainFile = reportTrainFile.substring(1, reportTrainFile.length() - 1); String reportTestFile = tokenizer.nextToken(); reportTestFile = reportTestFile.substring(1, reportTestFile.length() - 1); String reportRulesFile = tokenizer.nextToken(); reportRulesFile = reportRulesFile.substring(1, reportRulesFile.length() - 1); // Algorithm auxiliar configuration XMLConfiguration algConf = new XMLConfiguration(); algConf.setRootElementName("experiment"); algConf.addProperty("process[@algorithm-type]", "net.sourceforge.jclec.problem.classification.freitas.FreitasAlgorithm"); algConf.addProperty("process.rand-gen-factory[@type]", "net.sourceforge.jclec.util.random.RanecuFactory"); algConf.addProperty("process.rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed"))); algConf.addProperty("process.population-size", Integer.parseInt(props.getProperty("population-size"))); algConf.addProperty("process.max-of-generations", Integer.parseInt(props.getProperty("max-generations"))); algConf.addProperty("process.max-deriv-size", Integer.parseInt(props.getProperty("max-deriv-size"))); algConf.addProperty("process.dataset[@type]", "net.sourceforge.jclec.util.dataset.KeelDataSet"); algConf.addProperty("process.dataset.train-data.file-name", trainFile); algConf.addProperty("process.dataset.test-data.file-name", testFile); algConf.addProperty("process.species[@type]", "net.sourceforge.jclec.problem.classification.freitas.FreitasSyntaxTreeSpecies"); algConf.addProperty("process.evaluator[@type]", "net.sourceforge.jclec.problem.classification.freitas.FreitasEvaluator"); algConf.addProperty("process.provider[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeCreator"); algConf.addProperty("process.parents-selector[@type]", "net.sourceforge.jclec.selector.RouletteSelector"); algConf.addProperty("process.recombinator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeRecombinator"); algConf.addProperty("process.recombinator[@rec-prob]", Double.parseDouble(props.getProperty("rec-prob"))); algConf.addProperty("process.recombinator.base-op[@type]", "net.sourceforge.jclec.problem.classification.freitas.FreitasCrossover"); algConf.addProperty("process.copy-prob", Double.parseDouble(props.getProperty("copy-prob"))); algConf.addProperty("process.listener[@type]", "net.sourceforge.jclec.problem.classification.freitas.KeelFreitasPopulationReport"); algConf.addProperty("process.listener.report-dir-name", "./"); algConf.addProperty("process.listener.train-report-file", reportTrainFile); algConf.addProperty("process.listener.test-report-file", reportTestFile); algConf.addProperty("process.listener.rules-report-file", reportRulesFile); algConf.addProperty("process.listener.global-report-name", "resumen"); algConf.addProperty("process.listener.report-frequency", 50); try { algConf.save(new File("configure.txt")); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } net.sourceforge.jclec.RunExperiment.main(new String[] { "configure.txt" }); }
From source file:architecture.common.util.LocaleUtils.java
/** * Converts a locale string like "en", "en_US" or "en_US_win" to a Java * locale object. If the conversion fails, null is returned. * * @param localeCode// ww w.ja v a 2 s . c om * the locale code for a Java locale. See the * {@link java.util.Locale} class for more details. * @return The Java Locale that matches the locale code, or <tt>null</tt>. */ public static Locale localeCodeToLocale(String localeCode) { Locale locale = null; if (localeCode != null) { String language = null; String country = null; String variant = null; StringTokenizer tokenizer = new StringTokenizer(localeCode, "_"); if (tokenizer.hasMoreTokens()) { language = tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { country = tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { variant = tokenizer.nextToken(); } } } locale = new Locale(language, ((country != null) ? country : ""), ((variant != null) ? variant : "")); } return locale; }
From source file:edu.stanford.muse.lang.Languages.java
public static void init() { allPatterns.clear();//from ww w . j a v a2 s .c o m allLanguages.clear(); allScripts.clear(); allLanguages.add("English"); allScripts.add("Roman"); for (String[] lang : script_languages) { String scriptName = lang[0]; String langString = lang[1]; List<String> languages = new ArrayList<String>(); // tokenize langString by , StringTokenizer st = new StringTokenizer(langString, ","); while (st.hasMoreTokens()) { String language = st.nextToken(); language = language.trim(); if (language.length() == 0) continue; languages.add(language); } // build up pattern array or all pattern to languages for (String language : languages) { Pattern p = Pattern.compile(".*\\p{In" + scriptName + "}.*", Pattern.DOTALL); // DOTALL allows matching across lines which is what we want to detect chars in a given script allPatterns.add(new LangInfo(p, language)); allScripts.add(scriptName); allLanguages.add(language); } } log.info(allScripts.size() + " scripts, " + allLanguages.size() + " languages, " + allPatterns.size() + " patterns"); }
From source file:Main.java
public static final String[] toStringArray(String text, String token) { if (text == null || text.length() == 0) { return new String[0]; }// www .ja v a 2 s. c o m StringTokenizer tokens = new StringTokenizer(text, token); String[] words = new String[tokens.countTokens()]; for (int i = 0; i < words.length; i++) { words[i] = tokens.nextToken(); } return words; }
From source file:ddf.security.sts.claimsHandler.AttributeMapLoader.java
/** * Obtains the user name from the principal. * * @param principal Describing the current user that should be used for retrieving claims. * @return the user name if the principal has one, null if no name is specified or if principal * is null.//from w ww . ja v a 2s . c om */ public static String getUser(Principal principal) { String user = null; if (principal instanceof KerberosPrincipal) { KerberosPrincipal kp = (KerberosPrincipal) principal; StringTokenizer st = new StringTokenizer(kp.getName(), "@"); st = new StringTokenizer(st.nextToken(), "/"); user = st.nextToken(); } else if (principal instanceof X500Principal) { X500Principal x500p = (X500Principal) principal; StringTokenizer st = new StringTokenizer(x500p.getName(), ","); while (st.hasMoreElements()) { // token is in the format: // syntaxAndUniqueId // cn // ou // o // loc // state // country String[] strArr = st.nextToken().split("="); if (strArr.length > 1 && strArr[0].equalsIgnoreCase("cn")) { user = strArr[1]; break; } } } else if (principal != null) { user = principal.getName(); } return user; }
From source file:Main.java
/** * Splits a string around matches of the given delimiter character. * * Where applicable, this method can be used as a substitute for * <code>String.split(String regex)</code>, which is not available * on a JSR169/Java ME platform./* w ww. ja v a 2s .c o m*/ * * @param str the string to be split * @param delim the delimiter * @throws NullPointerException if str is null */ static public String[] split(String str, char delim) { if (str == null) { throw new NullPointerException("str can't be null"); } // Note the javadoc on StringTokenizer: // StringTokenizer is a legacy class that is retained for // compatibility reasons although its use is discouraged in // new code. // In other words, if StringTokenizer is ever removed from the JDK, // we need to have a look at String.split() (or java.util.regex) // if it is supported on a JSR169/Java ME platform by then. StringTokenizer st = new StringTokenizer(str, String.valueOf(delim)); int n = st.countTokens(); String[] s = new String[n]; for (int i = 0; i < n; i++) { s[i] = st.nextToken(); } return s; }
From source file:Main.java
public static String normalizeSpace(String str) { if (!isNullOrEmpty(str)) { StringTokenizer st = new StringTokenizer(str); if (st.hasMoreTokens()) { StringBuffer sb = new StringBuffer(str.length()); while (true) { sb.append(st.nextToken()); if (st.hasMoreTokens()) { sb.append(' '); } else { break; }/* w ww .j ava 2 s. c om*/ } return sb.toString(); } else { return ""; } } else { return str; } }
From source file:Main.java
private static ArrayList<String> parseLine(String line) { StringTokenizer st = new StringTokenizer(line); ArrayList<String> tokens = new ArrayList<>(); while (st.hasMoreTokens()) { tokens.add(st.nextToken()); }//from ww w . j a v a 2 s .com return tokens; }