Example usage for java.util Vector elementAt

List of usage examples for java.util Vector elementAt

Introduction

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

Prototype

public synchronized E elementAt(int index) 

Source Link

Document

Returns the component at the specified index.

Usage

From source file:com.verisign.epp.codec.gen.EPPUtil.java

/**
 * Decode a <code>List</code> of <code>Integer</code>'s by XML namespace and
 * tag name, from an XML Element. The children elements of
 * <code>aElement</code> will be searched for the specified <code>aNS</code>
 * namespace URI and the specified <code>aTagName</code>. Each XML element
 * found will be decoded and added to the returned <code>List</code>. Empty
 * child elements, will result in an <code>EPPDecodeException</code>.
 * /*from  w ww. ja  v a  2s. c  om*/
 * @param aElement
 *            XML Element to scan. For example, the element could be
 *            &ltdomain:update&gt
 * @param aNS
 *            XML namespace of the elements. For example, for domain element
 *            this is "urn:iana:xmlns:domain".
 * @param aTagName
 *            Tag name of the element including an optional namespace
 *            prefix. For example, the tag name for the domain name servers
 *            is "domain:server".
 * 
 * @return <code>List</code> of <code>Integer</code> elements representing
 *         the text nodes of the found XML elements.
 * 
 * @exception EPPDecodeException
 *                Error decoding <code>aElement</code>.
 */
public static List decodeIntegerList(Element aElement, String aNS, String aTagName) throws EPPDecodeException {

    List retVal = new ArrayList();

    Vector theChildren = EPPUtil.getElementsByTagNameNS(aElement, aNS, aTagName);

    for (int i = 0; i < theChildren.size(); i++) {
        Element currChild = (Element) theChildren.elementAt(i);

        Integer retInteger = null;

        Node textNode = currChild.getFirstChild();

        // Element does have a text node?
        if (textNode != null) {

            String intValStr = textNode.getNodeValue();
            try {
                retInteger = Integer.valueOf(intValStr);
            } catch (NumberFormatException e) {

                throw new EPPDecodeException(
                        "EPPUtil.decodeIntegerList Can't convert value to Integer: " + intValStr + e);
            }
        } else {
            throw new EPPDecodeException(
                    "EPPUtil.decodeIntegerList Can't decode numeric value from non-existant text node");
        }

        retVal.add(retInteger);
    }

    return retVal;
}

From source file:com.toughra.mlearnplayer.idevices.MCQIdevice.java

/**
 * Will make a table layout including questions, answers and feedback
 * //from w  w w .ja va2 s .c o  m
 * @return 
 */
public Form getForm() {
    form = new Form();

    //GridLayout gLayout = new GridLayout(totalQuestions + totalAnswers, 1);
    TableLayout tLayout = new TableLayout(totalQuestions + totalAnswers, 1);
    /*TableLayout tLayout = new TableLayout((totalQuestions*2) + totalAnswers,
        2);
    TableLayout.setMinimumSizePerColumn(20);
    form.setLayout(tLayout);
    */
    form.setLayout(tLayout);

    selectedAnswers = new int[totalQuestions];

    Component toFocus = null;

    for (int i = 0; i < questions.size(); i++) {

        HTMLComponent qHTML = hostMidlet.makeHTMLComponent(questions.elementAt(i).toString());
        qHTML.setFocusable(false);
        form.addComponent(qHTML);

        Vector questionAnswers = (Vector) answers.elementAt(i);
        String qId = String.valueOf(i);

        MCQAnswerItem[] itemArr = new MCQAnswerItem[questionAnswers.size()];

        for (int j = 0; j < questionAnswers.size(); j++) {
            Answer currentAnswer = (Answer) questionAnswers.elementAt(j);
            HTMLComponent answerComp = hostMidlet.makeHTMLComponent(currentAnswer.answerText);
            MCQAnswerItem thisItem = new MCQAnswerItem(this, answerComp, currentAnswer);

            thisItem.updateStyle();
            itemArr[j] = thisItem;
            TableLayout.Constraint tConst = tLayout.createConstraint();
            tConst.setWidthPercentage(100);
            form.addComponent(tConst, thisItem);

            if (i == 0 && j == 0) {
                form.setFocused(thisItem);
                thisItem.setFocus(true);
                thisItem.updateStyle();
            }
            thisItem.addActionListener(this);
        }

        for (int j = 0; j < questionAnswers.size(); j++) {
            if (j > 0) {
                itemArr[j].setNextFocusUp(itemArr[j - 1]);
            }
            if (j < questionAnswers.size() - 1) {
                itemArr[j].setNextFocusDown(itemArr[j + 1]);
            }
        }

    }

    return form;
}

