List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:com.adsapient.shared.service.TimeService.java
public static final boolean isInBlockTime(String beginTime, String endTime) throws IncorrectDateException { int beginHour; int endHour;//ww w . j a va 2s .com int beginMinute; int endMinute; Calendar calendar = Calendar.getInstance(); int currentHour = calendar.get(Calendar.HOUR_OF_DAY); int currentMinute = calendar.get(Calendar.MINUTE); if (StringUtils.isEmpty(beginTime) | StringUtils.isEmpty(endTime)) { throw new IncorrectDateException("Date string is empty."); } StringTokenizer begin = new StringTokenizer(beginTime, ":"); StringTokenizer end = new StringTokenizer(endTime, ":"); if (!begin.hasMoreTokens()) { throw new IncorrectDateException("Begin time was not specified."); } if (!end.hasMoreTokens()) { throw new IncorrectDateException("End time was not specified."); } String tempBH = begin.nextToken(); String tempEH = end.nextToken(); try { beginHour = Integer.parseInt(tempBH); endHour = Integer.parseInt(tempEH); } catch (NumberFormatException e) { throw new IncorrectDateException("Year parameter should be numeric."); } String tempBM = begin.nextToken(); String tempEM = end.nextToken(); try { beginMinute = Integer.parseInt(tempBM); endMinute = Integer.parseInt(tempEM); } catch (NumberFormatException e) { throw new IncorrectDateException("Year parameter should be numeric."); } System.out.println("cur hour" + currentHour + " curr min" + currentMinute); System.out.println("begin time" + beginHour + " begin min" + beginMinute); if ((currentHour > beginHour) | ((currentHour == beginHour) & (currentMinute > beginMinute))) { if ((currentHour < endHour) | ((currentHour == endHour) & (currentMinute < endMinute))) { return true; } } return false; }
From source file:hepple.postag.POSTagger.java
/** * Reads one input file and creates the structure needed by the tagger * for input.//from w w w. ja v a 2 s . c o m */ @SuppressWarnings("unused") private static List<List<String>> readInput(String file) throws IOException { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); String line = reader.readLine(); List<List<String>> result = new ArrayList<List<String>>(); while (line != null) { StringTokenizer tokens = new StringTokenizer(line); List<String> sentence = new ArrayList<String>(); while (tokens.hasMoreTokens()) sentence.add(tokens.nextToken()); result.add(sentence); line = reader.readLine(); } //while(line != null) return result; } finally { IOUtils.closeQuietly(reader); } }
From source file:edu.stanford.muse.index.NEROld.java
public static void readLocationNamesToSuppress() { String suppress_file = "suppress.locations.txt.gz"; try {/*w w w .j a v a 2s. c om*/ InputStream is = new GZIPInputStream(NER.class.getClassLoader().getResourceAsStream(suppress_file)); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is, "UTF-8")); while (true) { String line = lnr.readLine(); if (line == null) break; StringTokenizer st = new StringTokenizer(line); if (st.hasMoreTokens()) { String s = st.nextToken(); if (!s.startsWith("#")) locationsToSuppress.add(s.toLowerCase()); } } } catch (Exception e) { log.warn("Error: unable to read " + suppress_file); Util.print_exception(e); } log.info(locationsToSuppress.size() + " names to suppress as locations"); }
From source file:net.pms.encoders.AviSynthFFmpeg.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;// w w w.j a va 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.getFfmpegAvisynthConvertFps()) { 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 interframeLines = null; String interframePath = configuration.getInterFramePath(); int Cores = 1; if (configuration.isFfmpegAviSynthMultithreading()) { 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)"; } // True Motion if (configuration.getFfmpegAvisynthInterFrame()) { String GPU = ""; movieLine += ".ConvertToYV12()"; // Enable GPU to assist with CPU if (configuration.getFfmpegAvisynthInterFrameGPU() && 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 = "<movie>\n<sub>\n"; 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); } if (configuration.getFfmpegAvisynthInterFrame()) { lines.add(mtLine2); lines.add(interframeLines); } 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:com.concursive.connect.web.modules.search.utils.SearchUtils.java
/** * Extracts the keywords into tokens, and then either concats them with AND * if all words are required, or leaves the tokens alone * * @param searchText Description of the Parameter * @param allWords Description of the Parameter * @return Description of the Return Value */// w ww. j av a 2 s . c o m public static String parseSearchText(String searchText, boolean allWords) { StringBuffer sb = new StringBuffer(); boolean returnTokens = true; String currentDelims = WHITESPACE_AND_QUOTES; StringTokenizer parser = new StringTokenizer(searchText, currentDelims, returnTokens); String token = null; boolean spacer = false; while (parser.hasMoreTokens()) { token = parser.nextToken(currentDelims); if (!isDoubleQuote(token)) { if (hasText(token)) { String gotToken = token.trim().toLowerCase(); if ("and".equals(gotToken) || "or".equals(gotToken) || "not".equals(gotToken)) { if (sb.length() > 0) { sb.append(" "); } sb.append(gotToken.toUpperCase()); spacer = true; } else { if (spacer) { if (sb.length() > 0) { sb.append(" "); } spacer = false; } else { if (sb.length() > 0) { if (allWords) { sb.append(" AND "); } else { sb.append(" "); } } } if (gotToken.indexOf(" ") > -1) { sb.append("\"").append(gotToken).append("\""); } else { sb.append(gotToken); } } } } else { currentDelims = flipDelimiters(currentDelims); } } return sb.toString(); }
From source file:jenkins.plugins.testopia.TestopiaBuilder.java
/** * <p>Define properties. Following is the list of available properties.</p> * //from ww w . j a v a2 s .c o m * <ul> * <li>xmlrpc.basicEncoding</li> * <li>xmlrpc.basicPassword</li> * <li>xmlrpc.basicUsername</li> * <li>xmlrpc.connectionTimeout</li> * <li>xmlrpc.contentLengthOptional</li> * <li>xmlrpc.enabledForExceptions</li> * <li>xmlrpc.encoding</li> * <li>xmlrpc.gzipCompression</li> * <li>xmlrpc.gzipRequesting</li> * <li>xmlrpc.replyTimeout</li> * <li>xmlrpc.userAgent</li> * </ul> * * @param properties List of comma separated properties * @param listener Jenkins Build listener */ public static void setProperties(String properties, BuildListener listener) { if (StringUtils.isNotBlank(properties)) { final StringTokenizer tokenizer = new StringTokenizer(properties, ","); if (tokenizer.countTokens() > 0) { while (tokenizer.hasMoreTokens()) { String systemProperty = tokenizer.nextToken(); maybeAddSystemProperty(systemProperty, listener); } } } }
From source file:com.icesoft.faces.component.ext.taglib.Util.java
/** * Gets the comma separated list of enabling user roles from the given * component and checks if current user is in one of these roles. * * @param component a user role aware component * @return true if no user roles are defined for this component or user is * in one of these roles, false otherwise *///from w w w . j a v a2 s .c om public static boolean isEnabledOnUserRole(UIComponent component) { if (ignoreUserRoleAttributes()) { return true; } String userRole; if (component instanceof IceExtended) { userRole = ((IceExtended) component).getEnabledOnUserRole(); } else { userRole = (String) component.getAttributes().get(IceExtended.ENABLED_ON_USER_ROLE_ATTR); } // there is no restriction if (userRole == null) { return true; } FacesContext facesContext = FacesContext.getCurrentInstance(); StringTokenizer st = new StringTokenizer(userRole, ","); while (st.hasMoreTokens()) { if (facesContext.getExternalContext().isUserInRole(st.nextToken().trim())) { return true; } } return false; }
From source file:com.qframework.core.ServerkoParse.java
public static int parseFloatArray(float[] array, String data) { int count = 0; float val = 0; StringTokenizer tok = new StringTokenizer(data, ","); while (tok.hasMoreTokens() && count < array.length) try {//w w w. j av a2 s .c o m try { val = Float.parseFloat(tok.nextToken()); } catch (NumberFormatException e) { } array[count++] = val; } catch (NoSuchElementException e) { } return count; }
From source file:com.qframework.core.ServerkoParse.java
public static int parseFloatArray2(float[] array, String data) { int count = 0; float val = 0; StringTokenizer tok = new StringTokenizer(data, " "); while (tok.hasMoreTokens() && count < array.length) try {//w w w.j a v a 2 s.co m try { val = Float.parseFloat(tok.nextToken()); } catch (NumberFormatException e) { } array[count++] = val; } catch (NoSuchElementException e) { } return count; }
From source file:com.qframework.core.ServerkoParse.java
public static int parseIntArray(int[] array, String data) { int count = 0; int val = 0; StringTokenizer tok = new StringTokenizer(data, ","); while (tok.hasMoreTokens() && count < array.length) try {/*from w w w . j a va 2 s .c om*/ try { val = Integer.parseInt(tok.nextToken()); } catch (NumberFormatException e) { } array[count++] = val; } catch (NoSuchElementException e) { } return count; }