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:org.openxdata.server.sms.FormSmsParser.java

/**
 * Gets a list of questions which have been answered.
 * // ww  w.jav  a  2  s . c  o  m
 * @param formData the form data.
 * @param ids
 * @return list of answered questions
 */
private Vector<QuestionData> getAnsweredQuestions(org.openxdata.model.FormData formData, Vector<Byte> ids) {
    Vector<QuestionData> qtns = new Vector<QuestionData>();

    for (byte i = 0; i < ids.size(); i++) {
        QuestionData questionData = formData.getQuestion(Byte.parseByte(ids.elementAt(i).toString()));
        if (questionData.isAnswered())
            qtns.add(questionData);
    }

    return qtns;
}

From source file:org.apache.xmlrpc.applet.SimpleXmlRpcClient.java

/**
 * Generate an XML-RPC request from a method name and a parameter vector.
 *//*w w w. j a v  a2  s .com*/
void writeRequest(XmlWriter writer, String method, Vector params) throws IOException {
    writer.startElement("methodCall");
    writer.startElement("methodName");
    writer.write(method);
    writer.endElement("methodName");
    writer.startElement("params");
    int l = params.size();
    for (int i = 0; i < l; i++) {
        writer.startElement("param");
        writeObject(params.elementAt(i), writer);
        writer.endElement("param");
    }
    writer.endElement("params");
    writer.endElement("methodCall");
}

From source file:edu.umn.cs.spatialHadoop.mapreduce.SpatialInputFormat3.java

@Override
public List<InputSplit> getSplits(JobContext job) throws IOException {
    List<InputSplit> splits = super.getSplits(job);
    Configuration jobConf = job.getConfiguration();
    if (jobConf.getInt(CombineSplits, 1) > 1) {
        long t1 = System.currentTimeMillis();
        int combine = jobConf.getInt(CombineSplits, 1);
        /*/*ww w  .  j a va2 s . c  o  m*/
         * Combine splits to reduce number of map tasks. Currently, this is done
         * using a greedy algorithm that combines splits based on how many hosts
         * they share.
         * TODO: Use a graph clustering algorithm where each vertex represents a
         * split, and each edge is weighted with number of shared hosts between
         * the two splits
         */
        Vector<Vector<FileSplit>> openSplits = new Vector<Vector<FileSplit>>();
        int maxNumberOfSplits = (int) Math.ceil((float) splits.size() / combine);
        List<InputSplit> combinedSplits = new Vector<InputSplit>();
        for (InputSplit split : splits) {
            FileSplit fsplit = (FileSplit) split;
            int maxSimilarity = -1; // Best similarity found so far
            int bestFit = -1; // Index of a random open split with max similarity
            int numMatches = 0; // Number of splits with max similarity
            for (int i = 0; i < openSplits.size(); i++) {
                Vector<FileSplit> splitList = openSplits.elementAt(i);
                int similarity = 0;
                for (FileSplit otherSplit : splitList) {
                    for (String host1 : fsplit.getLocations())
                        for (String host2 : otherSplit.getLocations())
                            if (host1.equals(host2))
                                similarity++;
                }
                if (similarity > maxSimilarity) {
                    maxSimilarity = similarity;
                    bestFit = i;
                    numMatches = 1;
                } else if (similarity == maxSimilarity) {
                    numMatches++;
                    // Replace with a probability () for a reservoir sample
                    double random = Math.random();
                    if (random < (double) 1 / numMatches) {
                        // Replace the element in the reservoir
                        bestFit = i;
                    }
                }
            }
            if (maxSimilarity > 0 || (openSplits.size() + combinedSplits.size()) >= maxNumberOfSplits) {
                // Good fit || cannot create more open splits,
                // add it to an existing open split.
                Vector<FileSplit> bestList = openSplits.elementAt(bestFit);
                bestList.add(fsplit);
                if (bestList.size() > combine) {
                    // Reached threshold for this list. Add it to combined splits
                    combinedSplits.add(FileSplitUtil.combineFileSplits(bestList, 0, bestList.size()));
                    // Remove it from open splits
                    openSplits.remove(bestFit);
                }
            } else {
                // Bad fit && can add a new split
                // Create a new open split just for this one
                Vector<FileSplit> newOpenSplit = new Vector<FileSplit>();
                newOpenSplit.add(fsplit);
                openSplits.addElement(newOpenSplit);
            }
        }

        // Add all remaining open splits to the list of combined splits
        for (Vector<FileSplit> openSplit : openSplits) {
            combinedSplits.add(FileSplitUtil.combineFileSplits(openSplit, 0, openSplit.size()));
        }

        String msg = String.format("Combined %d splits into %d combined splits", splits.size(),
                combinedSplits.size());
        splits.clear();
        splits.addAll(combinedSplits);
        long t2 = System.currentTimeMillis();
        LOG.info(msg + " in " + ((t2 - t1) / 1000.0) + " seconds");
    }
    return splits;
}

