List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
From source file:Main.java
/** * get the name of an XML element, with the namespace prefix stripped off * @param el/*w w w . j a v a 2 s . 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 List<String> parseTokenList(String tokenList) { List<String> result = new ArrayList<String>(); StringTokenizer tokenizer = new StringTokenizer(tokenList, " "); while (tokenizer.hasMoreTokens()) { result.add(tokenizer.nextToken()); }//from www . ja va 2 s.c o m return result; }
From source file:Main.java
/** * Return current IP address as byte array, for V4 that will be 4 bytes for * V6 16./* w w w . j av a 2 s . co m*/ * * @param address * String representation of IP address. Both V4 and V6 type * addresses are accepted. * @return IP Byte array representation of the address. Check Array.length * to get the size of the array. */ public static byte[] parseByteArray(String address) throws IllegalArgumentException { StringTokenizer st; byte[] v; if (address.indexOf('.') != -1) { st = new StringTokenizer(address, "."); v = new byte[4]; } else if (address.indexOf(':') != -1) { st = new StringTokenizer(address, ":"); v = new byte[16]; } else { throw new IllegalArgumentException( "Illegal IP address format. Expected a string in either '.' or ':' notation"); } for (int i = 0; i < v.length; i++) { String t = st.nextToken(); if (t == null && i != v.length) { throw new IllegalArgumentException("Illegal IP address format. String has too few byte elements."); } v[i] = (byte) Integer.parseInt(t); } return (v); }
From source file:Main.java
/** * Returns a Set of String from a formatted string. * The format is /*from w w w . ja v a2 s . co m*/ * <pre> * <value1>,<value2>...,<value3> * </pre> * * @param str Formatted String. * @return a map of String to Set of String */ public static Set<String> parseStringToSet(String str) { Set<String> set = new HashSet<String>(); StringTokenizer st = new StringTokenizer(str, ","); while (st.hasMoreTokens()) { set.add(st.nextToken().trim()); } return set; }
From source file:Main.java
/** * This is basically the inverse of {@link #addAndDeHump(String)}. It will remove the 'replaceThis' parameter and * uppercase the next character afterwards. * * <pre>/*from www . jav a2s .c o m*/ * removeAndHump( "this-is-it", %quot;-" ); * </pre> * * will become 'ThisIsIt'. * * @param data * @param replaceThis * @return */ public static String removeAndHump(String data, String replaceThis) { String temp; StringBuilder out = new StringBuilder(); temp = data; StringTokenizer st = new StringTokenizer(temp, replaceThis); while (st.hasMoreTokens()) { String element = (String) st.nextElement(); out.append(capitalizeFirstLetter(element)); } return out.toString(); }
From source file:edu.indiana.lib.twinpeaks.util.StatusUtils.java
/** * Set up initial status information/* w w w . j a v a 2 s .c om*/ */ public static void initialize(SessionContext sessionContext, String targets) { StringTokenizer parser = new StringTokenizer(targets, " \t,"); ArrayList dbList = new ArrayList(); HashMap targetMap = getNewStatusMap(sessionContext); /* * Establish the DB list and initial (pre-LOGON) status */ while (parser.hasMoreTokens()) { String db = parser.nextToken(); HashMap emptyMap = new HashMap(); /* * Empty status entry */ emptyMap.put("STATUS", "INACTIVE"); emptyMap.put("STATUS_MESSAGE", "<none>"); emptyMap.put("HITS", "0"); emptyMap.put("ESTIMATE", "0"); emptyMap.put("MERGED", "0"); /* * Save */ dbList.add(db); targetMap.put(db, emptyMap); } /* * Search targets, global status */ sessionContext.put("TARGETS", dbList); sessionContext.putInt("active", 0); sessionContext.put("STATUS", "INACTIVE"); sessionContext.put("STATUS_MESSAGE", "<none>"); /* * Initial totals */ sessionContext.putInt("TOTAL_ESTIMATE", 0); sessionContext.putInt("TOTAL_HITS", 0); sessionContext.putInt("maxRecords", 0); /* * Assume this search is synchronous. An OSID that implements an * asynchronous search will need to set the async flags manually after * this code has finished. */ clearAsyncSearch(sessionContext); clearAsyncInit(sessionContext); }
From source file:Main.java
private SortedSet<Integer> getSet(String str) { SortedSet<Integer> result = new TreeSet<Integer>(); StringTokenizer st = new StringTokenizer(str, " "); while (st.hasMoreTokens()) { result.add(Integer.valueOf(st.nextToken())); }/*ww w.j a v a2 s . c o m*/ return result; }
From source file:Main.java
/** * parses comma or space separated list. A null return value means a wildcard. * /*from ww w .j a va2s .c om*/ * @return List of tokens or null if the commaSeparatedListText is null, '*', or empty */ public static List<String> parseCommaSeparatedList(final String commaSeparatedListText) { List<String> entries = null; if (commaSeparatedListText != null && !"*".equals(commaSeparatedListText)) { final StringTokenizer tokenizer = new StringTokenizer(commaSeparatedListText, ", "); while (tokenizer.hasMoreTokens()) { if (entries == null) { entries = new ArrayList<String>(); } entries.add(tokenizer.nextToken()); } } return entries; }
From source file:Main.java
/** * parses comma or space separated list. A null return value means a wildcard. * @return List of tokens or null if the commaSeparatedListText is null, '*', or empty *///from ww w .j a va2 s . c o m public static List<String> parseCommaSeparatedList(String commaSeparatedListText) { List<String> entries = null; if (commaSeparatedListText != null) { if (!"*".equals(commaSeparatedListText)) { StringTokenizer tokenizer = new StringTokenizer(commaSeparatedListText, ", "); while (tokenizer.hasMoreTokens()) { if (entries == null) { entries = new ArrayList<String>(); } entries.add(tokenizer.nextToken()); } } } return entries; }
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>//from ww w . ja v a2 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; }