List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:Main.java
public static Locale getLocale(String locale) { if (locale == null) return Locale.getDefault(); StringTokenizer localeTokenizer = new StringTokenizer(locale, "_"); if (localeTokenizer.countTokens() == 1) { return new Locale(locale); } else {/*w w w .j av a 2s .c om*/ return new Locale(localeTokenizer.nextToken(), localeTokenizer.nextToken()); } }
From source file:Main.java
/** * utility method to get the last token in a "."-delimited package+classname string * * @return/* w w w .ja v a 2 s .c o m*/ */ private static String getSimpleName(String in) { if (in == null || in.length() == 0) { return in; } String out = null; StringTokenizer tokenizer = new StringTokenizer(in, "."); if (tokenizer.countTokens() == 0) out = in; else { while (tokenizer.hasMoreTokens()) { out = tokenizer.nextToken(); } } return out; }
From source file:Main.java
public static String getThreadName(Thread thr) { if (thr == null) return "null"; // This depends on the formatting in SelectReaderThread and CorbaConnectionImpl. // Pattern for SelectReaderThreads: // SelectReaderThread CorbaConnectionImpl[ <host> <post> <state>] // Any other pattern in the Thread's name is just returned. String name = thr.getName();//from w w w .ja va 2s. c o m StringTokenizer st = new StringTokenizer(name); int numTokens = st.countTokens(); if (numTokens != 5) return name; String[] tokens = new String[numTokens]; for (int ctr = 0; ctr < numTokens; ctr++) tokens[ctr] = st.nextToken(); if (!tokens[0].equals("SelectReaderThread")) return name; return "SelectReaderThread[" + tokens[2] + ":" + tokens[3] + "]"; }
From source file:Main.java
public static QName getNamespace(Map<String, String> namespaces, String str, String defaultNamespace) { String prefix = null;/*from w w w .j a v a 2 s . c om*/ String localName = null; StringTokenizer tokenizer = new StringTokenizer(str, ":"); if (tokenizer.countTokens() == 2) { prefix = tokenizer.nextToken(); localName = tokenizer.nextToken(); } else if (tokenizer.countTokens() == 1) { localName = tokenizer.nextToken(); } String namespceURI = defaultNamespace; if (prefix != null) { namespceURI = namespaces.get(prefix); } return new QName(namespceURI, localName); }
From source file:Main.java
public static String[] split(final String string, final String tag) { StringTokenizer str = new StringTokenizer(string, tag); String[] result = new String[str.countTokens()]; int index = 0; for (; str.hasMoreTokens();) { result[index++] = str.nextToken(); }/*w ww. ja v a 2 s . c om*/ return result; }
From source file:Main.java
public static int[] decodeMultiIntegerField(String field) throws NumberFormatException { StringTokenizer fieldTokens = new StringTokenizer(field, ";"); int[] result = new int[fieldTokens.countTokens()]; int counter = 0; while (fieldTokens.hasMoreTokens()) { String fieldToken = fieldTokens.nextToken(); result[counter++] = Integer.valueOf(fieldToken); }/*from w w w .j av a2 s .c o m*/ return result; }
From source file:Main.java
private static String[] split(String s, String delim, boolean includeDelim) { StringTokenizer tok = new StringTokenizer(s, delim, includeDelim); String[] parts = new String[tok.countTokens()]; for (int i = 0; tok.hasMoreTokens(); i++) { parts[i] = tok.nextToken();// w ww. ja va 2 s. c o m } return parts; }
From source file:Main.java
/** * Splits specified string at XML space character boundaries (<tt>'\t'</tt>, * <tt>'\r'</tt>, <tt>'\n'</tt>, <tt>' '</tt>). Returns list of * parts./* ww w .j a v a 2 s.co m*/ * * @param s string to be split * @return list of parts */ public static final String[] splitList(String s) { StringTokenizer tokens = new StringTokenizer(s, " \n\r\t"); String[] split = new String[tokens.countTokens()]; for (int i = 0; i < split.length; ++i) split[i] = tokens.nextToken(); return split; }
From source file:Util.java
/** * Split "str" into tokens by delimiters and optionally remove white spaces * from the splitted tokens./*from ww w . java 2 s . co m*/ * * @param trimTokens if true, then trim the tokens */ public static String[] split(String str, String delims, boolean trimTokens) { StringTokenizer tokenizer = new StringTokenizer(str, delims); int n = tokenizer.countTokens(); String[] list = new String[n]; for (int i = 0; i < n; i++) { if (trimTokens) { list[i] = tokenizer.nextToken().trim(); } else { list[i] = tokenizer.nextToken(); } } return list; }
From source file:Main.java
public static String restoreWithEndnote(String text, String holderString, String replacement, String noteTag, String noteSplit) {//from w w w .jav a 2s . c om int start = text.lastIndexOf(noteTag); String note = text.substring(start); text = text.substring(0, start); if (note.length() == noteTag.length()) return text; StringBuilder sb = new StringBuilder(text); StringTokenizer token = new StringTokenizer(note.substring(1), noteSplit); int[] index = new int[token.countTokens()]; for (int i = index.length - 1; i >= 0; i--) { index[i] = Integer.parseInt(token.nextToken()); } int h_length = holderString.length(); for (int i = 0; i < index.length; i++) { sb.replace(index[i], index[i] + h_length, replacement); } return sb.toString(); }