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:Main.java

public static ArrayList<String> getInput() {
    ArrayList<String> result = new ArrayList<String>(10);
    String line;//from w  w  w.  ja v  a  2  s.c o  m
    try {
        line = new BufferedReader(new InputStreamReader(System.in)).readLine();
        if (line != null) {
            StringTokenizer st = new StringTokenizer(line);
            while (st.hasMoreTokens())
                result.add(st.nextToken());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

/**
 * Remove leading a trailing whitespace characters from each line of input
 * @param input//w  w w.j a  v  a2 s. co m
 * @return
 */
public static String trim(String input) {
    final String newlineDelimiters = "\n\r\f";

    StringBuilder ret = new StringBuilder();
    StringTokenizer st = new StringTokenizer(input, newlineDelimiters);
    while (st.hasMoreTokens()) {
        ret.append(st.nextToken().replaceAll("^\\s+", "").replaceAll("\\s+$", ""));
        ret.append('\n');
    }
    return ret.toString();
}

From source file:Main.java

private static List<String> stringToArray(String str) {
    try {/*from   w  w w  .  j  av  a 2s  .c  om*/
        List<String> arg = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(str, ",");
        while (st.hasMoreTokens()) {
            arg.add(st.nextToken());
        }
        return arg;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

/**
 * Loads the given expansion state of a JTree, making it expand in the given manner.
 * //from  w  ww.j a  v a 2 s. c o  m
 * @param tree
 *            The JTree to be expended
 * @param enumeration
 *            The expansion state for tree as Enumeration<TreePath>
 */
public static void loadTreeExpansionState(JTree tree, String expansionState, int row) {
    // if a tree is opened for the first time, its expansionState is null
    if (expansionState == null) {
        return;
    }

    StringTokenizer stok = new StringTokenizer(expansionState, ",");
    while (stok.hasMoreTokens()) {
        int token = row + Integer.parseInt(stok.nextToken());
        tree.expandRow(token);
    }
}

From source file:Main.java

public static boolean valiChar(String string) {
    StringTokenizer s = new StringTokenizer(string, ",");
    //      int num=0;
    if (s.hasMoreTokens()) {
        String str = s.nextToken();
        byte[] cc = str.getBytes();
        int a = (int) cc[0];
        if (a < 32 || a > 127) {
            return false;
        }//from   ww w  .  ja va 2  s.c  om
    }
    return true;
}

From source file:Main.java

/**
 * suppose the component path is "a.b.c", get 'a' as object name.
 * /*from   ww w.  j a  v a  2 s. c o m*/
 * @param componentPath
 * @return
 */
public static String getObjectNameOfComponentPath(String componentPath) {
    String objectName = componentPath;
    StringTokenizer tokens = new StringTokenizer(componentPath, ".");
    objectName = tokens.hasMoreTokens() ? tokens.nextToken() : objectName;
    return objectName;
}

From source file:Main.java

private static String[] tokenize(String str) {
    StringTokenizer tokenizer = new StringTokenizer(str);
    String[] arr = new String[tokenizer.countTokens()];
    int i = 0;/*from   w  w w  .  j  a va  2s .co  m*/
    while (tokenizer.hasMoreTokens()) {
        arr[i++] = tokenizer.nextToken();
    }
    return arr;
}

From source file:Main.java

public static List<String> parseStringList(String l, String separator) {
    List<String> tmp = new LinkedList<String>();
    StringTokenizer tok = new StringTokenizer(l, separator);
    String t;/*w  w w  . jav  a 2s.  c o  m*/

    while (tok.hasMoreTokens()) {
        t = tok.nextToken();
        tmp.add(t.trim());
    }

    return tmp;
}

From source file:Main.java

public static String normalizeSpace(String str) {
    if (!isNullOrEmpty(str)) {
        StringTokenizer st = new StringTokenizer(str);
        if (st.hasMoreTokens()) {

            StringBuffer sb = new StringBuffer(str.length());
            while (true) {
                sb.append(st.nextToken());
                if (st.hasMoreTokens()) {
                    sb.append(' ');
                } else {
                    break;
                }/*from w w w .  j  ava  2s.  c om*/
            }
            return sb.toString();
        } else {
            return "";
        }
    } else {
        return str;
    }
}

From source file:Main.java

public static List<String> parseTokenList(String tokenList) {
    List<String> result = new ArrayList<String>();
    StringTokenizer tokenizer = new StringTokenizer(tokenList, " ");
    while (tokenizer.hasMoreTokens()) {
        result.add(tokenizer.nextToken());
    }//from  ww  w  .  j a v  a  2 s  . co m
    return result;
}