Example usage for java.util StringTokenizer hasMoreTokens

List of usage examples for java.util StringTokenizer hasMoreTokens

Introduction

In this page you can find the example usage for java.util StringTokenizer hasMoreTokens.

Prototype

public boolean hasMoreTokens() 

Source Link

Document

Tests if there are more tokens available from this tokenizer's string.

Usage

From source file:net.cbtltd.server.PartyService.java

/**
 * Parse address:value;city:value;zip:value format and returns formatted address. 
 * /*from  www  .ja  va  2  s  .  c o  m*/
 * @param party party to get address from
 * @return formatted address
 */
public static String getSimpleAddress(Party party) {
    if (party == null || party.getPostaladdress() == null) {
        throw new ServiceException(Error.address_invalid, "or party is null");
    }
    String address = party.getPostaladdress();
    StringTokenizer tokenizer = new StringTokenizer(address, ";");
    String result = "";
    while (tokenizer.hasMoreTokens()) {
        String string = tokenizer.nextToken();
        String[] splittedValue = string.split(":");
        result += splittedValue[1] + ", ";
    }
    if (result.contains(",")) {
        result = result.substring(0, result.lastIndexOf(", "));
    } else {
        return "";
    }
    return result;
}

From source file:edu.stanford.muse.xword.Crossword.java

/** returns the word without spaces, after canonicalization (replaces periods and hyphens with spaces), along with the breakup of the words in the term */
public static Pair<String, List<Integer>> convertToWord(String s) {
    s = cleanCandidate(s);// ww  w  .  j a v a  2s  .com
    StringTokenizer st = new StringTokenizer(s);
    String trimmedWord = "";
    List<Integer> list = new ArrayList<Integer>();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        trimmedWord += token;
        list.add(token.length());
    }
    return new Pair<String, List<Integer>>(trimmedWord, list);
}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This method creates patch for batch class.
 * //  w ww  .  j  av  a 2s. c  om
 * @param service {@link BatchClassService}
 * @param batchClassInfo {@link String}
 */
private static void createPatchForBatchClass(BatchClassService service, String batchClassInfo) {
    StringTokenizer batchClassTokens = new StringTokenizer(batchClassInfo, DataAccessConstant.SEMI_COLON);
    while (batchClassTokens.hasMoreTokens()) {
        String batchClassName = batchClassTokens.nextToken();
        try {
            BatchClass createdBatchClass = createPatchForBatchClass(batchClassName, service);
            if (createdBatchClass != null) {
                batchClassNameVsBatchClassMap.put(createdBatchClass.getName(), createdBatchClass);
            }

        } catch (NoSuchElementException e) {
            LOG.error("Incomplete data specified in properties file.", e);
        }
    }

    try {
        File serializedExportFile = new File(
                upgradePatchFolderPath + File.separator + "BatchClassUpdate" + SERIALIZATION_EXT);
        SerializationUtils.serialize(batchClassNameVsBatchClassMap, new FileOutputStream(serializedExportFile));
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
    }
}

From source file:gov.nih.nci.system.web.util.RESTUtil.java

public static Object getObject(String className, String idValue, HttpServletRequest request,
        String base64encodedUsernameAndPassword, boolean collection)
        throws gov.nih.nci.system.client.util.xml.XMLUtilityException {
    try {/*from   w  w w. j a  v  a  2s .  com*/
        String url = request.getRequestURL().toString();
        String queryStr = "id";
        List<String> idValues = new ArrayList<String>();
        if (idValue.indexOf(",") != -1) {
            StringTokenizer tokenizer = new StringTokenizer(idValue, ",");
            while (tokenizer.hasMoreTokens())
                idValues.add(tokenizer.nextToken());
        } else {
            idValues.add(idValue);
        }
        //Set returnCollection = new HashSet();
        Collection returnCollection = new HashSet();
        for (String idStr : idValues) {
            String restURL = url.substring(0, url.lastIndexOf("/"));
            WebClient client = WebClient.create(restURL);

            if (base64encodedUsernameAndPassword != null) {
                client.header("Authorization", "Basic " + base64encodedUsernameAndPassword);
            }
            String path = "rest/" + className.substring(className.lastIndexOf(".") + 1, className.length())
                    + "/" + idStr;
            client.path(path);
            client.type("application/xml").accept("application/xml");
            Response r = client.get();
            if (r.getStatus() != Status.OK.getStatusCode()) {
                throw new gov.nih.nci.system.client.util.xml.XMLUtilityException(
                        "Failed to lookup id: " + idStr + " for class: " + className);
            } else {
                InputStream is = (InputStream) r.getEntity();
                InputStreamReader in = new InputStreamReader(is);
                String jaxbContextName = className.substring(0, className.lastIndexOf("."));
                Unmarshaller unmarshaller = new JAXBUnmarshaller(true, jaxbContextName);
                XMLUtility myUtil = new XMLUtility(null, unmarshaller);
                Object obj = myUtil.fromXML(in);
                if (collection) {
                    returnCollection.add(obj);
                    //return returnCol;
                } else
                    return obj;
            }
        }

        return returnCollection;
    } catch (gov.nih.nci.system.client.util.xml.XMLUtilityException e) {
        throw e;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new gov.nih.nci.system.client.util.xml.XMLUtilityException(
                "Failed to lookup id: " + idValue + " for class: " + className);
    }
}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This method creates patch for plugin config. 
 * //from w  ww.j a  v a 2 s.  c o m
 * @param service {@link BatchClassService}
 * @param pluginConfigInfo {@link String}
 */
