List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:ch.admin.suis.msghandler.common.MessageType.java
/** * Creates a list of message types from the provided string value. If the value * is null or empty, an empty list is returned. * * @param typesValue the types in the form <code>type1 type2</code>, i.e. the types are * numerical values separated by whitespaces * @return List of message types from a message *///from w w w . j a va 2 s. c o m public static List<MessageType> from(String typesValue) { // read the message types final ArrayList<MessageType> messageTypes = new ArrayList<>(); if (null != typesValue) { final StringTokenizer types = new StringTokenizer(typesValue); while (types.hasMoreTokens()) { String type = types.nextToken(); messageTypes.add(new MessageType(Integer.decode(type))); } } return messageTypes; }
From source file:keel.Algorithms.Genetic_Rule_Learning.Falco_GP.Main.java
/** * <p>/* w w w. j a v a 2 s . co 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.falco.FalcoAlgorithm"); 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.falco.FalcoSyntaxTreeSpecies"); algConf.addProperty("process.evaluator[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoEvaluator"); algConf.addProperty("process.evaluator.alpha", Double.parseDouble(props.getProperty("alpha"))); 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.falco.FalcoCrossover"); algConf.addProperty("process.mutator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeMutator"); algConf.addProperty("process.mutator[@mut-prob]", Double.parseDouble(props.getProperty("mut-prob"))); algConf.addProperty("process.mutator.base-op[@type]", "net.sourceforge.jclec.problem.classification.falco.FalcoMutator"); algConf.addProperty("process.copy-prob", Double.parseDouble(props.getProperty("copy-prob"))); algConf.addProperty("process.listener[@type]", "net.sourceforge.jclec.problem.classification.falco.KeelFalcoPopulationReport"); 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:Main.java
/** * Normalize a uri containing ../ and ./ paths. * * @param uri The uri path to normalize// ww w . jav a 2 s .co m * @return The normalized uri */ public static String normalize(String uri) { if ("".equals(uri)) { return uri; } int leadingSlashes; for (leadingSlashes = 0; leadingSlashes < uri.length() && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) { } boolean isDir = (uri.charAt(uri.length() - 1) == '/'); StringTokenizer st = new StringTokenizer(uri, "/"); LinkedList clean = new LinkedList(); while (st.hasMoreTokens()) { String token = st.nextToken(); if ("..".equals(token)) { if (!clean.isEmpty() && !"..".equals(clean.getLast())) { clean.removeLast(); if (!st.hasMoreTokens()) { isDir = true; } } else { clean.add(".."); } } else if (!".".equals(token) && !"".equals(token)) { clean.add(token); } } StringBuffer sb = new StringBuffer(); while (leadingSlashes-- > 0) { sb.append('/'); } for (Iterator it = clean.iterator(); it.hasNext();) { sb.append(it.next()); if (it.hasNext()) { sb.append('/'); } } if (isDir && sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') { sb.append('/'); } return sb.toString(); }
From source file:com.enonic.cms.framework.util.UrlPathEncoder.java
private static StringBuffer doEncodePath(String localPath, String encoding) { StringBuffer encodedPath = new StringBuffer(localPath.length() * 2); if (localPath.startsWith("/")) { encodedPath.append("/"); }//from w ww. j a v a2 s .c om StringTokenizer st = new StringTokenizer(localPath, "/"); int i = 0; while (st.hasMoreTokens()) { String pathElement = st.nextToken(); i++; if (i > 1) { encodedPath.append("/"); } try { encodedPath.append(URLEncoder.encode(pathElement, encoding)); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "Failed to encode path '" + localPath + "' with encoding '" + encoding + "'", e); } } if (localPath.endsWith("/")) { encodedPath.append("/"); } return encodedPath; }
From source file:Main.java
/** * Input is "daddy[8880],sindhu[8880],camille[5555]. Return List of * InetSocketAddress/*w w w .ja va 2s.c o m*/ */ public static List<InetSocketAddress> parseCommaDelimitedHosts2(String hosts, int port_range) { StringTokenizer tok = new StringTokenizer(hosts, ","); String t; InetSocketAddress addr; Set<InetSocketAddress> retval = new HashSet<InetSocketAddress>(); while (tok.hasMoreTokens()) { t = tok.nextToken().trim(); String host = t.substring(0, t.indexOf('[')); host = host.trim(); int port = Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']'))); for (int i = port; i < port + port_range; i++) { addr = new InetSocketAddress(host, i); retval.add(addr); } } return new LinkedList<InetSocketAddress>(retval); }
From source file:com.flipkart.poseidon.handlers.http.utils.StringUtils.java
/** * Gets the query parameters from the URL * @param httpUrl The URL from which query params have to be extracted * @return // w w w . java2 s .co m */ public static Map<String, String> getQueryParams(String httpUrl) { Map<String, String> params = new HashMap<String, String>(); if (httpUrl == null) { return params; } URL url = null; try { url = new URL(httpUrl); } catch (MalformedURLException e) { throw new RuntimeException(e); } String query = url.getQuery(); if (query == null) { return params; } StringTokenizer tokenizer = new StringTokenizer(query, "&"); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); int index = token.indexOf("="); params.put(token.substring(0, index).trim(), token.substring(index + 1).trim()); } return params; }
From source file:JavaUtils.java
/** * Utility to initialise the values of the JRE major/minor version. * Assumes the "java.version" string is in the form "XX.YY.ZZ". * Works for SUN JRE's.//from w ww. j a v a2 s . co m */ private static void initialiseJREVersion() { String version = System.getProperty("java.version"); // Assume that the version string is of the form XX.YY.ZZ (works for SUN JREs) StringTokenizer tokeniser = new StringTokenizer(version, "."); String token = tokeniser.nextToken(); try { Integer ver = new Integer(token); majorVersion = ver.intValue(); token = tokeniser.nextToken(); ver = new Integer(token); minorVersion = ver.intValue(); } catch (Exception e) { // Do nothing } versionInitialised = true; }
From source file:keel.Algorithms.Genetic_Rule_Learning.Tan_GP.Main.java
/** * <p>//from www . j a v a 2s . 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.tan.TanAlgorithm"); 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.tan.TanSyntaxTreeSpecies"); algConf.addProperty("process.evaluator[@type]", "net.sourceforge.jclec.problem.classification.tan.TanEvaluator"); algConf.addProperty("process.evaluator.w1", Double.parseDouble(props.getProperty("w1"))); algConf.addProperty("process.evaluator.w2", Double.parseDouble(props.getProperty("w2"))); 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.tan.TanCrossover"); algConf.addProperty("process.mutator[@type]", "net.sourceforge.jclec.syntaxtree.SyntaxTreeMutator"); algConf.addProperty("process.mutator[@mut-prob]", Double.parseDouble(props.getProperty("mut-prob"))); algConf.addProperty("process.mutator.base-op[@type]", "net.sourceforge.jclec.problem.classification.tan.TanMutator"); algConf.addProperty("process.copy-prob", Double.parseDouble(props.getProperty("copy-prob"))); algConf.addProperty("process.elitist-prob", Double.parseDouble(props.getProperty("elitist-prob"))); algConf.addProperty("process.support", Double.parseDouble(props.getProperty("support"))); algConf.addProperty("process.listener[@type]", "net.sourceforge.jclec.problem.classification.tan.KeelTanPopulationReport"); 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:com.l2jfree.gameserver.datatables.StaticObjects.java
public static L2StaticObjectInstance parse(String line) { StringTokenizer st = new StringTokenizer(line, ";"); st.nextToken(); //Pass over static object name (not used in server) int id = Integer.parseInt(st.nextToken()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); int z = Integer.parseInt(st.nextToken()); int type = Integer.parseInt(st.nextToken()); String texture = st.nextToken(); int map_x = Integer.parseInt(st.nextToken()); int map_y = Integer.parseInt(st.nextToken()); StatsSet npcDat = new StatsSet(); npcDat.set("npcId", id); npcDat.set("level", 0); npcDat.set("jClass", "staticobject"); npcDat.set("baseSTR", 0); npcDat.set("baseCON", 0); npcDat.set("baseDEX", 0); npcDat.set("baseINT", 0); npcDat.set("baseWIT", 0); npcDat.set("baseMEN", 0); npcDat.set("baseShldDef", 0); npcDat.set("baseShldRate", 0); npcDat.set("baseAccCombat", 38); npcDat.set("baseEvasRate", 38); npcDat.set("baseCritRate", 38); //npcDat.set("name", ""); npcDat.set("collision_radius", 10); npcDat.set("collision_height", 10); npcDat.set("fcollision_radius", 10); npcDat.set("fcollision_height", 10); npcDat.set("sex", "male"); npcDat.set("type", ""); npcDat.set("baseAtkRange", 0); npcDat.set("baseMpMax", 0); npcDat.set("baseCpMax", 0); npcDat.set("rewardExp", 0); npcDat.set("rewardSp", 0); npcDat.set("basePAtk", 0); npcDat.set("baseMAtk", 0); npcDat.set("basePAtkSpd", 0); npcDat.set("aggroRange", 0); npcDat.set("baseMAtkSpd", 0); npcDat.set("rhand", 0); npcDat.set("lhand", 0); npcDat.set("armor", 0); npcDat.set("baseWalkSpd", 0); npcDat.set("baseRunSpd", 0); npcDat.set("name", ""); npcDat.set("baseHpMax", 1); npcDat.set("baseHpReg", 3.e-3f); npcDat.set("baseMpReg", 3.e-3f); npcDat.set("basePDef", 1); npcDat.set("baseMDef", 1); L2CreatureTemplate template = new L2CreatureTemplate(npcDat); L2StaticObjectInstance obj = new L2StaticObjectInstance(IdFactory.getInstance().getNextId(), template, id); obj.setType(type);// w w w . j av a 2s.co m obj.getPosition().setXYZ(x, y, z); obj.setMap(texture, map_x, map_y); obj.spawnMe(); return obj; }
From source file:JavaUtils.java
/** * Check if the current version is greater or equals than the argument version. * @param version the version/*from www.j ava2 s . c om*/ * @return true if the runtime version is greater equals than the argument */ public static boolean isGreaterEqualsThan(String version) { boolean greaterEquals = false; StringTokenizer tokeniser = new StringTokenizer(version, "."); String token = tokeniser.nextToken(); try { Integer ver = new Integer(token); int majorVersion = ver.intValue(); token = tokeniser.nextToken(); ver = new Integer(token); int minorVersion = ver.intValue(); if (getJREMajorVersion() >= majorVersion && getJREMinorVersion() >= minorVersion) { greaterEquals = true; } } catch (Exception e) { // Do nothing } return greaterEquals; }