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:deprecate.compare.TokenizerJava_old.java

/**
 * Convert the tokens stored on disk onto a token source object
 * @param   tokenCode line from disk//from  w w w .  j a  v  a  2 s  . co  m
 * @return  the tokenSource object or null if some problem occurred    
 */
public static TokenSource decompress(final String tokenCode) {
    TokenizerJava_old tokens = new TokenizerJava_old();
    TokenSource result = new TokenSource();
    // split each method according to tabs
    //String[] methodTexts = tokenCode.split("\t");
    StringTokenizer stringTokenizer = new StringTokenizer(tokenCode, TokenSource.separatorMethod);

    // iterate and create the token methods
    //for(String methodText : methodTexts){
    while (stringTokenizer.hasMoreTokens()) {
        // create the token method
        SourceCodeSnippet method = new SourceCodeSnippet();
        final String line = stringTokenizer.nextElement().toString();
        int i1 = line.indexOf(TokenSource.separatorData);
        // feed the token data
        method.setTokens(line.substring(i1 + 1));

        // split the lines data in two lines
        final String lineData = line.substring(0, i1);
        final String[] lines = lineData.split("\\.\\.");
        // set the method lines
        method.setLineStart(Integer.parseInt(lines[0]));
        method.setLineEnd(Integer.parseInt(lines[1]));

        // add it to the result
        result.add(method);
    }
    // all done
    return result;
}

From source file:eionet.cr.util.URLUtil.java

/**
 *
 * @param str/*from   ww w  . j av  a 2  s .co m*/
 * @param exceptions
 * @return
 * @throws UnsupportedEncodingException
 */
private static String decodeEncode(String str, String exceptions) throws UnsupportedEncodingException {

    if (StringUtils.isEmpty(str)) {
        return str;
    } else if (StringUtils.isEmpty(exceptions)) {
        return decodeEncode(str);
    }

    StringBuilder result = new StringBuilder();
    StringTokenizer tokenizer = new StringTokenizer(str, exceptions, true);
    while (tokenizer.hasMoreTokens()) {

        String token = tokenizer.nextToken();
        if (!token.isEmpty() && exceptions.contains(token)) {
            result.append(token);
        } else {
            result.append(decodeEncode(token));
        }
    }

    return result.toString();
}

From source file:com.github.dozermapper.core.util.ReflectionUtils.java

private static Method findMethodWithParam(Class<?> parentDestClass, String methodName, String params,
        BeanContainer beanContainer) throws NoSuchMethodException {
    List<Class<?>> list = new ArrayList<>();
    if (params != null) {
        StringTokenizer tokenizer = new StringTokenizer(params, ",");
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            list.add(MappingUtils.loadClass(token, beanContainer));
        }/*w ww. jav a  2s  .  c  om*/
    }
    return getMethod(parentDestClass, methodName, list.toArray(new Class[list.size()]));
}

From source file:com.icesoft.faces.component.ext.taglib.Util.java

/**
 * Gets the comma separated list of visibility 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  ww. j a  v a  2s.c o m
public static boolean isRenderedOnUserRole(UIComponent component) {
    if (ignoreUserRoleAttributes()) {
        return true;
    }
    String userRole;
    if (component instanceof IceExtended) {
        userRole = ((IceExtended) component).getRenderedOnUserRole();
    } else {
        userRole = (String) component.getAttributes().get(IceExtended.RENDERED_ON_USER_ROLE_ATTR);
    }

    if (log.isTraceEnabled()) {
        log.trace("userRole in " + getRoot(component) + " is " + userRole);

    }

    //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 parseFloatData(Vector<float[]> outdata, String data, int[] offsets) {

    float val = 0;
    int arrcount = 0;
    int offsetcount = 0;
    float[] array = null;
    int currsize = 0;
    StringTokenizer tok = new StringTokenizer(data, ",");
    while (tok.hasMoreTokens()) {
        if (arrcount == 0) {
            currsize = offsets[offsetcount++];
            offsetcount = offsetcount % offsets.length;
            array = new float[currsize];
        }/*from   w  w  w. j  av a2 s .c om*/
        try {
            val = Float.parseFloat(tok.nextToken());
        } catch (NumberFormatException e) {
        }
        array[arrcount++] = val;
        if (arrcount >= currsize) {
            outdata.add(array);
            arrcount = 0;
        }
    }
    return outdata.size();
}

From source file:com.qframework.core.ServerkoParse.java

public static int parseIntData(Vector<int[]> outdata, String data, int[] offsets) {

    int val = 0;
    int arrcount = 0;
    int offsetcount = 0;
    int[] array = null;
    int currsize = 0;
    StringTokenizer tok = new StringTokenizer(data, ",");
    while (tok.hasMoreTokens()) {
        if (arrcount == 0) {
            currsize = offsets[offsetcount++];
            offsetcount = offsetcount % offsets.length;
            array = new int[currsize];
        }//from  w ww .j av a2  s.c o m
        try {
            val = Integer.parseInt(tok.nextToken());
        } catch (NumberFormatException e) {
        }
        array[arrcount++] = val;
        if (arrcount >= currsize) {
            outdata.add(array);
            arrcount = 0;
        }
    }
    return outdata.size();
}

