List of usage examples for java.util Vector Vector
public Vector()
From source file:WebCrawler.java
public void run() { String strURL = "http://www.google.com"; String strTargetType = "text/html"; int numberSearched = 0; int numberFound = 0; if (strURL.length() == 0) { System.out.println("ERROR: must enter a starting URL"); return;/*from w ww. j a v a 2s .co m*/ } vectorToSearch = new Vector(); vectorSearched = new Vector(); vectorMatches = new Vector(); vectorToSearch.addElement(strURL); while ((vectorToSearch.size() > 0) && (Thread.currentThread() == searchThread)) { strURL = (String) vectorToSearch.elementAt(0); System.out.println("searching " + strURL); URL url = null; try { url = new URL(strURL); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } vectorToSearch.removeElementAt(0); vectorSearched.addElement(strURL); try { URLConnection urlConnection = url.openConnection(); urlConnection.setAllowUserInteraction(false); InputStream urlStream = url.openStream(); String type = urlConnection.guessContentTypeFromStream(urlStream); if (type == null) break; if (type.compareTo("text/html") != 0) break; byte b[] = new byte[5000]; int numRead = urlStream.read(b); String content = new String(b, 0, numRead); while (numRead != -1) { if (Thread.currentThread() != searchThread) break; numRead = urlStream.read(b); if (numRead != -1) { String newContent = new String(b, 0, numRead); content += newContent; } } urlStream.close(); if (Thread.currentThread() != searchThread) break; String lowerCaseContent = content.toLowerCase(); int index = 0; while ((index = lowerCaseContent.indexOf("<a", index)) != -1) { if ((index = lowerCaseContent.indexOf("href", index)) == -1) break; if ((index = lowerCaseContent.indexOf("=", index)) == -1) break; if (Thread.currentThread() != searchThread) break; index++; String remaining = content.substring(index); StringTokenizer st = new StringTokenizer(remaining, "\t\n\r\">#"); String strLink = st.nextToken(); URL urlLink; try { urlLink = new URL(url, strLink); strLink = urlLink.toString(); } catch (MalformedURLException e) { System.out.println("ERROR: bad URL " + strLink); continue; } if (urlLink.getProtocol().compareTo("http") != 0) break; if (Thread.currentThread() != searchThread) break; try { URLConnection urlLinkConnection = urlLink.openConnection(); urlLinkConnection.setAllowUserInteraction(false); InputStream linkStream = urlLink.openStream(); String strType = urlLinkConnection .guessContentTypeFromStream(linkStream); linkStream.close(); if (strType == null) break; if (strType.compareTo("text/html") == 0) { if ((!vectorSearched.contains(strLink)) && (!vectorToSearch.contains(strLink))) { vectorToSearch.addElement(strLink); } } if (strType.compareTo(strTargetType) == 0) { if (vectorMatches.contains(strLink) == false) { System.out.println(strLink); vectorMatches.addElement(strLink); numberFound++; if (numberFound >= SEARCH_LIMIT) break; } } } catch (IOException e) { System.out.println("ERROR: couldn't open URL " + strLink); continue; } } } catch (IOException e) { System.out.println("ERROR: couldn't open URL " + strURL); break; } numberSearched++; if (numberSearched >= SEARCH_LIMIT) break; } if (numberSearched >= SEARCH_LIMIT || numberFound >= SEARCH_LIMIT) System.out.println("reached search limit of " + SEARCH_LIMIT); else System.out.println("done"); searchThread = null; }
From source file:SelectionHandler.java
private void removeFromSource(String item) { ListModel model = source.getModel(); Vector listData = new Vector(); for (int i = 0; i < model.getSize(); i++) { listData.addElement(model.getElementAt(i)); }/*from w w w . ja v a 2 s . c o m*/ listData.removeElement(item); source.setListData(listData); }
From source file:corner.util.VectorUtilsTest.java
public void testSumVector() { Vector<String> v = new Vector<String>(); v.add("1");/*from ww w. j a v a2 s . co m*/ v.add("2"); assertEquals(3.0, VectorUtils.sum(v)); v.add("1.2"); assertEquals(4.2, VectorUtils.sum(v)); v.add("1.258"); assertEquals(5.458, VectorUtils.sum(v)); }
From source file:com.bt.aloha.batchtest.v2.ScenarioRunner.java
public ScenarioRunner() { lifecycleListener = new Vector<ScenarioLifecycleListener>(); }
From source file:com.instantme.model.CommentEntryModel.java
public boolean fromJSONObject(JSONObject jobj, IAnimation anim) { boolean result = false; setAnimation(anim);/*from w w w .j ava 2s . com*/ try { Vector _data = new Vector(); JSONArray comments = jobj.getJSONArray("data"); int numElements = comments.length(); if (comments != null) { for (int n = 0; n < numElements; n++) { JSONObject entry = comments.getJSONObject(n); CommentEntry c = new CommentEntry(); c.fromJSONObject(entry, anim); _data.addElement(c); } } data = _data; result = true; } catch (JSONException ex) { ex.printStackTrace(); } return result; }
From source file:com.bt.aloha.batchtest.v2.BaseScenario.java
public BaseScenario() { resultListeners = new Vector<ScenarioRunResultListener>(); this.name = getClass().getSimpleName(); }
From source file:com.npower.dm.util.DDFTreeHelper.java
/** * Split the nodePath into a List. The "./" prefix in the node path will be * ignored. eg: ./a/b/c/d/ results: {a, b, c, d} /a/b/c/d/ results: {a, b, c, * d} a/b/c/d results: {a, b, c, d}/*from w w w . j a v a 2 s . c om*/ * * @param nodePath * @return */ public static List<String> getPathVector(String nodePath) { String path = nodePath; if (path.startsWith("./")) { path = nodePath.substring(2, path.length()); } StringTokenizer tokenizer = new StringTokenizer(path, "/"); List<String> pathVector = new Vector<String>(); while (tokenizer.hasMoreTokens()) { pathVector.add(tokenizer.nextToken()); } return pathVector; }
From source file:MainClass.java
public PagePrinter() { pageContents = new Vector(); }
From source file:com.ricemap.spateDB.mapred.FileSplitUtil.java
/** * Combines a number of file splits into one CombineFileSplit. If number of * splits to be combined is one, it returns this split as is without creating * a CombineFileSplit.//from www. j a v a 2 s .c o m * @param splits * @param startIndex * @param count * @return * @throws IOException */ public static InputSplit combineFileSplits(JobConf conf, List<FileSplit> splits, int startIndex, int count) throws IOException { if (count == 1) { return splits.get(startIndex); } else { Path[] paths = new Path[count]; long[] starts = new long[count]; long[] lengths = new long[count]; Vector<String> vlocations = new Vector<String>(); while (count > 0) { paths[count - 1] = splits.get(startIndex).getPath(); starts[count - 1] = splits.get(startIndex).getStart(); lengths[count - 1] = splits.get(startIndex).getLength(); vlocations.addAll(Arrays.asList(splits.get(startIndex).getLocations())); count--; startIndex++; } String[] locations = prioritizeLocations(vlocations); return new CombineFileSplit(conf, paths, starts, lengths, locations); } }
From source file:org.openmrs.web.controller.concept.ConceptDrugListController.java
/** * This is called prior to displaying a form for the first time. It tells Spring the * form/command object to load into the request * // w w w . j av a 2 s .c om * @see org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest) */ protected Object formBackingObject(HttpServletRequest request) throws ServletException { //HttpSession httpSession = request.getSession(); // default empty Object List<Drug> conceptDrugList = new Vector<Drug>(); //only fill the Object if the user has authenticated properly if (Context.isAuthenticated()) { ConceptService cs = Context.getConceptService(); conceptDrugList = cs.getAllDrugs(); } return conceptDrugList; }