Example usage for java.util Vector elements

List of usage examples for java.util Vector elements

Introduction

In this page you can find the example usage for java.util Vector elements.

Prototype

public Enumeration<E> elements() 

Source Link

Document

Returns an enumeration of the components of this vector.

Usage

From source file:org.apache.shindig.gadgets.servlet.HtmlAccelServletTest.java

private void expectPostRequest(String extraPath, String url, final String data) throws IOException {
    expect(request.getMethod()).andReturn("POST").anyTimes();
    expect(request.getServletPath()).andReturn(SERVLET).anyTimes();
    expect(request.getScheme()).andReturn("http").anyTimes();
    expect(request.getServerName()).andReturn("apache.org").anyTimes();
    expect(request.getServerPort()).andReturn(-1).anyTimes();
    expect(request.getRequestURI()).andReturn(SERVLET + extraPath).anyTimes();
    expect(request.getRequestURL()).andReturn(new StringBuffer("apache.org" + SERVLET + extraPath)).anyTimes();
    String queryParams = (url == null ? "" : "url=" + url + "&container=accel" + "&gadget=test");
    expect(request.getQueryString()).andReturn(queryParams).anyTimes();

    ServletInputStream inputStream = mock(ServletInputStream.class);
    expect(request.getInputStream()).andReturn(inputStream);
    expect(inputStream.read((byte[]) EasyMock.anyObject())).andAnswer(new IAnswer<Integer>() {
        public Integer answer() throws Throwable {
            byte[] byteArray = (byte[]) EasyMock.getCurrentArguments()[0];
            System.arraycopy(data.getBytes(), 0, byteArray, 0, data.length());
            return data.length();
        }/*  w ww . j  a v  a  2 s  .c om*/
    });
    expect(inputStream.read((byte[]) EasyMock.anyObject())).andReturn(-1);
    Vector<String> headerNames = new Vector<String>();
    expect(request.getHeaderNames()).andReturn(headerNames.elements());
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.util.JarsClassLoader.java

protected Enumeration findResources(String name) throws IOException {
    Vector urls = new Vector();
    for (int i = 0; i < jars.length; i++) {
        JarFileEntry entry = getJarEntry(jars[i], name);
        if (entry != null) {
            urls.add(urlStreamHandler.createURL(entry));
        }/*w  w w  .j a  v a 2 s  .  c  o  m*/
    }
    return urls.elements();
}

From source file:org.mnode.coucou.AbstractQueryTreeTableNode.java

/**
 * {@inheritDoc}//from w w  w  . ja  v  a  2  s.com
 */
@Override
public final Enumeration<? extends TreeTableNode> children() {
    Vector<T> children = new Vector<T>();
    for (Node node : getNodes()) {
        children.add(createChildNode(node));
    }
    return children.elements();
}

From source file:org.mule.modules.hdfs.automation.functional.AppendTestCases.java

@Test
public void testAppend() throws Exception {
    Vector<InputStream> inputStreams = new Vector<InputStream>();
    inputStreams.add(new ByteArrayInputStream(initialWrittenData));

    byte[] inputStreamToAppend = TestDataBuilder.payloadForAppend();
    inputStreams.add(new ByteArrayInputStream(inputStreamToAppend));

    SequenceInputStream inputStreamsSequence = new SequenceInputStream(inputStreams.elements());

    getConnector().append(MYFILE_PATH, 4096, new ByteArrayInputStream(inputStreamToAppend));
    InputStream payload = getConnector().readOperation(MYFILE_PATH, 4096);
    Assert.assertThat(IOUtils.contentEquals(inputStreamsSequence, payload), is(true));
}

From source file:org.webcurator.core.harvester.util.AlertLogger.java

/**
 * Write the alerts provided in the vector to the log file.
 * @param aAlerts the list of alerts to log
 *//*from ww  w  .  j av a2s .  c  o m*/
public void writeAlerts(Vector aAlerts) {
    if (null == fw) {
        if (log.isErrorEnabled()) {
            log.error("Attempting to use an invalid AlertLogger");
        }
        return;
    }

    try {
        SinkHandlerLogRecord alert;
        Enumeration e = aAlerts.elements();
        while (e.hasMoreElements()) {
            alert = (SinkHandlerLogRecord) e.nextElement();
            fw.write(alert.getLevel() + " " + alert.getCreationTime() + " " + alert.getMessage() + " "
                    + alert.getSequenceNumber() + "\n");
        }

        fw.flush();
    } catch (Exception e) {
        if (log.isWarnEnabled()) {
            log.warn("Failed to log alerts. " + e.getMessage(), e);
        }
    }
}

From source file:org.jbpm.formModeler.service.bb.mvc.controller.RequestMultipartWrapper.java

/**
 * Returns the parameter names on the MultipartRequest
 *
 * @return An Enumeration containing all the Parameter Names
 *//*  w ww. j a v a 2  s  .c o m*/
public Enumeration getParameterNames() {
    Vector names = new Vector(requestParameters.size() + requestFiles.size());
    names.addAll(requestParameters.keySet());
    names.addAll(requestFiles.keySet());
    return names.elements();
}

From source file:org.jboss.dashboard.ui.controller.RequestMultipartWrapper.java

/**
 * Returns the parameter names on the MultipartRequest
 *
 * @return An Enumeration containing all the Parameter Names
 *///  ww w.  j  av a2s  .  c  om
public Enumeration<String> getParameterNames() {
    Vector<String> names = new Vector<String>(requestParameters.size() + requestFiles.size());
    names.addAll(requestParameters.keySet());
    names.addAll(requestFiles.keySet());
    return names.elements();
}

From source file:org.p2pvpn.tools.AdvProperties.java

/**
 * A new version of keys which sorts the keys.
 * @return sortet keys//from  w  w w  . j  a v a 2 s  .com
 */
@Override
public synchronized Enumeration keys() {
    Enumeration keysEnum = super.keys();
    Vector keyList = new Vector();
    while (keysEnum.hasMoreElements()) {
        keyList.add(keysEnum.nextElement());
    }
    Collections.sort(keyList);
    return keyList.elements();
}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a stacked bar graph representing test counts for each product area. 
 *
 * @param   builds   List of builds//w  w  w  . ja  va  2s.c o m
 * @param   suites   List of test suites
 * @param   areas    List of product areas 
 * 
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAreaTestCountChart(Vector<CMnDbBuildData> builds,
        Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) {
    JFreeChart chart = null;

    // Collect the total times for each build, organized by area
    // This hashtable maps a build to the area/time information for that build
    Hashtable<Integer, Hashtable> buildTotals = new Hashtable<Integer, Hashtable>();

    // Generate placeholders for each build so the chart maintains a 
    // format consistent with the other charts that display build information
    if (builds != null) {
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            // Create the empty area list
            buildTotals.put(new Integer(build.getId()), new Hashtable<String, Integer>());
        }
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if ((suites != null) && (suites.size() > 0)) {

        // Collect build test numbers for each of the builds in the list 
        Enumeration suiteList = suites.elements();
        while (suiteList.hasMoreElements()) {

            // Process the test summary for the current build
            CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement();
            Integer buildId = new Integer(suite.getParentId());
            Integer testCount = new Integer(suite.getTestCount());

            // Parse the build information so we can track the time by build
            Hashtable<String, Integer> areaCount = null;
            if (buildTotals.containsKey(buildId)) {
                areaCount = (Hashtable) buildTotals.get(buildId);
            } else {
                areaCount = new Hashtable<String, Integer>();
                buildTotals.put(buildId, areaCount);
            }

            // Iterate through each product area to determine who owns this suite
            CMnDbFeatureOwnerData area = null;
            Iterator iter = areas.iterator();
            while (iter.hasNext()) {
                CMnDbFeatureOwnerData currentArea = (CMnDbFeatureOwnerData) iter.next();
                if (currentArea.hasFeature(suite.getGroupName())) {
                    area = currentArea;
                }
            }

            // Add the elapsed time for the current suite to the area total
            Integer totalValue = null;
            String areaName = area.getDisplayName();
            if (areaCount.containsKey(areaName)) {
                Integer oldTotal = (Integer) areaCount.get(areaName);
                totalValue = oldTotal + testCount;
            } else {
                totalValue = testCount;
            }
            areaCount.put(areaName, totalValue);

        } // while list has elements

        // Make sure every area is represented in the build totals
        Enumeration bt = buildTotals.keys();
        while (bt.hasMoreElements()) {
            // Get the build ID for the current build
            Integer bid = (Integer) bt.nextElement();

            // Get the list of area totals for the current build
            Hashtable<String, Integer> ac = (Hashtable<String, Integer>) buildTotals.get(bid);
            Iterator a = areas.iterator();
            while (a.hasNext()) {
                // Add a value of zero if no total was found for the current area
                CMnDbFeatureOwnerData area = (CMnDbFeatureOwnerData) a.next();
                if (!ac.containsKey(area.getDisplayName())) {
                    ac.put(area.getDisplayName(), new Integer(0));
                }
            }
        }

        // Populate the data set with the area times for each build
        Collections.sort(builds, new CMnBuildIdComparator());
        Enumeration bList = builds.elements();
        while (bList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) bList.nextElement();
            Integer buildId = new Integer(build.getId());
            Hashtable areaCount = (Hashtable) buildTotals.get(buildId);

            Enumeration areaKeys = areaCount.keys();
            while (areaKeys.hasMoreElements()) {
                String area = (String) areaKeys.nextElement();
                Integer count = (Integer) areaCount.get(area);
                dataset.addValue(count, area, buildId);
            }
        }

    } // if list has elements

    // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls)
    chart = ChartFactory.createStackedBarChart("Automated Tests by Area", "Builds", "Test Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    chartFormatter.formatAreaChart(plot, dataset);

    return chart;
}

From source file:org.apache.shindig.gadgets.servlet.ServletUtilTest.java

@Test
public void testFromHttpServletRequest() throws Exception {
    HttpServletRequest original = EasyMock.createMock(HttpServletRequest.class);
    EasyMock.expect(original.getScheme()).andReturn("https");
    EasyMock.expect(original.getServerName()).andReturn("www.example.org");
    EasyMock.expect(original.getServerPort()).andReturn(444);
    EasyMock.expect(original.getRequestURI()).andReturn("/path/foo");
    EasyMock.expect(original.getQueryString()).andReturn("one=two&three=four");
    Vector<String> headerNames = new Vector<String>();
    headerNames.add("Header1");
    headerNames.add("Header2");
    EasyMock.expect(original.getHeaderNames()).andReturn(headerNames.elements());
    EasyMock.expect(original.getHeaders("Header1")).andReturn(makeEnumeration("HVal1", "HVal3"));
    EasyMock.expect(original.getHeaders("Header2")).andReturn(makeEnumeration("HVal2", "HVal4"));
    EasyMock.expect(original.getMethod()).andReturn("post");
    final ByteArrayInputStream bais = new ByteArrayInputStream("post body".getBytes());
    ServletInputStream sis = new ServletInputStream() {
        @Override//from  w w w. j a  va  2s .  c  o m
        public int read() throws IOException {
            return bais.read();
        }
    };
    EasyMock.expect(original.getInputStream()).andReturn(sis);
    EasyMock.expect(original.getRemoteAddr()).andReturn("1.2.3.4");

    EasyMock.replay(original);
    HttpRequest request = ServletUtil.fromHttpServletRequest(original);
    EasyMock.verify(original);

    assertEquals(Uri.parse("https://www.example.org:444/path/foo?one=two&three=four"), request.getUri());
    assertEquals(3, request.getHeaders().size());
    assertEquals("HVal1", request.getHeaders("Header1").get(0));
    assertEquals("HVal3", request.getHeaders("Header1").get(1));
    assertEquals("HVal2", request.getHeaders("Header2").get(0));
    assertEquals("HVal4", request.getHeaders("Header2").get(1));
    assertEquals("post", request.getMethod());
    assertEquals("post body", request.getPostBodyAsString());
    assertEquals("1.2.3.4", request.getParam(ServletUtil.REMOTE_ADDR_KEY));
}