From source file:net.sf.excelutils.ExcelParser.java

/**
 * get a instance by the tag name./*from   w ww .j  a v  a  2s.com*/
 * 
 * @param str tag name
 * @return ITag instance
 */
public static ITag getTagClass(String str) {
    String tagName = "";
    int keytag = str.indexOf(KEY_TAG);
    if (keytag < 0)
        return null;
    if (!(keytag < str.length() - 1))
        return null;
    String tagRight = str.substring(keytag + 1, str.length());
    if (tagRight.startsWith(KEY_TAG) || "".equals(tagRight.trim()))
        return null;

    str = str.substring(str.indexOf(KEY_TAG) + KEY_TAG.length(), str.length());
    StringTokenizer st = new StringTokenizer(str, " ");
    if (st.hasMoreTokens()) {
        tagName = st.nextToken();
    }
    tagName = tagName.substring(0, 1).toUpperCase() + tagName.substring(1, tagName.length());
    tagName += "Tag";

    // find in tagMap first, if not exist, search in the package
    ITag tag = (ITag) tagMap.get(tagName);
    if (tag == null) {
        Iterator tagPackages = tagPackageMap.values().iterator();
        // seach the tag class
        while (tagPackages.hasNext() && null == tag) {
            String packageName = (String) tagPackages.next();
            try {
                Class clazz = Class.forName(packageName + "." + tagName);
                tag = (ITag) clazz.newInstance();
            } catch (Exception e) {
                tag = null;
            }
        }
        if (tag != null) {
            // find it, cache it
            tagMap.put(tagName, tag);
        }
    }
    return tag;
}

From source file:org.bedework.timezones.server.MethodBase.java

/** Return a path, beginning with a "/", after "." and ".." are removed.
 * If the parameter path attempts to go above the root we return null.
 *
 * Other than the backslash thing why not use URI?
 *
 * @param path      String path to be fixed
 * @return String   fixed path/* www  .java 2 s.c o m*/
 * @throws ServletException
 */
public static ResourceUri fixPath(final String path) throws ServletException {
    if (path == null) {
        return new ResourceUri();
    }

    String decoded;
    try {
        decoded = URLDecoder.decode(path, "UTF8");
    } catch (final Throwable t) {
        throw new ServletException("bad path: " + path);
    }

    if (decoded == null) {
        return new ResourceUri();
    }

    /** Make any backslashes into forward slashes.
     */
    if (decoded.indexOf('\\') >= 0) {
        decoded = decoded.replace('\\', '/');
    }

    /** Ensure a leading '/'
     */
    if (!decoded.startsWith("/")) {
        decoded = "/" + decoded;
    }

    /** Remove all instances of '//'.
     */
    while (decoded.contains("//")) {
        decoded = decoded.replaceAll("//", "/");
    }
    /** Somewhere we may have /./ or /../
     */

    final StringTokenizer st = new StringTokenizer(decoded, "/");

    final ArrayList<String> al = new ArrayList<>();
    while (st.hasMoreTokens()) {
        final String s = st.nextToken();

        if (s.equals(".")) {
            // ignore
            continue;
        }

        if (s.equals("..")) {
            // Back up 1
            if (al.size() == 0) {
                // back too far
                return new ResourceUri();
            }

            al.remove(al.size() - 1);
            continue;
        }

        al.add(s);
    }

    final ResourceUri ruri = new ResourceUri();

    /** Reconstruct */
    for (final String s : al) {
        ruri.addPathElement(s);
    }

    return ruri;
}

From source file:com.jims.oauth2.common.utils.OAuthUtils.java

public static boolean hasContentType(String requestContentType, String requiredContentType) {
    if (OAuthUtils.isEmpty(requiredContentType) || OAuthUtils.isEmpty(requestContentType)) {
        return false;
    }/*from   w ww.j  av  a 2s  . co  m*/
    StringTokenizer tokenizer = new StringTokenizer(requestContentType, ";");
    while (tokenizer.hasMoreTokens()) {
        if (requiredContentType.equals(tokenizer.nextToken())) {
            return true;
        }
    }

    return false;
}

From source file:com.moviejukebox.tools.StringTools.java

public static String[] tokenizeToArray(String sourceString, String delimiter) {
    StringTokenizer st = new StringTokenizer(sourceString, delimiter);
    Collection<String> keywords = new ArrayList<>();
    while (st.hasMoreTokens()) {
        keywords.add(st.nextToken());/*from www .j a v a  2  s .  com*/
    }
    return keywords.toArray(new String[keywords.size()]);
}