List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:NimbleTree.java
/** * A static constructor (is this the right term?) where a lisp-style s-expression * is passed in as a string. This can't be a true constructor because the result * is a tree over String, not a generic tree. *//*w w w.j a v a2 s . co m*/ public static NimbleTree<String> makeTreeOverStringFromSExpression(String input) { NimbleTree<String> tree = new NimbleTree<String>(); Stack<TreeNode<String>> previousParents = new Stack<TreeNode<String>>(); // Make sure the string is tokenizable // FIXME allow [] and maybe other delimiters? input = input.replace("(", " ( "); input = input.replace(")", " ) "); StringTokenizer st = new StringTokenizer(input); boolean firstTimeThrough = true; while (st.hasMoreTokens()) { String currTok = st.nextToken().trim(); if (currTok.equals("")) { // Tokenizer gave us an empty token, do nothing. } else if (currTok.equals("(")) { // Get the *next* token and make a new subtree on it. currTok = st.nextToken().trim(); if (firstTimeThrough == true) { // The tree is of the form "(x)" // This is the root node: just set its data firstTimeThrough = false; tree.getRoot().setData(currTok); } else { // This is the root of a new subtree. Save parent, // then set this node to be the new parent. tree.addChild(currTok); tree.getCurrentNode().getEnd().setID(tree.getNodeCount()); previousParents.push(tree.getCurrentNode()); tree.setCurrentNode(tree.getCurrentNode().getEnd()); } } else if (currTok.equals(")")) { // Finished adding children to current parent. Go back // to previous parent (if there was none, it's because // current parent is root, so we're finished anyway). if (!previousParents.empty()) { tree.setCurrentNode(previousParents.pop()); } } else { if (firstTimeThrough == true) { // The tree is of the form "x". // This is to be the root node: just set its data. firstTimeThrough = false; tree.getRoot().setData(currTok); } else { // Add a child node to current parent. tree.addChild(currTok); tree.getCurrentNode().getEnd().setID(tree.getNodeCount()); } } } return tree; }
From source file:com.glaf.core.util.FtpUtils.java
/** * FTP/*from w ww. j a va 2s . c o m*/ * * @param remotePath * FTP"/" */ public static void mkdirs(String remotePath) { if (!remotePath.startsWith("/")) { throw new RuntimeException(" path must start with '/'"); } try { getFtpClient().changeWorkingDirectory("/"); if (remotePath.indexOf("/") != -1) { String tmp = ""; StringTokenizer token = new StringTokenizer(remotePath, "/"); while (token.hasMoreTokens()) { String str = token.nextToken(); tmp = tmp + "/" + str; getFtpClient().mkd(str); getFtpClient().changeWorkingDirectory(tmp); } } } catch (IOException ex) { ex.printStackTrace(); logger.error("mkdirs error", ex); throw new RuntimeException(ex); } }
From source file:net.pms.encoders.AviSynthMEncoder.java
public static File getAVSScript(String fileName, DLNAMediaSubtitle subTrack, int fromFrame, int toFrame, String frameRateRatio, String frameRateNumber, PmsConfiguration configuration) throws IOException { String onlyFileName = fileName.substring(1 + fileName.lastIndexOf('\\')); File file = new File(configuration.getTempFolder(), "pms-avs-" + onlyFileName + ".avs"); try (PrintWriter pw = new PrintWriter(new FileOutputStream(file))) { String numerator;/*from w w w.jav a 2s .c o m*/ String denominator; if (frameRateRatio != null && frameRateNumber != null) { if (frameRateRatio.equals(frameRateNumber)) { // No ratio was available numerator = frameRateRatio; denominator = "1"; } else { String[] frameRateNumDen = frameRateRatio.split("/"); numerator = frameRateNumDen[0]; denominator = "1001"; } } else { // No framerate was given so we should try the most common one numerator = "24000"; denominator = "1001"; frameRateNumber = "23.976"; } String assumeFPS = ".AssumeFPS(" + numerator + "," + denominator + ")"; String directShowFPS = ""; if (!"0".equals(frameRateNumber)) { directShowFPS = ", fps=" + frameRateNumber; } String convertfps = ""; if (configuration.getAvisynthConvertFps()) { convertfps = ", convertfps=true"; } File f = new File(fileName); if (f.exists()) { fileName = ProcessUtil.getShortFileNameIfWideChars(fileName); } String movieLine = "DirectShowSource(\"" + fileName + "\"" + directShowFPS + convertfps + ")" + assumeFPS; String mtLine1 = ""; String mtLine2 = ""; String mtLine3 = ""; String interframeLines = null; String interframePath = configuration.getInterFramePath(); int Cores = 1; if (configuration.getAvisynthMultiThreading()) { Cores = configuration.getNumberOfCpuCores(); // Goes at the start of the file to initiate multithreading mtLine1 = "SetMemoryMax(512)\nSetMTMode(3," + Cores + ")\n"; // Goes after the input line to make multithreading more efficient mtLine2 = "SetMTMode(2)"; // Goes at the end of the file to allow the multithreading to work with MEncoder mtLine3 = "SetMTMode(1)\nGetMTMode(false) > 0 ? distributor() : last"; } // True Motion if (configuration.getAvisynthInterFrame()) { String GPU = ""; movieLine += ".ConvertToYV12()"; // Enable GPU to assist with CPU if (configuration.getAvisynthInterFrameGPU() && interframegpu.isEnabled()) { GPU = ", GPU=true"; } interframeLines = "\n" + "PluginPath = \"" + interframePath + "\"\n" + "LoadPlugin(PluginPath+\"svpflow1.dll\")\n" + "LoadPlugin(PluginPath+\"svpflow2.dll\")\n" + "Import(PluginPath+\"InterFrame2.avsi\")\n" + "InterFrame(Cores=" + Cores + GPU + ", Preset=\"Faster\")\n"; } String subLine = null; if (subTrack != null && configuration.isAutoloadExternalSubtitles() && !configuration.isDisableSubtitles()) { if (subTrack.getExternalFile() != null) { LOGGER.info("AviSynth script: Using subtitle track: " + subTrack); String function = "TextSub"; if (subTrack.getType() == SubtitleType.VOBSUB) { function = "VobSub"; } subLine = function + "(\"" + ProcessUtil.getShortFileNameIfWideChars(subTrack.getExternalFile().getAbsolutePath()) + "\")"; } } ArrayList<String> lines = new ArrayList<>(); lines.add(mtLine1); boolean fullyManaged = false; String script = configuration.getAvisynthScript(); StringTokenizer st = new StringTokenizer(script, PMS.AVS_SEPARATOR); while (st.hasMoreTokens()) { String line = st.nextToken(); if (line.contains("<movie") || line.contains("<sub")) { fullyManaged = true; } lines.add(line); } lines.add(mtLine2); if (configuration.getAvisynthInterFrame()) { lines.add(interframeLines); } lines.add(mtLine3); if (fullyManaged) { for (String s : lines) { if (s.contains("<moviefilename>")) { s = s.replace("<moviefilename>", fileName); } s = s.replace("<movie>", movieLine); s = s.replace("<sub>", subLine != null ? subLine : "#"); pw.println(s); } } else { pw.println(movieLine); if (subLine != null) { pw.println(subLine); } pw.println("clip"); } } file.deleteOnExit(); return file; }
From source file:bboss.org.apache.velocity.util.StringUtils.java
/** * Create a string array from a string separated by delim * * @param line the line to split/* www . j a v a 2 s . co m*/ * @param delim the delimter to split by * @return a string array of the split fields */ public static String[] split(String line, String delim) { List list = new ArrayList(); StringTokenizer t = new StringTokenizer(line, delim); while (t.hasMoreTokens()) { list.add(t.nextToken()); } return (String[]) list.toArray(new String[list.size()]); }
From source file:edu.indiana.lib.twinpeaks.util.StatusUtils.java
/** * Set up initial status information/*from w w w. j a v a2s .co m*/ */ public static void initialize(SessionContext sessionContext, String targets) { StringTokenizer parser = new StringTokenizer(targets, " \t,"); ArrayList dbList = new ArrayList(); HashMap targetMap = getNewStatusMap(sessionContext); /* * Establish the DB list and initial (pre-LOGON) status */ while (parser.hasMoreTokens()) { String db = parser.nextToken(); HashMap emptyMap = new HashMap(); /* * Empty status entry */ emptyMap.put("STATUS", "INACTIVE"); emptyMap.put("STATUS_MESSAGE", "<none>"); emptyMap.put("HITS", "0"); emptyMap.put("ESTIMATE", "0"); emptyMap.put("MERGED", "0"); /* * Save */ dbList.add(db); targetMap.put(db, emptyMap); } /* * Search targets, global status */ sessionContext.put("TARGETS", dbList); sessionContext.putInt("active", 0); sessionContext.put("STATUS", "INACTIVE"); sessionContext.put("STATUS_MESSAGE", "<none>"); /* * Initial totals */ sessionContext.putInt("TOTAL_ESTIMATE", 0); sessionContext.putInt("TOTAL_HITS", 0); sessionContext.putInt("maxRecords", 0); /* * Assume this search is synchronous. An OSID that implements an * asynchronous search will need to set the async flags manually after * this code has finished. */ clearAsyncSearch(sessionContext); clearAsyncInit(sessionContext); }
From source file:com.glaf.core.util.FtpUtils.java
/** * FTP/*w ww. j a v a2s.c o m*/ * * @param remotePath * FTP"/" */ public static void deleteFile(String remotePath) { if (!remotePath.startsWith("/")) { throw new RuntimeException(" path must start with '/'"); } try { if (remotePath.indexOf("/") != -1) { String tmp = ""; List<String> dirs = new ArrayList<String>(); StringTokenizer token = new StringTokenizer(remotePath, "/"); while (token.hasMoreTokens()) { String str = token.nextToken(); tmp = tmp + "/" + str; dirs.add(tmp); } for (int i = 0; i < dirs.size() - 1; i++) { getFtpClient().changeWorkingDirectory(dirs.get(i)); } String dir = remotePath.substring(remotePath.lastIndexOf("/") + 1, remotePath.length()); logger.debug("rm " + dir); getFtpClient().deleteFile(dir); } else { getFtpClient().deleteFile(remotePath); } } catch (IOException ex) { ex.printStackTrace(); logger.error("deleteFile error", ex); throw new RuntimeException(ex); } }
From source file:com.floreantpos.util.StringUtils.java
/** * <p>// w ww . ja va2 s . c o m * Remove underscores from a string and replaces first * letters with capitals. Other letters are changed to lower case. * </p> * * <p> * For example <code>foo_bar</code> becomes <code>FooBar</code> * but <code>foo_barBar</code> becomes <code>FooBarbar</code>. * </p> * * @param data string to remove underscores from. * @return String * @deprecated Use the org.apache.commons.util.StringUtils class * instead. Using its firstLetterCaps() method in conjunction * with a StringTokenizer will achieve the same result. */ static public String removeUnderScores(String data) { String temp = null; StringBuilder out = new StringBuilder(); temp = data; StringTokenizer st = new StringTokenizer(temp, "_"); while (st.hasMoreTokens()) { String element = (String) st.nextElement(); out.append(firstLetterCaps(element)); } return out.toString(); }
From source file:com.salesmanager.core.util.FileUtil.java
/** * Decrypt & Parses a url with tokens for displaying url page * needs 2 tokens, an id (first) and ten a dat * @param tokens/* w ww . j ava2 s. c o m*/ * @return * @throws Exception */ public static Map<String, String> getUrlTokens(String token) throws Exception { String decrypted = EncryptionUtil.decrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant), token); StringTokenizer st = new StringTokenizer(decrypted, "|"); String id = ""; String date = ""; int i = 0; while (st.hasMoreTokens()) { String t = st.nextToken(); if (i == 0) { id = t; } else if (i == 1) { date = t; } else { break; } i++; } if (StringUtils.isBlank(id) || StringUtils.isBlank(date)) { throw new Exception("Invalid URL parameters for FileUtil.getUrlTokens " + token); } Map response = new HashMap(); response.put("ID", id); response.put("DATE", date); return response; }
From source file:bboss.org.apache.velocity.util.StringUtils.java
/** * <p>/*from w w w . j ava 2s . co m*/ * Remove underscores from a string and replaces first * letters with capitals. Other letters are changed to lower case. * </p> * * <p> * For example <code>foo_bar</code> becomes <code>FooBar</code> * but <code>foo_barBar</code> becomes <code>FooBarbar</code>. * </p> * * @param data string to remove underscores from. * @return String * @deprecated Use the org.apache.commons.util.StringUtils class * instead. Using its firstLetterCaps() method in conjunction * with a StringTokenizer will achieve the same result. */ static public String removeUnderScores(String data) { String temp = null; StringBuffer out = new StringBuffer(); temp = data; StringTokenizer st = new StringTokenizer(temp, "_"); while (st.hasMoreTokens()) { String element = (String) st.nextElement(); out.append(firstLetterCaps(element)); } return out.toString(); }
From source file:blue.noteProcessor.TempoMapper.java
public static TempoMapper createTempoMapper(String timeWarpString) { TempoMapper tm = new TempoMapper(); StringTokenizer st = new StringTokenizer(timeWarpString); String time, tempo;/*from www .j av a2s. c om*/ BeatTempoPair temp; if (st.countTokens() % 2 != 0) { // not an even amount of tokens! return null; } tm.timeMap = new BeatTempoPair[st.countTokens() / 2]; int index = 0; BeatTempoPair[] tMap = tm.timeMap; while (st.hasMoreTokens()) { try { time = st.nextToken(); tempo = st.nextToken(); temp = new BeatTempoPair(); temp.beat = Float.parseFloat(time); temp.tempo = Float.parseFloat(tempo); if (temp.beat < 0.0f || temp.tempo <= 0.0f) { return null; } tMap[index] = temp; if (index > 0) { float factor1 = 60.0f / tMap[index - 1].tempo; float factor2 = 60.0f / tMap[index].tempo; float deltaBeat = tMap[index].beat - tMap[index - 1].beat; float acceleration = 0.0f; if (deltaBeat >= 0.0f) { acceleration = (factor2 - factor1) / (tMap[index].beat - tMap[index - 1].beat); } if (tMap[index].beat == tMap[index - 1].beat) { tMap[index].accumulatedTime = tMap[index - 1].accumulatedTime; } else { tMap[index].accumulatedTime = tMap[index - 1].accumulatedTime + getAreaUnderCurve(factor1, deltaBeat, acceleration); } } index++; } catch (Exception e) { // if there's any errors whatsoever, return null // and let the calling procedure handle it return null; } } return tm; }