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:com.qframework.core.ServerkoParse.java

public static int[] parseColorVector(String data) {
    int val = 0;
    StringTokenizer tok = new StringTokenizer(data, ",");
    int len = tok.countTokens();
    int[] array = new int[len];
    int count = 0;

    while (tok.hasMoreTokens())
        try {//from   www  . ja  v  a2s . com
            val = ColorFactory.getColorVal(tok.nextToken());
            array[count++] = val;
        } catch (NoSuchElementException e) {
        }

    return array;
}

From source file:com.salesmanager.core.util.FileUtil.java

/**
 * Decrypt and parses file token//from w w  w.jav a 2  s .c  o  m
 * 
 * @param tokens
 * @return
 * @throws Exception
 */
public static Map<String, String> getFileDownloadFileTokens(String token) throws Exception {

    String decrypted = EncryptionUtil.decrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant), token);

    StringTokenizer st = new StringTokenizer(decrypted, "|");
    String downloadId = "";
    String date = "";
    String merchantId = "";

    int i = 0;
    while (st.hasMoreTokens()) {
        String t = st.nextToken();
        if (i == 0) {
            downloadId = t;
        } else if (i == 1) {
            date = t;
        } else if (i == 2) {
            merchantId = t;
        } else {
            break;
        }
        i++;
    }

    if (StringUtils.isBlank(downloadId) || StringUtils.isBlank(date) || StringUtils.isBlank(merchantId)) {
        throw new Exception("Invalid URL parameters for FileUtil.getFileDownloadFileTokens " + token);
    }

    Map response = new HashMap();
    response.put("ID", downloadId);
    response.put("DATE", date);
    response.put("MERCHANTID", merchantId);

    return response;

}

From source file:com.omertron.thetvdbapi.tools.TvdbParser.java

/**
 * Create a List from a delimited string
 *
 * @param input//from www .  j  a v a 2s.c om
 * @param delim
 */
private static List<String> parseList(String input, String delim) {
    List<String> result = new ArrayList<String>();

    StringTokenizer st = new StringTokenizer(input, delim);
    while (st.hasMoreTokens()) {
        String token = st.nextToken().trim();
        if (token.length() > 0) {
            result.add(token);
        }
    }

    return result;
}

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

public static int[] parseIntVector(String data) {
    int val = 0;
    StringTokenizer tok = new StringTokenizer(data, ",");
    int len = tok.countTokens();
    int[] array = new int[len];
    int count = 0;

    while (tok.hasMoreTokens())
        try {/* w  w  w.  j a  va2s.  c o m*/
            try {
                val = Integer.parseInt(tok.nextToken());
            } catch (NumberFormatException e) {
            }
            array[count++] = val;
        } catch (NoSuchElementException e) {
        }

    return array;
}

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

public static float[] parseFloatVector(String data) {
    float val = 0;
    StringTokenizer tok = new StringTokenizer(data, ",");
    int len = tok.countTokens();
    float[] array = new float[len];
    int count = 0;
    while (tok.hasMoreTokens())
        try {/*from w  ww . j  a  va2s  .c  o  m*/
            try {
                val = Float.parseFloat(tok.nextToken());
            } catch (NumberFormatException e) {
            }
            array[count++] = val;
        } catch (NoSuchElementException e) {
        }

    return array;
}

From source file:com.alkacon.opencms.documentcenter.NewDocumentsTree.java

/**
 * Builds a list of the categories which were selected in the form.<p>
 * //from ww w  . j av  a  2s  . c o  m
 * @param allCategories String with all selected category paths
 * @return List with all selected categories (holds String objects with absolute paths)
 */
public static List getCategoryList(String allCategories) {

    ArrayList categories = new ArrayList();

    // get the indiviadual category paths from the token
    StringTokenizer T = new StringTokenizer(allCategories, CategoryTree.C_LIST_SEPARATOR);
    while (T.hasMoreTokens()) {
        String curToken = T.nextToken();
        if (!"".equals(curToken.trim())) {
            // add the category to the list
            categories.add(curToken);
        }
    }
    return categories;
}

From source file:com.alkacon.opencms.v8.documentcenter.NewDocumentsTree.java

/**
 * Builds a list of the categories which were selected in the form.<p>
 * //from  w w  w . ja v a  2s .  c o m
 * @param allCategories String with all selected category paths
 * @return List with all selected categories (holds String objects with absolute paths)
 */
public static List<String> getCategoryList(String allCategories) {

    ArrayList<String> categories = new ArrayList<String>();

    // get the indiviadual category paths from the token
    StringTokenizer T = new StringTokenizer(allCategories, CategoryTree.C_LIST_SEPARATOR);
    while (T.hasMoreTokens()) {
        String curToken = T.nextToken();
        if (!"".equals(curToken.trim())) {
            // add the category to the list
            categories.add(curToken);
        }
    }
    return categories;
}

From source file:com.trackplus.ddl.DataWriter.java

private static void insertBlobData(Connection con, String line) throws DDLException {
    String sql = "INSERT INTO TBLOB(OBJECTID, BLOBVALUE, TPUUID) VALUES(?,?,?)";
    StringTokenizer st = new StringTokenizer(line, ",");
    Integer objectID = Integer.valueOf(st.nextToken());
    String base64Str = st.nextToken();
    byte[] bytes = Base64.decodeBase64(base64Str);
    String tpuid = null;// w  w w  .  jav  a 2  s  .  c om
    if (st.hasMoreTokens()) {
        tpuid = st.nextToken();
    }

    try {
        PreparedStatement preparedStatement = con.prepareStatement(sql);
        preparedStatement.setInt(1, objectID);
        preparedStatement.setBinaryStream(2, new ByteArrayInputStream(bytes), bytes.length);
        preparedStatement.setString(3, tpuid);
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        throw new DDLException(e.getMessage(), e);
    }
}

From source file:com.qtplaf.library.util.StringUtils.java

/**
 * Parse a comma separated list of strings "S1, S2, S3".
 *
 * @param string The string to be tokenized.
 * @return the array of tokens.//w  w  w.j a  v  a 2  s  .co  m
 */
public static String[] parseCommaSeparatedStrings(String string) {
    StringTokenizer tokenizer = new StringTokenizer(string, ",");
    ArrayList<String> list = new ArrayList<>();
    while (tokenizer.hasMoreTokens()) {
        list.add(tokenizer.nextToken().trim());
    }
    return list.toArray(new String[list.size()]);
}

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

/**
 * Permite obtener la ruta relativa de un fichero a partir de su ruta
 * absoluta.//w w w .  j  a va  2 s . c o  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.
    }

}