From source file:org.apache.axis.wsdl.toJava.JavaDeployWriter.java

/**
 * Raw routine that writes out the operation and parameters.
 *
 * @param pw//from  w  w  w .jav a 2  s  .c o  m
 * @param javaOperName
 * @param elementQName
 * @param returnQName
 * @param returnType
 * @param params
 * @param bindingQName
 * @param faults
 */
protected void writeOperation(PrintWriter pw, String javaOperName, QName elementQName, QName returnQName,
        QName returnType, Parameters params, QName bindingQName, ArrayList faults, String SOAPAction) {

    pw.print("      <operation name=\"" + javaOperName + "\"");

    if (elementQName != null) {
        pw.print(" qname=\"" + Utils.genQNameAttributeString(elementQName, "operNS") + "\"");
    }

    if (returnQName != null) {
        pw.print(" returnQName=\"" + Utils.genQNameAttributeStringWithLastLocalPart(returnQName, "retNS")
                + "\"");
    }

    if (returnType != null) {
        pw.print(" returnType=\"" + Utils.genQNameAttributeString(returnType, "rtns") + "\"");
    }

    Parameter retParam = params.returnParam;
    if (retParam != null) {
        TypeEntry type = retParam.getType();
        QName returnItemQName = Utils.getItemQName(type);
        if (returnItemQName != null) {
            pw.print(" returnItemQName=\"");
            pw.print(Utils.genQNameAttributeString(returnItemQName, "tns"));
            pw.print("\"");
        }
        QName returnItemType = Utils.getItemType(type);
        if (returnItemType != null && use == Use.ENCODED) {
            pw.print(" returnItemType=\"");
            pw.print(Utils.genQNameAttributeString(returnItemType, "tns2"));
            pw.print("\"");
        }
    }

    if (SOAPAction != null) {
        pw.print(" soapAction=\"" + SOAPAction + "\"");
    }

    if (!OperationType.REQUEST_RESPONSE.equals(params.mep)) {
        String mepString = getMepString(params.mep);
        if (mepString != null) {
            pw.print(" mep=\"" + mepString + "\"");
        }
    }

    if ((params.returnParam != null) && params.returnParam.isOutHeader()) {
        pw.print(" returnHeader=\"true\"");
    }

    pw.println(" >");

    Vector paramList = params.list;

    for (int i = 0; i < paramList.size(); i++) {
        Parameter param = (Parameter) paramList.elementAt(i);

        // Get the parameter name QName and type QName
        QName paramQName = param.getQName();
        QName paramType = Utils.getXSIType(param);

        pw.print("        <parameter");

        if (paramQName == null) {
            pw.print(" name=\"" + param.getName() + "\"");
        } else {
            pw.print(" qname=\"" + Utils.genQNameAttributeStringWithLastLocalPart(paramQName, "pns") + "\"");
        }

        pw.print(" type=\"" + Utils.genQNameAttributeString(paramType, "tns") + "\"");

        // Get the parameter mode
        if (param.getMode() != Parameter.IN) {
            pw.print(" mode=\"" + getModeString(param.getMode()) + "\"");
        }

        // Is this a header?
        if (param.isInHeader()) {
            pw.print(" inHeader=\"true\"");
        }

        if (param.isOutHeader()) {
            pw.print(" outHeader=\"true\"");
        }

        QName itemQName = Utils.getItemQName(param.getType());
        if (itemQName != null) {
            pw.print(" itemQName=\"");
            pw.print(Utils.genQNameAttributeString(itemQName, "itns"));
            pw.print("\"");
        }

        pw.println("/>");
    }

    if (faults != null) {
        for (Iterator iterator = faults.iterator(); iterator.hasNext();) {
            FaultInfo faultInfo = (FaultInfo) iterator.next();
            QName faultQName = faultInfo.getQName();

            if (faultQName != null) {
                String className = Utils.getFullExceptionName(faultInfo.getMessage(), symbolTable);

                pw.print("        <fault");
                pw.print(" name=\"" + faultInfo.getName() + "\"");
                pw.print(" qname=\"" + Utils.genQNameAttributeString(faultQName, "fns") + "\"");
                pw.print(" class=\"" + className + "\"");
                pw.print(" type=\"" + Utils.genQNameAttributeString(faultInfo.getXMLType(), "tns") + "\"");
                pw.println("/>");
            }
        }
    }

    pw.println("      </operation>");
}