private static void createPatchForPluginConfig(BatchClassService service, final String pluginConfigInfo) {
    StringTokenizer pluginTokens = new StringTokenizer(pluginConfigInfo, DataAccessConstant.SEMI_COLON);
    while (pluginTokens.hasMoreTokens()) {
        String pluginToken = pluginTokens.nextToken();
        StringTokenizer pluginConfigTokens = new StringTokenizer(pluginToken, DataAccessConstant.COMMA);
        String pluginId = null;
        String pluginConfigId = null;
        try {
            pluginId = pluginConfigTokens.nextToken();
            pluginConfigId = pluginConfigTokens.nextToken();
            createPatch(pluginId, pluginConfigId, service);

        } catch (NoSuchElementException e) {
            LOG.error("Incomplete data specified in properties file.", e);
        }
    }

    try {
        File serializedExportFile = new File(
                upgradePatchFolderPath + File.separator + "PluginConfigUpdate" + SERIALIZATION_EXT);
        SerializationUtils.serialize(pluginNameVsBatchPluginConfigList,
                new FileOutputStream(serializedExportFile));
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
    }
}

From source file:com.sun.socialsite.util.Utilities.java

/** Convert string with delimeters to string list. */
public static List<String> stringToStringList(String instr, String delim)
        throws NoSuchElementException, NumberFormatException {
    StringTokenizer toker = new StringTokenizer(instr, delim);
    List<String> stringList = new ArrayList<String>();
    while (toker.hasMoreTokens()) {
        stringList.add(toker.nextToken());
    }/*w w w.  ja va 2s  .  com*/
    return stringList;
}

From source file:com.ephesoft.dcma.da.common.UpgradePatchPreparation.java

/**
 * This method creates patch for module.
 * //from  w w  w.  ja v  a2  s . com
 * @param service {@link BatchClassService}
 * @param moduleInfo {@link String}
 */
private static void createPatchForModule(BatchClassService service, String moduleInfo) {
    StringTokenizer moduleTokens = new StringTokenizer(moduleInfo, DataAccessConstant.SEMI_COLON);
    while (moduleTokens.hasMoreTokens()) {
        String moduleToken = moduleTokens.nextToken();
        StringTokenizer pluginConfigTokens = new StringTokenizer(moduleToken, DataAccessConstant.COMMA);
        String batchClassName = null;
        String moduleId = null;
        try {
            batchClassName = pluginConfigTokens.nextToken();
            moduleId = pluginConfigTokens.nextToken();
            BatchClassModule createdModule = createPatchForModule(batchClassName, moduleId, service);
            if (createdModule != null) {
                BatchClass batchClass = service.getBatchClassByIdentifier(batchClassName);
                ArrayList<BatchClassModule> bcmList = batchClassNameVsModulesMap.get(batchClass.getName());
                if (bcmList == null) {
                    bcmList = new ArrayList<BatchClassModule>();
                    batchClassNameVsModulesMap.put(batchClass.getName(), bcmList);
                }
                bcmList.add(createdModule);
            }

        } catch (NoSuchElementException e) {
            LOG.error("Incomplete data specified in properties file.", e);
        }
    }

    try {
        File serializedExportFile = new File(
                upgradePatchFolderPath + File.separator + "ModuleUpdate" + SERIALIZATION_EXT);
        SerializationUtils.serialize(batchClassNameVsModulesMap, new FileOutputStream(serializedExportFile));
    } catch (FileNotFoundException e) {
        // Unable to read serializable file
        LOG.error(ERROR_OCCURRED_WHILE_CREATING_THE_SERIALIZABLE_FILE + e.getMessage(), e);
    }

}

From source file:com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck.java

/**
 * Extracts defined amount of domains from the left side of package/import identifier
 * @param firstPackageDomainsCount/*  w w  w . j ava  2 s.co  m*/
 *        number of first package domains.
 * @param packageFullPath
 *        full identifier containing path to package or imported object.
 * @return String with defined amount of domains or full identifier
 *        (if full identifier had less domain then specified)
 */
private static String getFirstNDomainsFromIdent(final int firstPackageDomainsCount,
        final String packageFullPath) {
    final StringBuilder builder = new StringBuilder();
    final StringTokenizer tokens = new StringTokenizer(packageFullPath, ".");
    int count = firstPackageDomainsCount;

    while (tokens.hasMoreTokens() && count > 0) {
        builder.append(tokens.nextToken()).append('.');
        count--;
    }
    return builder.toString();
}

From source file:org.cyberoam.iview.charts.Chart.java

/**
 * This Method gives Title with Dynamic values of Parameter
 * @param title//from w w w  . j  ava  2 s. c  o 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.dsj.core.beans.StringUtils.java

/**
 * Tokenize the given String into a String array via a StringTokenizer.
 * <p>The given delimiters string is supposed to consist of any number of
 * delimiter characters. Each of those characters can be used to separate
 * tokens. A delimiter is always a single character; for multi-character
 * delimiters, consider using <code>delimitedListToStringArray</code>
 * @param str the String to tokenize//from  ww  w  . j a  v  a2s  .c om
 * @param delimiters the delimiter characters, assembled as String
 * (each of those characters is individually considered as delimiter)
 * @param trimTokens trim the tokens via String's <code>trim</code>
 * @param ignoreEmptyTokens omit empty tokens from the result array
 * (only applies to tokens that are empty after trimming; StringTokenizer
 * will not consider subsequent delimiters as token in the first place).
 * @return an array of the tokens
 * @see java.util.StringTokenizer
 * @see java.lang.String#trim
 * @see #delimitedListToStringArray
 */
public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens,
        boolean ignoreEmptyTokens) {

    StringTokenizer st = new StringTokenizer(str, delimiters);
    List tokens = new ArrayList();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (trimTokens) {
            token = token.trim();
        }
        if (!ignoreEmptyTokens || token.length() > 0) {
            tokens.add(token);
        }
    }
    return toStringArray(tokens);
}