List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:edu.stanford.muse.index.NER.java
public static void readLocationsWG() { InputStream is = null;//from ww w . ja va 2 s . co m try { is = new GZIPInputStream(NER.class.getClassLoader().getResourceAsStream("WG.locations.txt.gz")); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is, "UTF-8")); while (true) { String line = lnr.readLine(); if (line == null) break; StringTokenizer st = new StringTokenizer(line, "\t"); if (st.countTokens() == 4) { String locationName = st.nextToken(); String canonicalName = locationName.toLowerCase(); if (locationsToSuppress.contains(canonicalName)) continue; String lat = st.nextToken(); String longi = st.nextToken(); String pop = st.nextToken(); long popl = Long.parseLong(pop); float latf = ((float) Integer.parseInt(lat)) / 100.0f; float longif = ((float) Integer.parseInt(longi)) / 100.0f; Long existingPop = populations.get(canonicalName); if (existingPop == null || popl > existingPop) { populations.put(canonicalName, popl); locations.put(canonicalName, new LocationInfo(locationName, Float.toString(latf), Float.toString(longif))); } } } if (is != null) is.close(); } catch (Exception e) { log.warn("Unable to read World Gazetteer file, places info may be inaccurate"); log.debug(Util.stackTrace(e)); } }
From source file:it.univpm.deit.semedia.musicuri.core.Toolset.java
/** * Removes the first occurence of an integer within a String. It is used to * remove the integer test case identifier from filenames that are used for * testing and evaluation purposes in this project * @param filename the filename to remove the identifier from * @return a string containing the filename without an identifier *//*from w w w .jav a 2 s . c o m*/ public static String removeTestCaseIdentifier(String filename) { String filenameWithoutIdentifier; StringTokenizer tok = new StringTokenizer(filename, " `~!@#$%^&*()_-+={}[]|\\:;\"'<>,.?/\t\n\r"); int numOfTokensInString = tok.countTokens(); String[] tokens = new String[numOfTokensInString]; int i = 0; while (tok.hasMoreTokens()) { String token = tok.nextToken(); tokens[i] = token; i++; } try { Integer tmp = new Integer(tokens[0]); int testCaseId = tmp.intValue(); String identifier = ""; if (testCaseId >= 1) { // add zero padding if (testCaseId >= 0 && testCaseId < 10) identifier = "000" + testCaseId + " "; if (testCaseId >= 10 && testCaseId < 100) identifier = "00" + testCaseId + " "; if (testCaseId >= 100 && testCaseId < 1000) identifier = "0" + testCaseId + " "; if (testCaseId > 1000) identifier = testCaseId + " "; } filenameWithoutIdentifier = filename.replaceFirst(identifier, ""); } catch (NumberFormatException e) { // if the first token was not an integer identifier, return what you got as input filenameWithoutIdentifier = filename; } return filenameWithoutIdentifier; }
From source file:jp.terasoluna.fw.validation.ValidationUtil.java
/** * ?URL??????????/*from w w w .ja v a 2 s . com*/ * * <code>null</code> ??????? * * @param value * @param allowallschemes ???????? * @param allow2slashes ?????? * @param nofragments URL?????? * @param schemesVar ?? * ????? * @return * ?URL?????? * <code>true</code>? * ?????<code>false</code>? */ public static boolean isUrl(String value, boolean allowallschemes, boolean allow2slashes, boolean nofragments, String schemesVar) { if (StringUtils.isEmpty(value)) { return true; } // ? int options = 0; if (allowallschemes) { options += UrlValidator.ALLOW_ALL_SCHEMES; } if (allow2slashes) { options += UrlValidator.ALLOW_2_SLASHES; } if (nofragments) { options += UrlValidator.NO_FRAGMENTS; } // ??????GenericValidator if (options == 0 && schemesVar == null) { if (GenericValidator.isUrl(value)) { return true; } return false; } // String[]?? String[] schemes = null; if (schemesVar != null) { StringTokenizer st = new StringTokenizer(schemesVar, ","); schemes = new String[st.countTokens()]; int i = 0; while (st.hasMoreTokens()) { schemes[i++] = st.nextToken().trim(); } } // ????UrlValidator UrlValidator urlValidator = new UrlValidator(schemes, options); if (urlValidator.isValid(value)) { return true; } return false; }
From source file:com.impetus.kundera.metadata.MetadataUtils.java
/** * Gets the enclosing document name./*from w w w. j a va 2 s . c o m*/ * * @param m * the m * @param criteria * Input criteria * @param viaColumnName * true if <code>criteria</code> is column Name, false if * <code>criteria</code> is column field name * @return the enclosing document name */ public static String getEnclosingEmbeddedFieldName(EntityMetadata m, String criteria, boolean viaColumnName, final KunderaMetadata kunderaMetadata) { String enclosingEmbeddedFieldName = null; StringTokenizer strToken = new StringTokenizer(criteria, "."); String embeddableAttributeName = null; String embeddedFieldName = null; String nestedEmbeddedFieldName = null; if (strToken.countTokens() > 0) { embeddableAttributeName = strToken.nextToken(); } if (strToken.countTokens() > 0) { embeddedFieldName = strToken.nextToken(); } if (strToken.countTokens() > 0) { nestedEmbeddedFieldName = strToken.nextToken(); } Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit()); EntityType entity = metaModel.entity(m.getEntityClazz()); try { Attribute attribute = entity.getAttribute(embeddableAttributeName); if (((MetamodelImpl) metaModel).isEmbeddable(((AbstractAttribute) attribute).getBindableJavaType())) { EmbeddableType embeddable = metaModel .embeddable(((AbstractAttribute) attribute).getBindableJavaType()); Iterator<Attribute> attributeIter = embeddable.getAttributes().iterator(); while (attributeIter.hasNext()) { AbstractAttribute attrib = (AbstractAttribute) attributeIter.next(); if (viaColumnName && attrib.getName().equals(embeddedFieldName)) { if (nestedEmbeddedFieldName != null && ((MetamodelImpl) metaModel) .isEmbeddable(((AbstractAttribute) attrib).getBindableJavaType())) { EmbeddableType nestedEmbeddable = metaModel .embeddable(((AbstractAttribute) attrib).getBindableJavaType()); Iterator<Attribute> iter = embeddable.getAttributes().iterator(); while (iter.hasNext()) { AbstractAttribute nestedAttribute = (AbstractAttribute) iter.next(); if (viaColumnName && nestedAttribute.getName().equals(embeddedFieldName)) { return nestedAttribute.getName(); } if (!viaColumnName && nestedAttribute.getJPAColumnName().equals(embeddedFieldName)) { return nestedAttribute.getName(); } } } else if (nestedEmbeddedFieldName != null && !((MetamodelImpl) metaModel) .isEmbeddable(((AbstractAttribute) attrib).getBindableJavaType())) { return null; } else { return attribute.getName(); } } if (!viaColumnName && attrib.getJPAColumnName().equals(embeddedFieldName)) { return attribute.getName(); } } } } catch (IllegalArgumentException iax) { return null; } return enclosingEmbeddedFieldName; }
From source file:net.cbtltd.server.PartyService.java
public static String getAddressValue(String address, Address.Type value) { if (address == null) { throw new ServiceException(Error.address_invalid, "or party is null"); }//from w ww. j av a 2 s . c o m StringTokenizer tokenizer = new StringTokenizer(address, ";"); if (tokenizer.countTokens() < 2) { return ""; } while (tokenizer.hasMoreTokens()) { String string = tokenizer.nextToken(); if (string.contains(value.name())) { String[] splittedValue = string.split(":"); if (splittedValue.length < 2) { return ""; } return splittedValue[1]; } } return ""; }
From source file:org.cyberoam.iview.charts.Chart.java
/** * This Method gives Title with Dynamic values of Parameter * @param title/*from w w w. ja v a 2 s. co m*/ * @param request * @param reportGroupBean * @return */ public static String getFormattedTitle(HttpServletRequest request, ReportGroupBean reportGroupBean, boolean isPDF) { String title = null; if (request != null) { Object[] paramValues = null; String paramName = null, paramVal = null; StringTokenizer stToken = new StringTokenizer(reportGroupBean.getInputParams(), ","); paramValues = new Object[stToken.countTokens()]; for (int i = 0; stToken.hasMoreTokens(); i++) { paramName = stToken.nextToken(); if (paramName != null && (paramName.equalsIgnoreCase("Application") || paramName.equalsIgnoreCase("Protocol Group") || paramName.equalsIgnoreCase("proto_group") && request.getParameter(paramName).indexOf(':') != -1)) { paramVal = request.getParameter(paramName); try { String data; data = ProtocolBean.getProtocolNameById( Integer.parseInt(paramVal.substring(0, paramVal.indexOf(':')))); data = data + paramVal.substring(paramVal.indexOf(':'), paramVal.length()); paramVal = data; } catch (Exception ex) { } } else if (paramName.equalsIgnoreCase("Severity")) { paramVal = TabularReportConstants.getSeverity(request.getParameter(paramName)); } else if (request.getParameter(paramName) == null || request.getParameter(paramName).equals("")) { paramVal = "N/A"; } else { paramVal = request.getParameter(paramName); } if (isPDF) { paramValues[i] = paramVal; } else { paramValues[i] = "<i>" + paramVal + "</i>"; } } MessageFormat queryFormat = new MessageFormat(reportGroupBean.getTitle()); title = queryFormat.format(paramValues); } if (title == null) { return reportGroupBean.getTitle(); } else { return title; } }
From source file:com.sun.socialsite.util.Utilities.java
/** Convert string to integer array. */ public static int[] stringToIntArray(String instr, String delim) throws NoSuchElementException, NumberFormatException { StringTokenizer toker = new StringTokenizer(instr, delim); int intArray[] = new int[toker.countTokens()]; int i = 0;//ww w. j a va2 s .co m while (toker.hasMoreTokens()) { String sInt = toker.nextToken(); int nInt = Integer.parseInt(sInt); intArray[i++] = new Integer(nInt).intValue(); } return intArray; }
From source file:com.sun.socialsite.util.Utilities.java
/** Convert string to string array. */ public static String[] stringToStringArray(String instr, String delim) throws NoSuchElementException, NumberFormatException { StringTokenizer toker = new StringTokenizer(instr, delim); String stringArray[] = new String[toker.countTokens()]; int i = 0;//from ww w . j a va2s .co m while (toker.hasMoreTokens()) { stringArray[i++] = toker.nextToken(); } return stringArray; }
From source file:isl.FIMS.utils.Utils.java
private static long getFreeSpaceOnLinux(String path) throws Exception { long bytesFree = -1; Process p = Runtime.getRuntime().exec("df " + "/" + path); //$NON-NLS-1$ //$NON-NLS-2$ InputStream reader = new BufferedInputStream(p.getInputStream()); StringBuffer buffer = new StringBuffer(); for (;;) {/* w w w .j a v a 2s . co m*/ int c = reader.read(); if (c == -1) { break; } buffer.append((char) c); } String outputText = buffer.toString(); reader.close(); // parse the output text for the bytes free info StringTokenizer tokenizer = new StringTokenizer(outputText, "\n"); //$NON-NLS-1$ tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { String line2 = tokenizer.nextToken(); StringTokenizer tokenizer2 = new StringTokenizer(line2, " "); //$NON-NLS-1$ if (tokenizer2.countTokens() >= 4) { tokenizer2.nextToken(); tokenizer2.nextToken(); tokenizer2.nextToken(); bytesFree = Long.parseLong(tokenizer2.nextToken()); return bytesFree * 1024; } return bytesFree * 1024; } throw new Exception("Can not read the free space of " + path + " path"); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:com.smartmarmot.common.Configurator.java
private static Query[] getQueries(String parameter, Properties _propsq) throws Exception { try {//from w ww . java2 s.c om StringTokenizer stq = new StringTokenizer(_propsq.getProperty(parameter), Constants.DELIMITER); String[] QueryLists = new String[stq.countTokens()]; int count = 0; while (stq.hasMoreTokens()) { String token = stq.nextToken().toString().trim(); QueryLists[count] = token; count++; } Collection<Query> Queries = new ArrayList<Query>(); for (int i = 0; i < QueryLists.length; i++) { try { Query q = getQueryProperties(_propsq, QueryLists[i]); Queries.add(q); } catch (Exception e1) { SmartLogger.logThis(Level.ERROR, "Error on Configurator on reading query " + QueryLists[i] + e1); SmartLogger.logThis(Level.INFO, "Query " + QueryLists[i] + " skipped due to error " + e1); } } Query[] queries = (Query[]) Queries.toArray(new Query[0]); return queries; } catch (Exception ex) { SmartLogger.logThis(Level.ERROR, "Error on Configurator on reading properties file " + _propsq.toString() + " getQueries(" + parameter + "," + _propsq.toString() + ") " + ex.getMessage()); return null; } }