Example usage for java.util StringTokenizer hasMoreElements

List of usage examples for java.util StringTokenizer hasMoreElements

Introduction

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

Prototype

public boolean hasMoreElements() 

Source Link

Document

Returns the same value as the hasMoreTokens method.

Usage

From source file:org.wso2.carbon.apimgt.core.impl.APIDefinitionFromSwagger20.java

public static List<Parameter> getParameters(String uriTemplate) {
    List<Parameter> parameters = new ArrayList<>();
    StringTokenizer stringTokenizer = new StringTokenizer(uriTemplate, "/");
    while (stringTokenizer.hasMoreElements()) {
        String part1 = stringTokenizer.nextToken();
        if (part1.contains("{")) {
            String pathParam = part1.replace("{", "").replace("}", "");
            PathParameter parameter = new PathParameter();
            parameter.setName(pathParam);
            parameter.setType("string");
            parameters.add(parameter);/*  w  ww .  j  a va  2s. c o  m*/
        }
    }
    return parameters;
}

From source file:com.stratelia.webactiv.util.FileRepositoryManager.java

/**
 * to create the array of the string this array represents the repertories where the files must be
 * stored.//w w  w  . ja va 2s.co  m
 *
 * @param str : type String: the string of repertories
 * @return
 */
public static String[] getAttachmentContext(String str) {

    String strAt = "Attachment " + CONTEXT_TOKEN;

    if (str != null) {
        strAt = strAt.concat(str);
    }
    StringTokenizer strToken = new StringTokenizer(strAt, CONTEXT_TOKEN);
    // number of elements
    int nElt = strToken.countTokens();
    // to init array
    String[] context = new String[nElt];

    int k = 0;

    while (strToken.hasMoreElements()) {
        context[k] = ((String) strToken.nextElement()).trim();
        k++;
    }
    return context;
}

From source file:dynamicrefactoring.util.io.FileManager.java

/**
 * Permite obtener la ruta relativa de un fichero a partir de su ruta
 * absoluta./*from  w ww.  ja va2s .co  m*/
 * 
 * @param rutaAbsoluta
 *            ruta absoluta de un fichero.
 * @return devuelve la ruta relativa del fichero cuya rutaAbsoluta se ha
 *         introducido en al funcin.
 */
public static String AbsoluteToRelative(String rutaAbsoluta) {
    StringBuffer rutaRelativa = new StringBuffer();
    int contador = 0;
    boolean comun = false;
    Object absolute = null;
    Object actual = null;
    String rutaActual = new File(".").getAbsolutePath();

    String rAbsoluta = rutaAbsoluta.replace("/", File.separator);
    rAbsoluta = rAbsoluta.replace("" + File.separatorChar + "", File.separator);

    StringTokenizer st_absolute = new StringTokenizer(rAbsoluta, File.separator);
    StringTokenizer st_actual = new StringTokenizer(rutaActual, File.separator);

    while (st_absolute.hasMoreTokens() && st_actual.hasMoreElements()) {
        absolute = st_absolute.nextElement();
        actual = st_actual.nextElement();
        if (absolute.toString().equals(actual.toString())) {
            comun = true;
        } else {
            break;
        }
    }

    while (st_actual.hasMoreElements()) {
        st_actual.nextElement();
        contador++;
    }
    contador++;

    if (comun) {
        if (contador > 0) {
            for (int i = 1; i < contador; i++) {
                rutaRelativa.append(".." + File.separator);
            }
        } else if (contador == 0) {
            rutaRelativa.append("." + File.separator);
        }
        while (st_absolute.hasMoreElements()) {
            rutaRelativa.append(absolute.toString() + File.separator);
            absolute = st_absolute.nextElement();
        }
        rutaRelativa.append(absolute.toString());
        return rutaRelativa.toString().replace("" + File.separatorChar + "", "/");
    } else {
        return rAbsoluta; //estan en distinta unidad y por
        //tanto no se puede obtener su ruta relativa.
    }

}

From source file:edu.uci.ics.hyracks.control.nc.NodeControllerService.java

private static List<IODeviceHandle> getDevices(String ioDevices) {
    List<IODeviceHandle> devices = new ArrayList<IODeviceHandle>();
    StringTokenizer tok = new StringTokenizer(ioDevices, ",");
    while (tok.hasMoreElements()) {
        String devPath = tok.nextToken().trim();
        devices.add(new IODeviceHandle(new File(devPath), "."));
    }//from ww  w . j  a  v  a2s.c o m
    return devices;
}

From source file:org.hyperic.hq.product.DetectionUtil.java

