List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
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(); }//from w ww . j a va 2 s.co m return result; }
From source file:Main.java
/** * Remove an element using XPath-quotation expressions. Path must not including * the context element, path elements can be separated by / or ., * and namespace is NOT supported./*w w w . j a va2s . com*/ * @param context Element to start the search from, cannot be null. * @param path XPath-quotation expression, cannot be null. * @return the removed element if there are matches, otherwise * return null. */ public static Element removeElementByPath(Element context, String path) { Element cur = context; StringTokenizer tokens = new StringTokenizer(path, "/"); String name = null; while (tokens.hasMoreTokens()) { name = tokens.nextToken(); cur = getElementByPath(cur, name); if (cur == null) { return null; } } if (name != null) { Element parent = (Element) cur.getParentNode(); return removeChildElement(parent, name); } return null; }
From source file:Util.java
/** Parse comma-separated list of ints and return as array. */ public static int[] splitInts(String str) throws IllegalArgumentException { StringTokenizer tokenizer = new StringTokenizer(str, ","); int n = tokenizer.countTokens(); int[] list = new int[n]; for (int i = 0; i < n; i++) { String token = tokenizer.nextToken(); list[i] = Integer.parseInt(token); }//from w ww. j a v a 2 s .co m return list; }
From source file:Main.java
/** * * @param source/*from w ww . j a va 2s. c o m*/ * ifconfig output * @param device * device of interest * @return */ public static String[] findIPandNetmask(String source, String device) { int deviceIndex = source.indexOf(device); source = source.substring(deviceIndex); int nextLine = source.indexOf("\n"); source = source.substring(nextLine); int startOfIP = source.indexOf(":"); int endOfIP = source.indexOf(" ", startOfIP); String ip = source.substring(startOfIP + 1, endOfIP); int startOfMask = source.indexOf("Mask:"); int endOfMask = source.indexOf("\n", startOfMask); String mask = source.substring(startOfMask + 5, endOfMask); StringTokenizer ipTokens = new StringTokenizer(ip, "."); StringTokenizer maskTokens = new StringTokenizer(mask, "."); int firstOctet = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); int secondOctet = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); int thirdOctet = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); int fourthOctet = Integer.parseInt(ipTokens.nextToken()) & Integer.parseInt(maskTokens.nextToken()); String networkAddress = firstOctet + "." + secondOctet + "." + thirdOctet + "." + fourthOctet; return new String[] { networkAddress, mask }; }
From source file:Util.java
/** Parse comma-separated list of longs and return as array. */ public static long[] splitLongs(String str) throws IllegalArgumentException { StringTokenizer tokenizer = new StringTokenizer(str, ","); int n = tokenizer.countTokens(); long[] list = new long[n]; for (int i = 0; i < n; i++) { String token = tokenizer.nextToken(); list[i] = Long.parseLong(token); }/*from w ww .ja v a 2 s .co m*/ return list; }
From source file:Main.java
public static void dumpParameters(Parameters parameters) { String flattened = parameters.flatten(); StringTokenizer tokenizer = new StringTokenizer(flattened, ";"); Log.d(TAG, "Dump all camera parameters:"); while (tokenizer.hasMoreElements()) { Log.d(TAG, tokenizer.nextToken()); }/* w w w . j av a 2 s. co m*/ }
From source file:kaleidoscope.util.HttpUtils.java
public static Locale getLocale(String acceptLanguage) { Locale locale = null;/*from ww w . j a v a 2s. c o m*/ if (StringUtils.isEmpty(acceptLanguage) != true) { StringTokenizer langToken = new StringTokenizer(acceptLanguage, ",; "); String language = langToken.nextToken().replace('-', '_'); StringTokenizer localeToken = new StringTokenizer(language, "_"); switch (localeToken.countTokens()) { case 1: locale = new Locale(localeToken.nextToken()); break; case 2: locale = new Locale(localeToken.nextToken(), localeToken.nextToken()); break; case 3: locale = new Locale(localeToken.nextToken(), localeToken.nextToken(), localeToken.nextToken()); break; } } if (locale == null) { locale = Locale.getDefault(); } return locale; }
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 ww .j a v a 2 s . co m return result; }
From source file:Main.java
/** * suppose the component path is "a.b.c", get 'a' as object name. * // w w w . j a v a2s . c om * @param componentPath * @return */ public static String getObjectNameOfComponentPath(String componentPath) { String objectName = componentPath; StringTokenizer tokens = new StringTokenizer(componentPath, "."); objectName = tokens.hasMoreTokens() ? tokens.nextToken() : objectName; return objectName; }
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 a v a 2s .c o m return new Locale(localeTokenizer.nextToken(), localeTokenizer.nextToken()); } }