From source file:net.nosleep.superanalyzer.analysis.views.QualityView.java

private void refreshDataset() {

    Stat itemStats = null;/*from  w ww.  ja v a 2 s  .com*/

    if (_comboBox == null) {
        itemStats = _analysis.getStats(Analysis.KIND_TRACK, null);
    } else {
        ComboItem item = (ComboItem) _comboBox.getSelectedItem();
        itemStats = _analysis.getStats(item.getKind(), item.getValue());
    }

    Vector counts = new Vector(5);
    int[] rates = itemStats.getBitRates();
    for (int i = 0; i < rates.length; i++)
        counts.addElement(new Double(rates[i]));

    Vector labels = new Vector(5);
    labels.add(new String(Misc.getString("POOR") + "\n(0-63 kbps)\n"));
    labels.add(new String(Misc.getString("LOW") + "\n(64-127 kbps)\n"));
    labels.add(new String(Misc.getString("GOOD") + "\n(128-191 kbps)\n"));
    labels.add(new String(Misc.getString("HIGH") + "\n(192-255 kbps)\n"));
    labels.add(new String(Misc.getString("EXCELLENT") + "\n(256-320 kbps)\n"));

    _dataset.clear();

    PiePlot3D plot = (PiePlot3D) _chart.getPlot();
    Color[] colors = Theme.getColorSet();
    plot.setIgnoreZeroValues(true);

    for (int i = 0; i < counts.size(); i++) {
        // if((Double)counts.elementAt(i) > 0)
        {
            _dataset.setValue((String) labels.elementAt(i), (Double) counts.elementAt(i));
            plot.setSectionPaint((String) labels.elementAt(i), colors[5 - i]);
        }

    }

}

From source file:com.objectsecurity.xwiki.objects.classes.SPARQListClass.java

public List<ListItem> getSPARQList(XWikiContext context) {
    LOG.info("SPARQListClass::getSPARQList: " + context);
    List<ListItem> list = getCachedSPARQList(context);
    String insertedValue = getInsertValue();
    String insertAtPosition = getInsertAtPosition();
    LOG.debug("insertedValue: `" + insertedValue + "'");
    LOG.debug("insertAtPosition: `" + insertAtPosition + "'");
    if (list == null) {
        XWiki xwiki = context.getWiki();
        String query = getQuery(context);

        if (query == null) {
            list = new ArrayList<ListItem>();
        } else {/*from ww  w . j  a  va2 s. c  o m*/
            try {
                Vector<Vector<String>> vec = Context.getInstance().query(query, new String[0]);
                LOG.debug("result of query: " + vec);
                LOG.debug("result of query: " + ((vec == null) ? "<null>" : vec.getClass().toString()));
                list = new ArrayList<ListItem>();
                for (int i = 0; i < vec.size(); i++) {
                    String name = vec.elementAt(i).elementAt(0);
                    LOG.debug("add name: " + name);
                    list.add(new ListItem(name));
                }
                // if ((xwiki.getHibernateStore() != null) && (!query.startsWith("/"))) {
                //     list = makeList(xwiki.search(query, context));
                // } else {
                //     list = makeList(((QueryPlugin) xwiki.getPlugin("query", context)).xpath(query).list());
                // }
            } catch (Exception e) {
                LOG.warn("exception while executing query", e);
                list = new ArrayList<ListItem>();
            }
        }
        if (insertAtPosition != null && !(insertAtPosition.equals("") || insertAtPosition.equals("----"))) {
            if (insertAtPosition.equals("beginning")) {
                list.add(0, new ListItem(insertedValue));
            } else if (insertAtPosition.equals("end")) {
                list.add(new ListItem(insertedValue));
            } else {
                throw new RuntimeException("Wrong insert position in SPARQ list: " + insertAtPosition);
            }
        }
        setCachedSPARQList(list, context);
    }

    StringBuilder logResult = new StringBuilder("list: [");
    for (int i = 0; i < list.size(); i++) {
        logResult.append("'").append(list.get(i)).append("',");
    }
    LOG.debug(logResult.append("]").toString());
    return list;
}

From source file:fsi_admin.JAwsS3Conn.java