From source file:Animator.java

/**
 * Fetch the images named in the argument, updating maxWidth and maxHeight
 * as we go. Is restartable./* w ww. j a  v  a 2 s. c o m*/
 * 
 * @param images
 *            a Vector of URLs
 * @return true if all went well, false otherwise.
 */
boolean fetchImages(Vector images) {
    int i;
    int size = images.size();
    for (i = 0; i < size; i++) {
        Object o = images.elementAt(i);
        if (o instanceof URL) {
            URL url = (URL) o;
            tellLoadingMsg(url, imageLabel);
            Image im = getImage(url);
            tracker.addImage(im, ANIMATION_ID);
            images.setElementAt(im, i);
        }
    }

    try {
        tracker.waitForID(ANIMATION_ID);
    } catch (InterruptedException e) {
    }
    if (tracker.isErrorID(ANIMATION_ID)) {
        return false;
    }

    for (i = 0; i < size; i++) {
        updateMaxDims(getImageDimensions((Image) images.elementAt(i)));
    }

    return true;
}

From source file:CSVReader.java

public String[] getLine() {
    Vector lineArray = new Vector();
    String token = null;/* w ww  .  j  a va  2 s  . co  m*/
    String returnArray[] = null;

    // reading values from line until null comes

    try {
        while (lineArray.size() == 0) {
            while ((token = get()) != null) {
                lineArray.add(token);
            } // end of while
        } // end of while
    } catch (EOFException e) {
        return null;
    } catch (IOException e) {
    }

    returnArray = new String[lineArray.size()];

    for (int ii = 0; ii < lineArray.size(); ii++) {
        returnArray[ii] = lineArray.elementAt(ii).toString();
    } // end of for

    return returnArray;
}

From source file:com.naryx.tagfusion.cfm.xml.ws.javaplatform.DynamicWebServiceStubGenerator.java

private Service getWSDLService(Parser wsdlParser) throws cfmRunTimeException {
    SymTabEntry symTabEntry = null;/*from   ww  w .  ja va2 s. c om*/
    Map.Entry entry = null;
    Vector v = null;

    // Iterate through all the entries in the WSDL until we
    // find the first service entry. Assume it's that one.
    Iterator iterator = wsdlParser.getSymbolTable().getHashMap().entrySet().iterator();
    while (iterator.hasNext()) {
        entry = (Map.Entry) iterator.next();
        v = (Vector) entry.getValue();
        for (int i = 0; i < v.size(); ++i) {
            if (ServiceEntry.class.isInstance(v.elementAt(i))) {
                symTabEntry = (SymTabEntry) v.elementAt(i);
                break;
            }
        }
    }

    if (symTabEntry == null)
        throw new cfmRunTimeException(catchDataFactory.generalException("errorCode.runtimeError",
                "Invalid web service operation. Cannot locate service entry in WSDL"));

    // Return the service
    return ((ServiceEntry) symTabEntry).getService();
}

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

/**
 * Decode a <code>List</code> of <code>EPPCodecComponent</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 result in the instantiation of <code>aClass</code>, which will
 * decode the associated XML element and added to the returned
 * <code>List</code>./*from  ww w .  ja  va 2s  . c  om*/
 * 
 * @param aElement
 *            XML Element to scan. For example, the element could be
 *            &ltdomain:add&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 contact elements of
 *            &gtdomain:add&gt is "domain:contact".
 * @param aClass
 *            Class to instantiate for each found XML element. This must be
 *            a class that implements <code>EPPCodecComponent</code>
 * @return <code>List</code> of <code>EPPCodecComponent</code> elements
 *         representing the found XML elements.
 * @exception EPPDecodeException
 *                Error decoding <code>aElement</code>.
 */
