List of usage examples for java.util StringTokenizer nextElement
public Object nextElement()
From source file:StringReverse.java
public static void main(String[] argv) { //+/* w ww.j a va 2 s . com*/ String s = "Father Charles Goes Down And Ends Battle"; // Put it in the stack frontwards Stack myStack = new Stack(); StringTokenizer st = new StringTokenizer(s); while (st.hasMoreTokens()) myStack.push(st.nextElement()); // Print the stack backwards System.out.print('"' + s + '"' + " backwards by word is:\n\t\""); while (!myStack.empty()) { System.out.print(myStack.pop()); System.out.print(' '); } System.out.println('"'); //- }
From source file:org.terracotta.workmanager.spider.StartMaster.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("u", "url", true, "the start URL"); options.addOption("d", "depth", true, "the parse depth"); options.addOption("l", "external-links", false, "follow external links (optional, defaults to false)"); options.addOption("i", "routing-ids", true, "list with the routing IDs for the work queues, separated with '" + ROUTING_IDS_LIST_SEPARATOR + "'"); options.addOption("f", "fail-over-routing-id", true, "the routing ID for the fail-over queue (optional)"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); HelpFormatter formatter = new HelpFormatter(); String startURL;/*from w w w.ja va 2 s . co m*/ int maxDepth; boolean followExternalLinks = false; // Boolean.parseBoolean(args[2]); String[] routingIDs = null; String failOverRoutingID = null; if (cmd.hasOption("u")) { startURL = cmd.getOptionValue("u"); } else { formatter.printHelp(SPIDER_MASTER_NAME, options); return; } if (cmd.hasOption("d")) { try { maxDepth = Integer.parseInt(cmd.getOptionValue("d")); } catch (NumberFormatException nfe) { formatter.printHelp(SPIDER_MASTER_NAME, options); return; } } else { formatter.printHelp(SPIDER_MASTER_NAME, options); return; } if (cmd.hasOption("i")) { String tokens = cmd.getOptionValue("i"); StringTokenizer tokenizer = new StringTokenizer(tokens, ROUTING_IDS_LIST_SEPARATOR); routingIDs = new String[tokenizer.countTokens()]; for (int i = 0; i < routingIDs.length; i++) { routingIDs[i] = ((String) tokenizer.nextElement()).trim(); } } else { formatter.printHelp(SPIDER_MASTER_NAME, options); return; } if (cmd.hasOption("f")) { failOverRoutingID = cmd.getOptionValue("f"); } // else { // formatter.printHelp(SPIDER_MASTER_NAME, options); // return; // } if (cmd.hasOption("l")) { followExternalLinks = Boolean.parseBoolean(cmd.getOptionValue("l")); } StringBuilder builder = new StringBuilder(); builder.append("Starting Spider: "); builder.append("\n start url \t\t\t= "); builder.append(startURL); builder.append("\n max parse depth \t\t= "); builder.append(maxDepth); builder.append("\n follow external links \t= "); builder.append(followExternalLinks); builder.append("\n list with routing IDs \t= [ "); for (int i = 0; i < routingIDs.length; i++) { builder.append(routingIDs[i]); builder.append(' '); } builder.append("]"); if (failOverRoutingID != null) { builder.append("\n routing ID for fail-over node = "); builder.append(failOverRoutingID); } System.out.println(builder.toString()); new SpiderMaster(startURL, maxDepth, followExternalLinks, routingIDs, failOverRoutingID).run(); }
From source file:Main.java
public static String getIdentifier(HashMap<String, ArrayList<String>> addresses) { String wifi_address = addresses.get("eth0").get(0); //for now we expect there to be only 1 address, the one OLSRd has assigned //need to extract the 3rd and 4th octet of the address StringTokenizer tokens = new StringTokenizer(wifi_address, "."); tokens.nextElement(); tokens.nextElement();/* ww w . j a v a2s . c om*/ String identifier = tokens.nextToken() + "." + tokens.nextToken(); return identifier; }
From source file:Main.java
/** * This fucntion parse database id to retrieve UUID, Major and Minor * @param id//from ww w.j a v a 2 s . c o m * @return */ public static List<String> parseId(String id) { List<String> list = new ArrayList<String>(); StringTokenizer token = new StringTokenizer(id, "."); while (token.hasMoreElements()) { list.add((String) token.nextElement()); } return list; }
From source file:Main.java
public static ArrayList splitStringByCharC(String str, String c) { StringTokenizer en = new StringTokenizer(str, c); ArrayList vec = new ArrayList(); while (en.hasMoreElements()) vec.add(en.nextElement()); return vec;// w w w .j a v a2 s . co m }
From source file:Main.java
private static String[] parseCommandStr(String str) { StringTokenizer st = new StringTokenizer(str, "|"); String[] command_arr = new String[st.countTokens()]; int i = 0;/* w w w . j a va 2s .co m*/ while (st.hasMoreElements()) { command_arr[i] = (String) st.nextElement(); i++; } return command_arr; }
From source file:org.vedantatree.expressionoasis.utils.StringUtils.java
/** * Gets the last token for spcefied dlimiter and string. * //from ww w. j ava 2s. c o m * @param value the string to parse * @param delimiter the delimiter used for parsing. * @return */ public final static String getLastToken(String value, String delimiter) { String result = null; StringTokenizer tokenizer = new StringTokenizer(value, delimiter); while (tokenizer.hasMoreElements()) { result = (String) tokenizer.nextElement(); } return result; }
From source file:gov.nih.nci.lv.util.LVUtils.java
/** * converts a ids seperated by a comma to a set. * @param ids ids/*from ww w.j a v a 2 s . c o m*/ * @param delimiter delimiter * @return Set */ public static Set<Long> convertStringToSet(String ids, String delimiter) { Set<Long> labs = new HashSet<Long>(); if (StringUtils.isEmpty(ids)) { return labs; } StringTokenizer st = new StringTokenizer(ids, delimiter); while (st.hasMoreTokens()) { labs.add(new Long(st.nextElement().toString())); } return labs; }
From source file:gov.nih.nci.lv.util.LVUtils.java
/** * converts a ids seperated by a comma to a set. * @param ids ids// w w w.j a v a2 s .c o m * @param delimiter delimiter * @return Set */ public static List<Long> convertStringToList(String ids, String delimiter) { List<Long> labs = new ArrayList<Long>(); if (StringUtils.isEmpty(ids)) { return labs; } StringTokenizer st = new StringTokenizer(ids, delimiter); while (st.hasMoreTokens()) { labs.add(new Long(st.nextElement().toString())); } return labs; }
From source file:Main.java
/** * gets a tokenizer and returns an arraylist with the separated elements of the tokenizer * /*from 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); }