List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
From source file:Main.java
public static String[] split(String str, String delimiters) { final StringTokenizer st = new StringTokenizer(str, delimiters); final List<String> tokens = new ArrayList<String>(); while (st.hasMoreTokens()) { final String token = st.nextToken(); tokens.add(token);/*from ww w .j a va2 s .c o m*/ } return tokens.toArray(new String[tokens.size()]); }
From source file:Main.java
public static Color convertHexStringToColor(String str) throws NumberFormatException { int multiplier = 1; StringTokenizer tokenizer = new StringTokenizer(str, " \t\r\n\b:;[]()+"); while (tokenizer.hasMoreTokens()) { multiplier = 1;// w w w .j a v a 2s. com String token = tokenizer.nextToken(); if (null == token) { throw new NumberFormatException(str); } if (token.startsWith("-")) { multiplier = -1; token = token.substring(1); } int point_index = token.indexOf("."); if (point_index > 0) { token = token.substring(0, point_index); } else if (point_index == 0) { return new Color(0); } try { if (token.startsWith("0x")) { return new Color(multiplier * Integer.parseInt(token.substring(2), 16)); } else if (token.startsWith("#")) { return new Color(multiplier * Integer.parseInt(token.substring(1), 16)); } else if (token.startsWith("0") && !token.equals("0")) { return new Color(multiplier * Integer.parseInt(token.substring(1), 8)); } else { return new Color(multiplier * Integer.parseInt(token)); } } catch (NumberFormatException e) { continue; } } throw new NumberFormatException(str); }
From source file:Main.java
public static void addDepsFromCSL(Set<String> deps, String dep) { if (dep != null) { StringTokenizer tk = new StringTokenizer(dep, ","); while (tk.hasMoreTokens()) { String d = tk.nextToken().trim(); if (d.length() > 0) { deps.add(d);/*from ww w . j a v a2 s. co m*/ } } } }
From source file:Main.java
private static String[] setPlacesToWatch(String placeWatch) { String[] places = { "" }; if (placeWatch != null && !placeWatch.equals("")) { StringTokenizer tok = new StringTokenizer(placeWatch, ","); List<String> l = new ArrayList<String>(); while (tok.hasMoreElements()) { l.add(tok.nextToken().toString()); }//w w w.j a va 2 s . c o m if (!l.isEmpty()) { //Object[] o = l.toArray(); places = new String[l.size()];// (String[])o; int idx = 0; for (String s : l) { places[idx++] = s; } } } return places; }
From source file:Main.java
public static boolean isInRange(String ip, String[] netInfo) { // Log.d(TAG, "checking if " + ip + " is in range of " + netInfo[0] + // "/"/*from w ww . j ava 2 s. c o m*/ // + netInfo[1]); StringTokenizer maskTokens = new StringTokenizer(netInfo[1], "."); StringTokenizer ipTokens = new StringTokenizer(ip, "."); int ipArray[] = new int[4]; ipArray[0] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); ipArray[1] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); ipArray[2] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); ipArray[3] = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); String networkAddress = ipArray[0] + "." + ipArray[1] + "." + ipArray[2] + "." + ipArray[3]; return netInfo[0].equals(networkAddress); }
From source file:Main.java
/** * remove from a name any characters not allowed in XML tags * (what are they?)/*from ww w . j ava2s .com*/ * @param name * @return */ public static String legalTagName(String name) { String tagName = ""; StringTokenizer st = new StringTokenizer(name, " ,/;'\\"); while (st.hasMoreTokens()) tagName = tagName + st.nextToken(); return tagName; }
From source file:Main.java
public static String decodePath(String path, String delimiter, String characterSet) throws UnsupportedEncodingException { final StringTokenizer tokenizer = new StringTokenizer(path, delimiter); final StringBuilder builder = new StringBuilder(path.length()); while (tokenizer.hasMoreTokens()) { builder.append(URLDecoder.decode(tokenizer.nextToken(), characterSet)); builder.append(delimiter);/*ww w. j ava2 s.c o m*/ } builder.delete(builder.length() - delimiter.length(), builder.length()); return builder.toString(); }
From source file:Main.java
public static String encodePath(String path, String delimiter, String characterSet) throws UnsupportedEncodingException { final StringTokenizer tokenizer = new StringTokenizer(path, delimiter); final StringBuilder builder = new StringBuilder(path.length()); while (tokenizer.hasMoreTokens()) { builder.append(URLEncoder.encode(tokenizer.nextToken(), characterSet)); builder.append(delimiter);//from w w w . j av a2 s . co m } builder.delete(builder.length() - delimiter.length(), builder.length()); return builder.toString(); }
From source file:Main.java
/** * This fucntion parse database id to retrieve UUID, Major and Minor * @param id/* ww w . j av a 2s .c o m*/ * @return */ public static List<String> parseId(String id) { List<String> list = new ArrayList<String>(); StringTokenizer token = new StringTokenizer(id, "."); while (token.hasMoreElements()) { list.add((String) token.nextElement()); } return list; }
From source file:Main.java
/** * Input is "daddy[8880],sindhu[8880],camille[5555]. Return List of * InetSocketAddress// ww w .j a va 2 s . c o m */ public static List<InetSocketAddress> parseCommaDelimitedHosts2(String hosts, int port_range) { StringTokenizer tok = new StringTokenizer(hosts, ","); String t; InetSocketAddress addr; Set<InetSocketAddress> retval = new HashSet<InetSocketAddress>(); while (tok.hasMoreTokens()) { t = tok.nextToken().trim(); String host = t.substring(0, t.indexOf('[')); host = host.trim(); int port = Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']'))); for (int i = port; i < port + port_range; i++) { addr = new InetSocketAddress(host, i); retval.add(addr); } } return new LinkedList<InetSocketAddress>(retval); }