public static List decodeCompList(Element aElement, String aNS, String aTagName, Class aClass)
        throws EPPDecodeException {
    List retVal = new ArrayList();

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

        // For each element
        for (int i = 0; i < theChildren.size(); i++) {
            EPPCodecComponent currComp = (EPPCodecComponent) aClass.newInstance();

            currComp.decode((Element) theChildren.elementAt(i));

            retVal.add(currComp);
        }

        // end for each element
    } catch (IllegalAccessException e) {
        throw new EPPDecodeException("EPPUtil.decodeCompList(), IllegalAccessException: " + e);
    } catch (InstantiationException e) {
        throw new EPPDecodeException("EPPUtil.decodeCompList(), InstantiationException: " + e);
    }

    return retVal;
}

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

/**
 * Decode a <code>Vector</code> of <code>EPPCodecComponent</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 result in the instantiation of <code>aClass</code>, which will
 * decode the associated XML element and added to the returned
 * <code>Vector</code>.//from w w  w. j a v a2 s.com
 * 
 * @param aElement
 *            XML Element to scan. For example, the element could be
 *            &ltdomain:add&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 contact elements of
 *            &gtdomain:add&gt is "domain:contact".
 * @param aClass
 *            Class to instantiate for each found XML element. This must be
 *            a class that implements <code>EPPCodecComponent</code>
 * @return <code>Vector</code> of <code>EPPCodecComponent</code> elements
 *         representing the found XML elements.
 * @exception EPPDecodeException
 *                Error decoding <code>aElement</code>.
 */
public static Vector decodeCompVector(Element aElement, String aNS, String aTagName, Class aClass)
        throws EPPDecodeException {
    Vector retVal = new Vector();

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

        // For each element
        for (int i = 0; i < theChildren.size(); i++) {
            EPPCodecComponent currComp = (EPPCodecComponent) aClass.newInstance();

            currComp.decode((Element) theChildren.elementAt(i));

            retVal.addElement(currComp);
        }

        // end for each element
    } catch (IllegalAccessException e) {
        throw new EPPDecodeException("EPPUtil.decodeCompVector(), IllegalAccessException: " + e);
    } catch (InstantiationException e) {
        throw new EPPDecodeException("EPPUtil.decodeCompVector(), InstantiationException: " + e);
    }

    return retVal;
}

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

/**
 * compares two <code>Vector</code> instances. The Java 1.1
 * <code>Vector</code> class does not implement the <code>equals</code>
 * methods, so <code>equalVectors</code> was written to implement
 * <code>equals</code> of two <code>Vectors</code> (aV1 and aV2). This
 * method is not need for Java 2./*from  ww w  . j a v  a  2  s. co m*/
 * 
 * @param aV1
 *            First Vector instance to compare.
 * @param aV2
 *            Second Vector instance to compare.
 * @return <code>true</code> if Vector's are equal; <code>false</code>
 *         otherwise.
 */
public static boolean equalVectors(Vector aV1, Vector aV2) {
    if ((aV1 == null) && (aV2 == null)) {
        return true;
    }

    else if ((aV1 != null) && (aV2 != null)) {
        if (aV1.size() != aV2.size()) {
            return false;
        }

        for (int i = 0; i < aV1.size(); i++) {
            Object elm1 = aV1.elementAt(i);
            Object elm2 = aV2.elementAt(i);

            if (!((elm1 == null) ? (elm2 == null) : elm1.equals(elm2))) {
                return false;
            }
        }

        return true;
    } else {
        return false;
    }
}

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

/** 
 * Constructor - setup the for, dig through the questions and answers
 * that are there.//from  w  w  w.  j  a va 2  s . c om
 * 
 * @param host the midlet host
 * @param data the XML data to construct with
 */
