List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:Main.java
public static List<String> parseTokenList(String tokenList) { List<String> result = new ArrayList<>(); StringTokenizer tokenizer = new StringTokenizer(tokenList, " "); while (tokenizer.hasMoreTokens()) { result.add(tokenizer.nextToken()); }/*ww w . j av a 2 s. co m*/ return result; }
From source file:Main.java
/** * get the name of an XML element, with the namespace prefix stripped off * @param el/*w ww .j ava 2s. co m*/ * @return */ public static String getLocalName(Node el) { String locName = ""; StringTokenizer st = new StringTokenizer(el.getNodeName(), ":"); while (st.hasMoreTokens()) locName = st.nextToken(); return locName; }
From source file:Main.java
public static String parseValue(Map<String, List<String>> responseHeader, String parentKey, String valueKey) { List<String> contentTypes = responseHeader.get(parentKey); if (contentTypes != null && contentTypes.size() > 0) { String contentType = contentTypes.get(0); StringTokenizer stringTokenizer = new StringTokenizer(contentType, ";"); while (stringTokenizer.hasMoreTokens()) { String token = stringTokenizer.nextToken(); if (token.contains(valueKey)) { String[] values = token.split("="); if (values.length > 1) { return values[1]; }/* w w w . ja va 2s . c om*/ } } } return null; }
From source file:Main.java
/** * Creates a list of integers from a string within tokens. Empty tokens will * be omitted: If a string within tokens is <code>"1,,2,,3"</code> and the * delimiter string is <code>","</code>, the returned list of integers * contains the tree elements <code>1, 2, 3</code>. * * <em>It is expected, that each token can be parsed as an integer or is * empty!</em>/* w ww . j av a 2 s.c o m*/ * * @param string String within tokens parsable as integer * @param delimiter Delimiter between the integer tokens. Every character * of the delimiter string is a separate delimiter. If * the string within tokens is <code>"1,2:3"</code> * and the delimiter string is <code>",:"</code>, the * returned list of integers contains the three elements * <code>1, 2, 3</code>. * @return list of integers * @throws NumberFormatException if the string contains a not empty * token that can't parsed as an integer */ public static List<Integer> integerTokenToList(String string, String delimiter) { if (string == null) { throw new NullPointerException("string == null"); } if (delimiter == null) { throw new NullPointerException("delimiter == null"); } List<Integer> integerList = new ArrayList<>(); StringTokenizer tokenizer = new StringTokenizer(string, delimiter); while (tokenizer.hasMoreTokens()) { integerList.add(Integer.parseInt(tokenizer.nextToken())); } return integerList; }
From source file:TokenizerUtil.java
public static String[] convertCSVStringToArray(String s) { ArrayList<String> list = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(s, "|"); while (st.hasMoreTokens()) { String token = st.nextToken(); list.add(token);/* w ww. j a va2 s .c o m*/ } return (String[]) list.toArray(new String[list.size()]); }
From source file:Main.java
/** * Remove leading a trailing whitespace characters from each line of input * @param input//from w w w. j a v a 2 s .c o m * @return */ public static String trim(String input) { final String newlineDelimiters = "\n\r\f"; //$NON-NLS-1$ StringBuilder ret = new StringBuilder(); StringTokenizer st = new StringTokenizer(input, newlineDelimiters); while (st.hasMoreTokens()) { ret.append(st.nextToken().replaceAll("^\\s+", "").replaceAll("\\s+$", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ ret.append("\n"); //$NON-NLS-1$ } return ret.toString(); }
From source file:TokenizerUtil.java
public static Map<String, String> convertCSVStringToMap(String s) { TreeMap<String, String> map = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(s, "|"); while (st.hasMoreTokens()) { String keyToken = st.nextToken(); String valueToken = st.nextToken(); map.put(keyToken, valueToken);// w ww . j a va 2 s.c om } return map; }
From source file:Main.java
public static String quote(String value) { if (value != null) { if (value.contains("'")) { if (value.contains("\"")) { // We've got something perverse like [["It's back!"]] (ie a mix of single and double quotes!) StringBuilder sb = new StringBuilder("concat("); StringTokenizer st = new StringTokenizer(value, "'\"", true); while (st.hasMoreTokens()) { sb.append(quote(st.nextToken())); if (st.hasMoreTokens()) { sb.append(", "); }/*from w ww .j a v a 2 s . co m*/ } sb.append(")"); return sb.toString(); } else { return '"' + value + '"'; } } else { return "'" + value + "'"; } } return value; }
From source file:Main.java
public static Node createNodeFromPath(Element modelElement, String path) { Document document = modelElement.getOwnerDocument(); StringTokenizer st = new StringTokenizer(path, "/"); while (st.hasMoreTokens()) { String t = st.nextToken(); if (st.hasMoreTokens()) { if (t.equals("..")) { modelElement = (Element) modelElement.getParentNode(); } else { Element elm = getFirstChildElement(modelElement, t); if (elm == null) modelElement = (Element) modelElement.insertBefore(document.createElement(t), getFirstChildElement(modelElement, t)); else modelElement = elm;// w ww. j a va 2 s. c o m } } else { modelElement = (Element) modelElement.insertBefore(document.createElement(t), getFirstChildElement(modelElement, t)); } } return modelElement; }
From source file:Main.java
public static String[] toStringArray(String s) { StringTokenizer st = new StringTokenizer(s); String[] array = new String[st.countTokens()]; for (int i = 0; st.hasMoreTokens(); i++) array[i] = st.nextToken();/*w w w. j a v a 2 s . c o m*/ return array; }