List of usage examples for java.util Vector elements
public Enumeration<E> elements()
From source file:InputStreamEnumerator.java
public InputStreamEnumerator(Vector<String> files) { this.files = files.elements(); }
From source file:com.substanceofcode.twitter.model.Status.java
private static Enumeration findMedia(JSONObject status) { JSONObject je;/*w w w . ja v a2 s . c o m*/ try { je = status.getJSONObject("entities"); } catch (JSONException jsonex) { return null; } if (je == null) { return null; } try { JSONArray jsa = je.getJSONArray("urls"); if (jsa != null) { for (int j = 0; j < jsa.length(); j++) { JSONObject jo = jsa.getJSONObject(j); String tco = jo.getString("url"); String exp = jo.getString("expanded_url"); if (tco != null && exp != null) { tCoResolver.add(tco, exp); } } } } catch (JSONException jsonex) { Log.error(jsonex.toString()); } Vector media = new Vector(); try { JSONArray jsa = je.getJSONArray("media"); for (int j = 0; j < jsa.length(); j++) { try { JSONObject jo = jsa.getJSONObject(j); String mu = jo.getString("media_url"); if (mu != null) { media.addElement(mu); String url = jo.getString("url"); if (url != null) { tCoResolver.add(url, mu); } } } catch (JSONException jsonex) { } } } catch (JSONException jsonex) { } return media.elements(); }
From source file:eu.crowdrec.contest.sender.RequestSender.java
/** * read logFile then sends line by line to server. * /*from ww w. j av a 2 s .c om*/ * @param inLogFileName * path to log file. That can be a zip file or text file. * @param outLogFile * path to outLog file. The outLog file should be analyzed by the evaluator. * if the filename is null; no output will be generated * @param serverURL * URL of the server */ public static void sender(final String inLogFileName, final String outLogFile, final String serverURL) { // handle the log file // check type of file // try to read the defined logFile BufferedReader br = null; BufferedWriter bw = null; try { // if outLogFile name is not null, create an output file if (outLogFile != null && outLogFile.length() > 0) { bw = new BufferedWriter(new FileWriter(new File(outLogFile), false)); } // support a list of files in a directory File inLogFile = new File(inLogFileName); InputStream is; if (inLogFile.isFile()) { is = new FileInputStream(inLogFileName); // support gZip files if (inLogFile.getName().toLowerCase().endsWith(".gz")) { is = new GZIPInputStream(is); } } else { // if the input is a directory, consider all files based on a pattern File[] childs = inLogFile.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { final String fileName = name.toLowerCase(); return fileName.endsWith("data.idomaar.txt.gz") || fileName.endsWith("data.idomaar.txt") || fileName.endsWith(".data.gz"); } }); if (childs == null || childs.length == 0) { throw new IOException("invalid inLogFileName or empty directory"); } Arrays.sort(childs, new Comparator<File>() { @Override public int compare(File o1, File o2) { return o1.getName().compareTo(o2.getName()); } }); Vector<InputStream> isChilds = new Vector<InputStream>(); for (int i = 0; i < childs.length; i++) { InputStream tmpIS = new FileInputStream(childs[i]); // support gZip files if (childs[i].getName().toLowerCase().endsWith(".gz")) { tmpIS = new GZIPInputStream(tmpIS); } isChilds.add(tmpIS); } is = new SequenceInputStream(isChilds.elements()); } // read the log file line by line br = new BufferedReader(new InputStreamReader(is)); try { for (String line = br.readLine(); line != null; line = br.readLine()) { // ignore invalid lines and header if (line.startsWith("null") || line.startsWith("#")) { continue; } if (useThreadPool) { RequestSenderThread t = new RequestSenderThread(line, serverURL, bw); try { // try to limit the speed of sending requests if (Thread.activeCount() > 1000) { if (logger.isDebugEnabled()) { logger.debug("Thread.activeCount() = " + Thread.activeCount()); } Thread.sleep(200); } } catch (Exception e) { logger.info(e.toString()); } t.start(); } else { // send parameters to http server and get response. final long startTime = System.currentTimeMillis(); String result = HttpLib.HTTPCLIENT.equals(httpLib) ? excutePostWithHttpClient(line, serverURL) : excutePost(line, serverURL); // analyze whether an answer is expected boolean answerExpected = false; if (line.contains("\"event_type\": \"recommendation_request\"")) { answerExpected = true; } if (answerExpected) { if (logger.isInfoEnabled()) { logger.info("serverResponse: " + result); } // if the output file is not null, write the output in a synchronized way if (bw != null) { String[] data = LogFileUtils.extractEvaluationRelevantDataFromInputLine(line); String requestId = data[0]; String userId = data[1]; String itemId = data[2]; String domainId = data[3]; String timeStamp = data[4]; long responseTime = System.currentTimeMillis() - startTime; synchronized (bw) { try { bw.write("prediction\t" + requestId + "\t" + timeStamp + "\t" + responseTime + "\t" + itemId + "\t" + userId + "\t" + domainId + "\t" + result); bw.newLine(); } catch (Exception e) { e.printStackTrace(); } } } } } } } catch (IOException e) { logger.warn(e.toString(), e); } } catch (FileNotFoundException e) { logger.error("logFile not found e:" + e.toString()); } catch (IOException e) { logger.error("reading the logFile failed e:" + e.toString()); } finally { if (br != null) { try { br.close(); } catch (IOException e) { logger.debug("close read-log file failed"); } } if (bw != null) { try { // wait for ensuring that all request are finished // this simplifies the management of thread and worked fine for all test machines Thread.sleep(5000); bw.flush(); } catch (Exception e) { logger.debug("close write-log file failed"); } } } }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a stacked bar graph representing the total number of tests in * in each build. //from w ww . ja v a 2s. c o m * * @param builds List of builds * * @return Stacked graph representing automated tests across all builds */ public static final JFreeChart getTestCountChart(Vector<CMnDbBuildData> builds) { JFreeChart chart = null; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); if ((builds != null) && (builds.size() > 0)) { // Collect build test numbers for each of the builds in the list Collections.sort(builds, new CMnBuildIdComparator()); Enumeration buildList = builds.elements(); while (buildList.hasMoreElements()) { // Process the test summary for the current build CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement(); Hashtable testSummary = build.getTestSummary(); if ((testSummary != null) && (testSummary.size() > 0)) { Enumeration keys = testSummary.keys(); while (keys.hasMoreElements()) { String testType = (String) keys.nextElement(); Integer buildId = new Integer(build.getId()); CMnDbTestSummaryData tests = (CMnDbTestSummaryData) testSummary.get(testType); // Record the total number of tests dataset.addValue(tests.getTotalCount(), testType, buildId); } } } // while list has elements } // if list has elements // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls) chart = ChartFactory.createStackedBarChart("Automated Tests by Type", "Builds", "Test Count", dataset, PlotOrientation.VERTICAL, true, true, false); // get a reference to the plot for further customization... CategoryPlot plot = (CategoryPlot) chart.getPlot(); chartFormatter.formatTypeChart(plot, dataset); return chart; }
From source file:SortedProperties.java
@Override public synchronized Enumeration<Object> keys() { Vector<Object> keyList = new Vector<Object>(super.keySet()); Collections.sort(keyList, comparator); return keyList.elements(); }
From source file:org.mikha.utils.web.multipart.MultipartRequestWrapper.java
public Enumeration<String> getParameterNames() { Vector<String> v = new Vector<String>(params.keySet()); return v.elements(); }
From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java
/** * Generate a pie graph representing average test counts for each type of test for * all builds in the list. /*from ww w. j a va 2s. co m*/ * * @param builds List of builds * * @return Pie graph representing build execution times across all builds */ public static final JFreeChart getAverageTestCountChart(Vector<CMnDbBuildData> builds) { JFreeChart chart = null; // Collect the average of all test types Hashtable countAvg = new Hashtable(); DefaultPieDataset dataset = new DefaultPieDataset(); if ((builds != null) && (builds.size() > 0)) { // Collect build metrics for each of the builds in the list Enumeration buildList = builds.elements(); while (buildList.hasMoreElements()) { // Process the build metrics for the current build CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement(); Hashtable testSummary = build.getTestSummary(); if ((testSummary != null) && (testSummary.size() > 0)) { Enumeration keys = testSummary.keys(); while (keys.hasMoreElements()) { String testType = (String) keys.nextElement(); CMnDbTestSummaryData tests = (CMnDbTestSummaryData) testSummary.get(testType); Integer avgValue = null; if (countAvg.containsKey(testType)) { Integer oldAvg = (Integer) countAvg.get(testType); avgValue = oldAvg + tests.getTotalCount(); } else { avgValue = tests.getTotalCount(); } countAvg.put(testType, avgValue); } } } // while list has elements // Populate the data set with the average values for each metric Enumeration keys = countAvg.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); Integer total = (Integer) countAvg.get(key); Integer avg = new Integer(total.intValue() / builds.size()); dataset.setValue(key, avg); } } // if list has elements // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls) chart = ChartFactory.createPieChart("Avg Test Count by Type", dataset, true, true, false); // get a reference to the plot for further customization... PiePlot plot = (PiePlot) chart.getPlot(); chartFormatter.formatTypeChart(plot, "tests"); return chart; }
From source file:org.helios.ember.web.spring.ServletContextAttributes.java
/** * {@inheritDoc}//w ww . ja v a 2 s . co m * @see org.eclipse.jetty.util.Attributes#getAttributeNames() */ @Override public Enumeration<String> getAttributeNames() { Vector<String> v = new Vector<String>(attrs.keySet()); return v.elements(); }
From source file:Main.java
public Enumeration keys() { Enumeration keysEnum = super.keys(); Vector<String> keyList = new Vector<String>(); while (keysEnum.hasMoreElements()) { keyList.add((String) keysEnum.nextElement()); }/* www. j av a 2 s .c o m*/ Collections.sort(keyList); return keyList.elements(); }
From source file:com.simplenoteapp.test.Test.java
public void getIndexSucceeded(Vector noteInfo) { for (Enumeration e = noteInfo.elements(); e.hasMoreElements();) { NoteInfo i = (NoteInfo) e.nextElement(); System.out.println("Key: " + i.getKey()); System.out.println("Last modified: " + i.getModifiedDate()); System.out.println("Deleted: " + i.isDeleted()); System.out.print('\n'); }/*from ww w . j a va2 s . c o m*/ System.exit(0); }