public MCQIdevice(MLearnPlayerMidlet host, XmlNode data) {
    super(host);

    questions = new Vector();
    answers = new Vector();

    Vector dataQuestions = data.findChildrenByTagName("question", true);
    hadCorrect = MLearnUtils.makeBooleanArray(false, dataQuestions.size());
    qAttempted = MLearnUtils.makeBooleanArray(false, dataQuestions.size());

    fbackAreas = new HTMLComponent[dataQuestions.size()];

    for (int i = 0; i < dataQuestions.size(); i++) {
        XmlNode currentNode = (XmlNode) dataQuestions.elementAt(i);
        if (i == 0 && currentNode.hasAttribute("audio")) {
            audioURL = currentNode.getAttribute("audio");
        }

        //CDATA text section will always be the first child after question
        String questionTextHTML = currentNode.getTextChildContent(0);
        XmlNode tinCanNode = currentNode.findFirstChildByTagName("tincan", true);
        String tinCanId = null;
        String tinCanDef = null;
        JSONObject tcDefObj = null;

        if (tinCanNode != null) {
            tinCanDef = currentNode.findFirstChildByTagName("activitydef", true).getTextChildContent(0);
            tinCanId = tinCanNode.getAttribute("id");
        } else {
            tinCanId = MLearnUtils.TINCAN_PREFIX + "/" + MLearnPlayerMidlet.getInstance().getTinCanPage()
                    + "/mcq" + i;
            tcDefObj = new JSONObject();
            try {
                String qText = MLearnUtils.removeHTMLTags(questionTextHTML);
                String qName = "MCQ: " + i + ": " + MLearnPlayerMidlet.getInstance().getTinCanPage();
                tcDefObj.put("name", UMTinCan.makeLangMapVal("en-US", qName));
                tcDefObj.put("description", UMTinCan.makeLangMapVal("en-US", qName + " " + qText));
                tcDefObj.put("type", "http://adlnet.gov/expapi/activities/cmi.interaction");
                tcDefObj.put("interactionType", "choice");

            } catch (JSONException e) {

            }
        }

        QuestionItem thisItem = new QuestionItem(questionTextHTML, tinCanId, tinCanDef);
        questions.addElement(thisItem);

        Vector questionAnswers = currentNode.findChildrenByTagName("answer", true);
        Vector answerObjVector = new Vector();
        String[][] ansInfo = new String[questionAnswers.size()][2];
        int correctIndex = 0;
        for (int j = 0; j < questionAnswers.size(); j++) {
            XmlNode currentAnswer = (XmlNode) questionAnswers.elementAt(j);
            String answerText = currentAnswer.getTextChildContent(0);
            XmlNode feedbackNode = (XmlNode) currentAnswer.findChildrenByTagName("feedback", true).elementAt(0);
            String feedback = feedbackNode.getTextChildContent(0);
            String responseId = currentAnswer.getAttribute("id");
            if (responseId == null) {
                responseId = "opt" + j;
            }

            boolean thisAnswerCorrect = currentAnswer.getAttribute("iscorrect").equals("true");
            Answer answer = new Answer(answerText, thisAnswerCorrect, new Integer(i), feedback, j, responseId);
            answer.questionId = i;
            if (thisAnswerCorrect) {
                correctIndex = j;
            }

            if (feedbackNode.hasAttribute("audio")) {
                answer.fbAudio = feedbackNode.getAttribute("audio");
            }

            answerObjVector.addElement(answer);
            ansInfo[j][0] = "opt" + j;
            ansInfo[j][1] = MLearnUtils.removeHTMLTags(answerText).trim();
            totalAnswers++;
        }

        //complete definition if applicable
        if (tcDefObj != null) {
            JSONArray correctArr = new JSONArray();
            correctArr.put(ansInfo[correctIndex][0]);
            try {
                tcDefObj.put("correctResponsesPattern", correctArr);
                JSONArray choicesArr = new JSONArray();
                for (int j = 0; j < questionAnswers.size(); j++) {
                    JSONObject thisAnsObj = new JSONObject();
                    thisAnsObj.put("id", ansInfo[j][0]);
                    thisAnsObj.put("description", UMTinCan.makeLangMapVal("en-US", ansInfo[j][1]));
                    choicesArr.put(thisAnsObj);
                }
                tcDefObj.put("choices", choicesArr);

                String jsonStr = tcDefObj.toString();
                thisItem.tinCanDefinition = jsonStr;
                int x = 0;
            } catch (JSONException e) {

            }
        }

        answers.addElement(answerObjVector);
        questionAnswers = null;
        totalQuestions++;
    }
    int done = 0;
}