List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
From source file:Main.java
public static String getConditionOfExpression(String expression) { // pattern for conditions Pattern conditionPattern = Pattern .compile("^([\\w\\W&&[^/\\[\\]]]+)?(\\[[\\w\\W&&[^\\[\\]]]+\\])(/[\\w\\W]+)?$"); Matcher conditionMatcher = conditionPattern.matcher(expression); if (conditionMatcher.find() && (conditionMatcher.group().length() == expression.length())) { StringTokenizer st = new StringTokenizer(expression, "]"); String condition = st.nextToken(); condition = condition.substring(condition.indexOf("[") + 1); return condition; }/*from w w w. j ava 2s.c o m*/ return null; }
From source file:Main.java
private static String getElementInPathAtPosixFromEnd(String path, int posix) { StringTokenizer st = new StringTokenizer(path, "."); int cpt = st.countTokens(); // if (cpt==1) // return root; int i = cpt - posix; for (int j = 0; j < i; j++) { st.nextToken();/* w ww. jav a 2 s .co m*/ } return (String) st.nextToken(); }
From source file:cn.com.sunjiesh.xcutils.common.VersionUtil.java
/** * //from w w w . j a v a2s . co m * @param version1 * @param version2 * @return */ public static int compareVersion(String version1, String version2) { StringTokenizer version1Tokenizer = new StringTokenizer(version1, "."); StringTokenizer version2Tokenizer = new StringTokenizer(version2, "."); if (version1.equals(version2)) { return 0; } else { while (version1Tokenizer.hasMoreTokens() && version2Tokenizer.hasMoreTokens()) { String version1Token = version1Tokenizer.nextToken(); String Version2Token = version2Tokenizer.nextToken(); if (StringUtils.isNotBlank(version1Token)) { version1Token = version1Token.replace("-", ""); } if (StringUtils.isNotBlank(Version2Token)) { Version2Token = Version2Token.replace("-", ""); } if (StringUtils.isNotBlank(version1Token)) { version1Token = version1Token.replace("0", ""); if (version1Token.equals("")) { version1Token = "0"; } } if (StringUtils.isNotBlank(Version2Token)) { Version2Token = Version2Token.replace("0", ""); if (Version2Token.equals("")) { Version2Token = "0"; } } if (NumberUtils.isDigits(version1Token) && NumberUtils.isDigits(Version2Token)) {//??? if (Integer.parseInt(version1Token) < Integer.parseInt(Version2Token)) { return -1; } if (Integer.parseInt(version1Token) > Integer.parseInt(Version2Token)) { return 1; } } } } return 0; }
From source file:Main.java
/** * Loads the given expansion state of a JTree, making it expand in the given manner. * // w w w. j av a 2s . c om * @param tree * The JTree to be expended * @param enumeration * The expansion state for tree as Enumeration<TreePath> */ public static void loadTreeExpansionState(JTree tree, String expansionState, int row) { // if a tree is opened for the first time, its expansionState is null if (expansionState == null) { return; } StringTokenizer stok = new StringTokenizer(expansionState, ","); while (stok.hasMoreTokens()) { int token = row + Integer.parseInt(stok.nextToken()); tree.expandRow(token); } }
From source file:Main.java
/** * Converts a path into a <code>List</code> of element names. * * @param childPath a path. e.g. "aaa:bbb/ccc:ddd/eee" * @return a <code>List</code> of element names. * e.g. "aaa:bbb", "ccc:ddd", "eee"./* ww w.ja va 2s .com*/ */ private static List getElementNames(final String childPath) { List<String> strArray = new ArrayList<>(); if (childPath != null) { StringTokenizer st = new StringTokenizer(childPath, elementDelim); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.length() > 0) { strArray.add(token); } } } return strArray; }
From source file:Main.java
/** * Change the extension of specified file.<br> * Usage :<br>//from ww w.ja va 2 s . co m * f.renameTo(MyFileUtility.reExtension(f, "jpg")) ;<br> * As we know ,File class is a dummy File , <br> * thus , you must follow the usage to change extension. * @param fin File input * @param newExtension newExtension without '.' * @return File with new extension */ public static File reExtension(File fin, String newExtension) { //Usage: f.renameTo(MyFileUtility.reExtension(f, "jpg")) ; StringTokenizer strTokener = new StringTokenizer(fin.getName(), "."); //For a file may has many '.' in its file name , we use a collection to stroe it. ArrayList<String> strVec = new ArrayList<String>(); while (strTokener.hasMoreTokens()) strVec.add(strTokener.nextToken()); String newName = ""; //Give up the original extension for (int i = 0; i != strVec.size() - 1; ++i) { newName += strVec.get(i); newName += "."; } newName += newExtension; return new File(fin.getParent() + "\\" + newName); }
From source file:Main.java
public static int findProcessIdWithPS(String command) throws Exception { int procId = -1; Runtime r = Runtime.getRuntime(); Process procPs = null;/*from ww w. jav a 2 s. co m*/ procPs = r.exec(SHELL_CMD_PS); BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { if (line.indexOf(' ' + command) != -1) { StringTokenizer st = new StringTokenizer(line, " "); st.nextToken(); // proc owner procId = Integer.parseInt(st.nextToken().trim()); break; } } return procId; }
From source file:Main.java
/** * Converts a path into a <code>List</code> of element names. * * @param childPath a path. e.g. "aaa:bbb/ccc:ddd/eee" * * @return a <code>List</code> of element names. * e.g. "aaa:bbb", "ccc:ddd", "eee". *///w ww .j a va 2 s.c o m private static List getElementNames(final String childPath) { List strArray = new ArrayList(); if (childPath != null) { StringTokenizer st = new StringTokenizer(childPath, elementDelim); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.length() > 0) { strArray.add(token); } } } return strArray; }
From source file:Main.java
/** * gets a tokenizer and returns an arraylist with the separated elements of the tokenizer * /* w w w .j a va 2 s. c o m*/ * @param strt the tokenizer * @param hasToTrim if has to trim every single element of the tokenizer * @return the AL with the elements */ public static String[] getStringArrayFromString(String strValues, String strSeparator, boolean hasToTrim) { // if null if (strValues == null) return new String[0]; // creates the AL ArrayList<String> al = new ArrayList<String>(); StringTokenizer strt = new StringTokenizer(strValues, strSeparator); while (strt.hasMoreElements()) { // gets the next element String strElement = (String) strt.nextElement(); // if is to be trimmed, it does it if (hasToTrim) strElement = strElement.trim(); // and adds it to the AL al.add(strElement); } String[] strArray = new String[al.size()]; // returns the AL return al.toArray(strArray); }
From source file:com.dc.gameserver.extComponents.Kit.ip.Util.java
/** * ip??// w ww .j a va2s. c o m * * @param ip * ?ip * @return ?ip */ public static byte[] getIpByteArrayFromString(String ip) { byte[] ret = new byte[4]; StringTokenizer st = new StringTokenizer(ip, "."); try { ret[0] = (byte) (Integer.parseInt(st.nextToken()) & 0xFF); ret[1] = (byte) (Integer.parseInt(st.nextToken()) & 0xFF); ret[2] = (byte) (Integer.parseInt(st.nextToken()) & 0xFF); ret[3] = (byte) (Integer.parseInt(st.nextToken()) & 0xFF); } catch (Exception e) { log.info("ip??"); } return ret; }