/**
 * /*from   www  . j  a  va2s  .c  o  m*/
 * @param wmiObjName
 * @param filter a name-value pair. The first '-' sign seperates between the name and the value. The rest which follows are part of the value's name
 * @param col
 * @param name
 * @return
 * @throws PluginException
 */
public static Set<String> getWMIObj(String namespace, String wmiObjName, Map<String, String> filters,
        String col, String name) throws PluginException {
    if (wmiObjName == null || "".equals(wmiObjName)) {
        throw new PluginException("object property not specified in the template of " + name);
    }
    StringBuilder sb = new StringBuilder().append("wmic /NAMESPACE:\\\\" + namespace + " path ")
            .append(wmiObjName);

    if (filters != null && !filters.isEmpty()) {
        sb.append(" WHERE \"");
        int num = 0;
        for (Entry<String, String> filterEntry : filters.entrySet()) {
            String filterFieldAndVal = filterEntry.getKey();
            String operator = filterEntry.getValue();
            int i = filterFieldAndVal.indexOf("-");
            sb.append(filterFieldAndVal.substring(0, i)).append(" ").append(operator).append(" '")
                    .append(filterFieldAndVal.substring(i + 1, filterFieldAndVal.length())).append("'");
            num++;
            if (num < filters.size()) {
                sb.append(" and ");
            }
        }
        sb.append("\"");
    }

    sb.append(" get");
    if (col != null && !"".equals(col)) {
        sb.append(" " + col);
    }

    sb.append(" /format:textvaluelist.xsl");
    String cmd = sb.toString();
    if (log.isDebugEnabled()) {
        log.debug("cmd=" + cmd);
    }

    BufferedReader input = null;
    try {
        Process process = Runtime.getRuntime().exec(cmd);
        input = new BufferedReader(new InputStreamReader(process.getInputStream()));

        String line;
        Set<String> obj = new HashSet<String>();
        StringTokenizer st;
        while ((line = input.readLine()) != null) {
            line = line.trim();
            st = new StringTokenizer(line, "=");
            while (st.hasMoreElements()) {
                String k = ((String) st.nextElement()).trim();
                String v = ((String) st.nextElement()).trim();
                obj.add(v);
            }
        }
        return obj;
    } catch (IOException e) {
        throw new PluginException(e);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                throw new PluginException(e);
            }
        }
    }
}

From source file:org.commoncrawl.io.NIOHttpHeaders.java

public static NIOHttpHeaders parseHttpHeadersAlternate(String headers) {

    NIOHttpHeaders headersOut = new NIOHttpHeaders();

    if (headers != null && headers.length() != 0) {
        StringTokenizer tokenizer = new StringTokenizer(headers, "\r\n");

        while (tokenizer.hasMoreElements()) {
            String token = tokenizer.nextToken();

            if (token != null && token.length() != 0) {
                int colonPos = token.indexOf(':');

                if (colonPos != -1 && colonPos != token.length() - 1) {

                    String key = token.substring(0, colonPos);
                    String value = token.substring(colonPos + 1);

                    if (key.length() != 0 && value.length() != 0) {
                        headersOut.add(key, value);
                    }//  www.j a v a 2  s  . c  o m
                } else {
                    headersOut.add(null, token);
                }

            }
        }
    }
    return headersOut;
}

From source file:com.silverpeas.util.FileUtil.java

/**
 * Create the array of strings this array represents the repertories where the files must be
 * stored.//from   w w  w . ja v a 2  s  .  c  o m
 *
 * @param context
 * @return
 */
public static String[] getAttachmentContext(final String context) {
    if (!StringUtil.isDefined(context)) {
        return new String[] { BASE_CONTEXT };
    }
    final StringTokenizer strToken = new StringTokenizer(context, CONTEXT_TOKEN);
    final List<String> folders = new ArrayList<String>(10);
    folders.add(BASE_CONTEXT);
    while (strToken.hasMoreElements()) {
        folders.add(strToken.nextToken().trim());
    }
    return folders.toArray(new String[folders.size()]);
}

From source file:org.dozer.util.ReflectionUtils.java

/**
 * Find a method with concrete string representation of it's parameters
 * @param clazz clazz to search/*from   w  ww  .  j  a v  a2  s .c o m*/
 * @param methodName name of method with representation of it's parameters
 * @return found method
 * @throws NoSuchMethodException
 */