@SuppressWarnings("rawtypes")
private boolean subirArchivo(StringBuffer msj, AmazonS3 s3, String S3BUKT, String nombre, Vector archivos) {
    //System.out.println("AwsConn SubirArchivo:" + nombre + ":nombre");

    if (!archivos.isEmpty()) {
        FileItem actual = null;//w w w . ja  va  2 s . c o  m

        try {
            for (int i = 0; i < archivos.size(); i++) {
                InputStream inputStream = null;
                try {
                    actual = (FileItem) archivos.elementAt(i);
                    /////////////////////////////////////////////////////////
                    //Obtain the Content length of the Input stream for S3 header
                    InputStream is = actual.getInputStream();
                    byte[] contentBytes = IOUtils.toByteArray(is);

                    Long contentLength = Long.valueOf(contentBytes.length);

                    ObjectMetadata metadata = new ObjectMetadata();
                    metadata.setContentLength(contentLength);

                    //Reobtain the tmp uploaded file as input stream
                    inputStream = actual.getInputStream();

                    //Put the object in S3
                    //System.out.println("BUCKET: " + S3BUKT + " OBJETO: " + nombre.replace('_', '-'));
                    //System.out.println("BUCKET: " + S3BUKT + " OBJETO: " + nombre.replace('_', '-'));
                    s3.putObject(new PutObjectRequest(S3BUKT, nombre, inputStream, metadata));
                } finally {
                    if (inputStream != null)
                        try {
                            inputStream.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                }
                ////////////////////////////////////////////////////////////
            }
            return true;
        } catch (AmazonServiceException ase) {
            ase.printStackTrace();
            msj.append("Error de AmazonServiceException al subir archivo a S3.<br>");
            msj.append("Mensaje: " + ase.getMessage() + "<br>");
            msj.append("Cdigo de Estatus HTTP: " + ase.getStatusCode() + "<br>");
            msj.append("Cdigo de Error AWS:   " + ase.getErrorCode() + "<br>");
            msj.append("Tipo de Error:       " + ase.getErrorType() + "<br>");
            msj.append("Request ID:       " + ase.getRequestId());
            return false;
        } catch (AmazonClientException ace) {
            ace.printStackTrace();
            msj.append("Error de AmazonClientException al subir archivo a S3.<br>");
            msj.append("Mensaje: " + ace.getMessage());
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            msj.append("Error de Entrada/Salida al subir archivo a S3: " + e.getMessage());
            return false;
        }

    } else {
        msj.append("Error al subir archivo a la nube: No se envi ningun archivo");
        return false;
    }
}

From source file:com.sun.grizzly.http.jk.server.JkMain.java

private String[] split(String s, String delim) {
    Vector v = new Vector();
    StringTokenizer st = new StringTokenizer(s, delim);
    while (st.hasMoreTokens()) {
        v.addElement(st.nextToken());/*www.  ja v a 2  s  . co  m*/
    }
    String res[] = new String[v.size()];
    for (int i = 0; i < res.length; i++) {
        res[i] = (String) v.elementAt(i);
    }
    return res;
}

From source file:org.apache.tomcat.util.net.puretls.PureTLSSupport.java

public Object[] getPeerCertificateChain(boolean force) throws IOException {
    Vector v = ssl.getCertificateChain();

    if (v == null && force) {
        SSLPolicyInt policy = new SSLPolicyInt();
        policy.requireClientAuth(true);/*  w  ww .  j  ava 2s.co  m*/
        policy.handshakeOnConnect(false);
        policy.waitOnClose(false);
        ssl.renegotiate(policy);
        v = ssl.getCertificateChain();
    }

    if (v == null)
        return null;

    java.security.cert.X509Certificate[] chain = new java.security.cert.X509Certificate[v.size()];

    try {
        for (int i = 1; i <= v.size(); i++) {
            // PureTLS provides cert chains with the peer
            // cert last but the Servlet 2.3 spec (S 4.7) requires
            // the opposite order so we reverse the chain as we go
            byte buffer[] = ((X509Cert) v.elementAt(v.size() - i)).getDER();

            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            ByteArrayInputStream stream = new ByteArrayInputStream(buffer);

            X509Certificate xCert = (X509Certificate) cf.generateCertificate(stream);
            chain[i - 1] = xCert;
            if (logger.isTraceEnabled()) {
                logger.trace("Cert # " + i + " = " + xCert);
            }
        }
    } catch (java.security.cert.CertificateException e) {
        logger.info("JDK's broken cert handling can't parse this certificate (which PureTLS likes)", e);
        throw new IOException("JDK's broken cert handling can't parse this certificate (which PureTLS likes)");
    }
    return chain;
}

From source file:ascensionxyplot.AscensionXYPlot.java

/**
 * Creates a sample dataset.//from ww  w . j av a2  s  .co  m
 *
 * @return Series 1.
 */
private XYDataset createDataset1(File dataFile) {

    Body body = DataReader.ReadAscensionControlLog(dataFile);

    Vector<Point> p = body.markers.get(String.valueOf(0)).points;

    // create dataset 1...
    final XYSeries series1a = new XYSeries("x");
    //        series1.add(10.0, 12353.3);
    //        series1.add(20.0, 13734.4);

    final XYSeries series1b = new XYSeries("y");
    //        series1b.add(10.0, 15000.3);
    //        series1b.add(20.0, 11000.4);

    final XYSeries series1c = new XYSeries("z");
    //        series1b.add(10.0, 15000.3);
    //        series1b.add(20.0, 11000.4);

    Long lowerBound = 0L;
    Long upperBound = 120L;

    Long previousTime = lowerBound;
    int i = 0;

    while (previousTime < upperBound) {
        Point currentPoint = p.elementAt(i);
        Long currentTime = Long.valueOf(body.timepoints.elementAt(i).toString());

        if (currentTime == lowerBound || currentTime - previousTime >= 10) {
            // plot a point if it is the first record or more than 0.01s passed since last plot
            // note: the actual time was multiplied by 1000 in DataReader, thus requiring time difference of 10
            series1a.add(currentPoint.time, currentPoint.x);
            series1b.add(currentPoint.time, currentPoint.y);
            //                series1c.add(currentPoint.z, currentTime);
            series1c.add(currentPoint.time, currentPoint.z); //HOW IS THIS NOT WORKING??? WHYYYYYY....

            previousTime = currentTime;
            //                System.out.println(previousTime);
            //                System.out.println(currentTime);
            //                System.out.println(currentPoint.time);
        }

        i++;
    }

    final XYSeriesCollection collection = new XYSeriesCollection();
    collection.addSeries(series1a);
    collection.addSeries(series1b);
    collection.addSeries(series1c);
    return collection;

}

From source file:com.instantme.api.InstagramAPI.java

private void updateCookies(HttpConnection connection) throws IOException {

    /*/*from w ww  . j  a  va2s  . c  o m*/
     When we have more than one header, for instance, two 'Set-Cookie' headers,
     they are concatenated using ",", not ";". This generates a parser error
     since this program is expecting a string like "key=value;key=value;..."
              
     It is not possible to know where the "," was added since it is a valid
     character for values. The dirt fix below will solve the problem while
     instagram does not change the values inside cookies
     */

    String cookieHeader = connection.getHeaderField("Set-Cookie");
    int fix = cookieHeader.indexOf("sessionid", 0);
    if (fix >= 0) {
        cookieHeader = cookieHeader.substring(0, fix) + ";" + cookieHeader.substring(fix);
    }

    /*
    // does not work too, header are concatenated as well
    String cookieHeader = "";
    int index = 0;
    while(connection.getHeaderFieldKey(index) != null) {
    String headerName = connection.getHeaderFieldKey(index);
    headerName = headerName.toLowerCase();
    if(headerName.startsWith("set-cookie")) {
        if(cookieHeader.length() > 0) {
            cookieHeader = cookieHeader + ";" + connection.getHeaderField(index);
        }
        else {
            cookieHeader = connection.getHeaderField(index);
        }
    }
    index++;
    }  
    */

    if (cookieHeader != null) {
        if (cookieHeader.length() > 0) {
            //lastLog = cookieHeader;
            //println(cookieHeader);
            Vector cookieList = split(cookieHeader, ";");
            for (int n = 0; n < cookieList.size(); n++) {
                Vector cks = split((String) cookieList.elementAt(n), "=");
                if (cks.size() == 2) {
                    String key = ((String) cks.elementAt(0)).trim();
                    String value = ((String) cks.elementAt(1)).trim();
                    //println("Adding cookie " + key + "=" + value);
                    cookies.put(key, value);
                } else {
                    println("Problem in cookie " + cks);
                }

            }
        }
    }
}