public static Method findAMethod(Class<?> clazz, String methodName) throws NoSuchMethodException {
    StringTokenizer tokenizer = new StringTokenizer(methodName, "(");
    String m = tokenizer.nextToken();
    Method result;
    // If tokenizer has more elements, it mean that parameters may have been specified
    if (tokenizer.hasMoreElements()) {
        StringTokenizer tokens = new StringTokenizer(tokenizer.nextToken(), ")");
        String params = (tokens.hasMoreTokens() ? tokens.nextToken() : null);
        result = findMethodWithParam(clazz, m, params);
    } else {
        result = findMethod(clazz, methodName);
    }
    if (result == null) {
        throw new NoSuchMethodException(clazz.getName() + "." + methodName);
    }
    return result;
}

From source file:com.amalto.core.history.accessor.record.DataRecordAccessor.java

@SuppressWarnings("rawtypes")
private static LinkedList<PathElement> getPath(DataRecord dataRecord, String path) {
    LinkedList<PathElement> elements = new LinkedList<PathElement>();
    StringTokenizer tokenizer = new StringTokenizer(path, "/"); //$NON-NLS-1$
    DataRecord current = dataRecord;/* w w  w .  ja  v a  2s  . com*/
    while (tokenizer.hasMoreElements()) {
        String element = tokenizer.nextToken();
        PathElement pathElement = new PathElement();
        if (element.indexOf('@') == 0) {
            pathElement.field = elements.getLast().field;
            pathElement.setter = TypeValue.SET;
            pathElement.getter = TypeValue.GET;
        } else {
            if (current == null) {
                throw new IllegalStateException("Cannot update '" + path + "'."); //$NON-NLS-1$ //$NON-NLS-2$
            }
            if (element.indexOf('[') > 0) {
                pathElement.field = current.getType().getField(StringUtils.substringBefore(element, "[")); //$NON-NLS-1$
                if (!pathElement.field.isMany()) {
                    throw new IllegalStateException(
                            "Expected a repeatable field for '" + element + "' in path '" + path //$NON-NLS-1$ //$NON-NLS-2$
                                    + "'."); //$NON-NLS-1$
                }
                int indexStart = element.indexOf('[');
                int indexEnd = element.indexOf(']');
                if (indexStart < 0 || indexEnd < 0) {
                    throw new RuntimeException(
                            "Field name '" + element + "' did not match many field pattern in path '" //$NON-NLS-1$ //$NON-NLS-2$
                                    + path + "'."); //$NON-NLS-1$
                }
                pathElement.index = Integer.parseInt(element.substring(indexStart + 1, indexEnd)) - 1;
                pathElement.setter = ManyValue.SET;
                pathElement.getter = ManyValue.GET;
                List list = (List) current.get(pathElement.field);
                if (list == null || pathElement.index > list.size() - 1) {
                    throw new IllegalStateException("Cannot update '" + path + "'."); //$NON-NLS-1$ //$NON-NLS-2$
                }
                Object value = list.get(pathElement.index);
                if (value instanceof DataRecord) {
                    current = (DataRecord) value;
                } else if (value instanceof List) {
                    throw new IllegalStateException();
                }
            } else {
                pathElement.field = current.getType().getField(element);
                pathElement.setter = SimpleValue.SET;
                pathElement.getter = SimpleValue.GET;
                if (pathElement.field instanceof ContainedTypeFieldMetadata
                        || pathElement.field instanceof ReferenceFieldMetadata) {
                    Object value = current.get(pathElement.field);
                    if (value instanceof DataRecord) {
                        current = (DataRecord) value;
                    }
                }
            }
        }
        elements.add(pathElement);
    }
    return elements;
}

From source file:org.apache.geode.management.internal.configuration.utils.XmlUtils.java

/**
 * Build schema location map of schemas used in given <code>schemaLocationAttribute</code>.
 * //  ww w .  j a va2s .  c  om
 * @see <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">XML Schema Part 0: Primer
 *      Second Edition | 5.6 schemaLocation</a>
 * 
 * @param schemaLocation attribute value to build schema location map from.
 * @return {@link Map} of schema namespace URIs to location URLs.
 * @since GemFire 8.1
 */
public static Map<String, String> buildSchemaLocationMap(final String schemaLocation) {
    Map<String, String> schemaLocationMap = new HashMap<>();
    if (StringUtils.isBlank(schemaLocation)) {
        return schemaLocationMap;
    }

    final StringTokenizer st = new StringTokenizer(schemaLocation, " \n\t\r");
    while (st.hasMoreElements()) {
        final String ns = st.nextToken();
        final String loc = st.nextToken();
        schemaLocationMap.put(ns, loc);
    }

    return schemaLocationMap;
}