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:gov.nih.nci.evs.browser.utils.SourceTreeUtils.java

public ResolvedConceptReference getRandomResolvedConceptReference(String source) {
    //    public TreeItem getSourceTree(String source) {
    SourceTreeUtils sourceTreeUtils = new SourceTreeUtils(lbSvc);
    TreeItem ti = sourceTreeUtils.getSourceTree(source);
    if (ti == null)
        return null;
    if (!ti._expandable) {
        return null;
    }//from  w ww. j  a  v  a  2 s  .  c om
    Vector v = new Vector();
    Iterator iterator = ti._assocToChildMap.keySet().iterator();
    while (iterator.hasNext()) {
        String assocText = (String) iterator.next();
        List<TreeItem> children = ti._assocToChildMap.get(assocText);
        for (int k = 0; k < children.size(); k++) {
            TreeItem child_ti = (TreeItem) children.get(k);
            ResolvedConceptReference rcr = new ResolvedConceptReference();
            EntityDescription ed = new EntityDescription();
            ed.setContent(child_ti._text);
            rcr.setEntityDescription(ed);
            rcr.setCode(child_ti._code);
            v.add(rcr);
        }
    }
    if (v.size() == 0)
        return null;
    //int m = new RandomVariateGenerator().uniform(0, v.size()-1);
    int m = uniform(0, v.size() - 1);
    return (ResolvedConceptReference) v.elementAt(m);
}

From source file:org.ecoinformatics.datamanager.parser.generic.GenericDataPackageParser.java

/**
 * Pulls the entity information out of the XML and stores it in a hash table.
 *//* w w  w .ja v a  2  s  .  c  om*/
private void processEntities(CachedXPathAPI xpathapi, NodeList entitiesNodeList, String xpath, String packageId)
        throws SAXException, javax.xml.transform.TransformerException, Exception {
    // Make sure that entities is not null
    if (entitiesNodeList == null) {
        return;
    }

    int entityNodeListLength = entitiesNodeList.getLength();
    numEntities = numEntities + entityNodeListLength;
    String entityName = "";
    String entityDescription = "";
    String entityOrientation = "";
    String entityCaseSensitive = "";
    String entityNumberOfRecords = "-1";
    String onlineUrl = "";
    String format = null;
    String numHeaderLines = "0";
    int numFooterLines = 0;
    String fieldDelimiter = null;
    String recordDelimiter = "";
    String compressionMethod = "";
    String encodingMethod = "";
    String quoteCharacter = null;
    String literalCharacter = null;
    boolean isImageEntity = false;
    boolean isOtherEntity = false;
    boolean isGZipDataFile = false;
    boolean isZipDataFile = false;
    boolean isTarDataFile = false;
    boolean isSimpleDelimited = true;
    boolean isCollapseDelimiters = false;
    TextComplexDataFormat[] formatArray = null;

    for (int i = 0; i < entityNodeListLength; i++) {

        if (xpath != null) {
            if (xpath.equals(spatialRasterEntityPath) || xpath.equals(spatialVectorEntityPath)) {
                isImageEntity = true;
            } else if (xpath.equals(otherEntityPath)) {
                isOtherEntity = true;
            }
        }

        //go through the entities and put the information into the hash.
        elementId++;
        Node entityNode = entitiesNodeList.item(i);
        String id = null;
        NamedNodeMap entityNodeAttributes = entityNode.getAttributes();

        if (entityNodeAttributes != null) {
            Node idNode = entityNodeAttributes.getNamedItem(ID);

            if (idNode != null) {
                id = idNode.getNodeValue();
            }
        }

        NodeList entityNodeChildren = entityNode.getChildNodes();

        for (int j = 0; j < entityNodeChildren.getLength(); j++) {
            Node childNode = entityNodeChildren.item(j);
            String childName = childNode.getNodeName();
            String childValue = childNode.getFirstChild() == null ? null
                    : childNode.getFirstChild().getNodeValue();

            if (childName.equals("entityName")) {
                entityName = childValue;
            } else if (childName.equals("entityDescription")) {
                entityDescription = childValue;
            } else if (childName.equals("caseSensitive")) {
                entityCaseSensitive = childValue;
            } else if (childName.equals("numberOfRecords")) {
                entityNumberOfRecords = childValue;
                /*numRecords = (new Integer(entityNumberOfRecords))
                            .intValue();*/
            }

        }

        NodeList attributeOrientationNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/textFormat/attributeOrientation");

        if (attributeOrientationNodeList != null && attributeOrientationNodeList.getLength() > 0) {
            entityOrientation = attributeOrientationNodeList.item(0).getFirstChild().getNodeValue();

        }

        NodeList numHeaderLinesNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/textFormat/numHeaderLines");

        if ((numHeaderLinesNodeList != null) && (numHeaderLinesNodeList.getLength() > 0)) {
            Node numHeaderLinesNode = numHeaderLinesNodeList.item(0);

            if (numHeaderLinesNode != null) {
                numHeaderLines = numHeaderLinesNode.getFirstChild().getNodeValue();
            }
        }

        NodeList numFooterLinesNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/textFormat/numFooterLines");

        if ((numFooterLinesNodeList != null) && (numFooterLinesNodeList.getLength() > 0)) {
            Node numFooterLinesNode = numFooterLinesNodeList.item(0);

            if (numFooterLinesNode != null) {
                String numFooterLinesStr = numFooterLinesNode.getFirstChild().getNodeValue();
                numFooterLines = (new Integer(numFooterLinesStr.trim())).intValue();
            }
        }

        // Here is the simple delimited data file
        NodeList fieldDelimiterNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/textFormat/simpleDelimited/fieldDelimiter");

        if (fieldDelimiterNodeList != null && fieldDelimiterNodeList.getLength() > 0) {
            fieldDelimiter = fieldDelimiterNodeList.item(0).getFirstChild().getNodeValue();
        }

        NodeList collapseDelimitersNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/textFormat/simpleDelimited/collapseDelimiters");

        if (collapseDelimitersNodeList != null && collapseDelimitersNodeList.getLength() > 0) {

            String collapseDelimiters = collapseDelimitersNodeList.item(0).getFirstChild().getNodeValue();

            if (collapseDelimiters.equalsIgnoreCase("yes")) {
                isCollapseDelimiters = true;
            }
        }

        NodeList quoteCharacterNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/textFormat/simpleDelimited/quoteCharacter");

        if (quoteCharacterNodeList != null && quoteCharacterNodeList.getLength() > 0) {
            quoteCharacter = quoteCharacterNodeList.item(0).getFirstChild().getNodeValue();
        }

        NodeList literalCharacterNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/textFormat/simpleDelimited/literalCharacter");

        if (literalCharacterNodeList != null && literalCharacterNodeList.getLength() > 0) {
            literalCharacter = literalCharacterNodeList.item(0).getFirstChild().getNodeValue();
        }

        // For complex format data file
        NodeList complexNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/textFormat/complex");

        if (complexNodeList != null && complexNodeList.getLength() > 0) {
            //log.debug("in handle complex text data format");
            isSimpleDelimited = false;
            Node complexNode = complexNodeList.item(0);
            NodeList complexChildNodes = complexNode.getChildNodes();
            int complexChildNodesLength = complexChildNodes.getLength();
            Vector formatVector = new Vector();

            for (int k = 0; k < complexChildNodesLength; k++) {
                Node complexChildNode = complexChildNodes.item(k);

                if (complexChildNode != null && complexChildNode.getNodeName().equals("textFixed")) {
                    TextWidthFixedDataFormat textWidthFixedDataFormat = handleTextFixedDataFormatNode(
                            complexChildNode);

                    if (textWidthFixedDataFormat != null) {
                        formatVector.add(textWidthFixedDataFormat);
                        //complexFormatsNumber++;
                    }
                } else if (complexChildNode != null && complexChildNode.getNodeName().equals("textDelimited")) {
                    TextDelimitedDataFormat textDelimitedDataFormat = handleComplexDelimitedDataFormatNode(
                            complexChildNode);

                    if (textDelimitedDataFormat != null) {
                        formatVector.add(textDelimitedDataFormat);
                        //complexFormatsNumber++;
                    }
                }
            }

            // Transfer vector to array
            numberOfComplexFormats = formatVector.size();
            formatArray = new TextComplexDataFormat[numberOfComplexFormats];
            for (int j = 0; j < numberOfComplexFormats; j++) {
                formatArray[j] = (TextComplexDataFormat) formatVector.elementAt(j);
            }
        }

        NodeList recordDelimiterNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/textFormat/recordDelimiter");

        if ((recordDelimiterNodeList != null) && (recordDelimiterNodeList.getLength() > 0)) {
            recordDelimiter = recordDelimiterNodeList.item(0).getFirstChild().getNodeValue();
        } else {
            recordDelimiter = "\\r\\n";
        }

        // Get the distribution information
        NodeList urlNodeList = xpathapi.selectNodeList(entityNode, "physical/distribution/online/url");

        if (urlNodeList != null && urlNodeList.getLength() > 0) {
            onlineUrl = urlNodeList.item(0).getFirstChild().getNodeValue();

            if (isDebugging) {
                //log.debug("The url is "+ onlineUrl);
            }
        }

        /**
         * Determine file format (mime)
         * Note: this could be better fleshed out in cases where the delimiter is known
         * 
         * physical/dataFormat/textFormat
         * physical/dataFormat/binaryRasterFormat
         * physical/dataFormat/externallyDefinedFormat/formatName
         */
        NodeList formatNodeList = xpathapi.selectNodeList(entityNode,
                "physical/dataFormat/externallyDefinedFormat/formatName");
        if (formatNodeList != null && formatNodeList.getLength() > 0) {
            format = formatNodeList.item(0).getFirstChild().getNodeValue();
        } else {
            // try binary raster
            formatNodeList = xpathapi.selectNodeList(entityNode, "physical/dataFormat/binaryRasterFormat");
            if (formatNodeList != null && formatNodeList.getLength() > 0) {
                format = "application/octet-stream";
            } else {
                formatNodeList = xpathapi.selectNodeList(entityNode, "physical/dataFormat/textFormat");
                if (formatNodeList != null && formatNodeList.getLength() > 0) {
                    format = "text/plain";
                }
                if (isSimpleDelimited) {
                    format = "text/csv";
                }
            }
        }

        // Get the compressionMethod information
        NodeList compressionMethodNodeList = xpathapi.selectNodeList(entityNode, "physical/compressionMethod");

        if (compressionMethodNodeList != null && compressionMethodNodeList.getLength() > 0) {
            compressionMethod = compressionMethodNodeList.item(0).getFirstChild().getNodeValue();

            if (isDebugging) {
                //log.debug("Compression method is "+compressionMethod);
            }

            if (compressionMethod != null && compressionMethod.equals(Entity.GZIP)) {
                isGZipDataFile = true;
            } else if (compressionMethod != null && compressionMethod.equals(Entity.ZIP)) {
                isZipDataFile = true;
            }
        }

        // Get encoding method info (mainly for tar file)
        NodeList encodingMethodNodeList = xpathapi.selectNodeList(entityNode, "physical/encodingMethod");

        if (encodingMethodNodeList != null && encodingMethodNodeList.getLength() > 0) {
            encodingMethod = encodingMethodNodeList.item(0).getFirstChild().getNodeValue();

            if (isDebugging) {
                //log.debug("encoding method is "+encodingMethod);
            }

            if (encodingMethod != null && encodingMethod.equals(Entity.TAR)) {
                isTarDataFile = true;
            }
        }

        if (entityOrientation.trim().equals("column")) {
            entityOrientation = Entity.COLUMNMAJOR;
        } else {
            entityOrientation = Entity.ROWMAJOR;
        }

        if (entityCaseSensitive.equals("yes")) {
            entityCaseSensitive = "true";
        } else {
            entityCaseSensitive = "false";
        }

        entityObject = new Entity(id, entityName == null ? null : entityName.trim(),
                entityDescription == null ? null : entityDescription.trim(), new Boolean(entityCaseSensitive),
                entityOrientation, new Integer(entityNumberOfRecords).intValue());

        entityObject.setNumHeaderLines((new Integer(numHeaderLines)).intValue());
        entityObject.setNumFooterLines(numFooterLines);
        entityObject.setSimpleDelimited(isSimpleDelimited);

        // For simple delimited data file
        if (fieldDelimiter != null) {
            entityObject.setDelimiter(fieldDelimiter);
        }

        if (quoteCharacter != null) {
            entityObject.setQuoteCharacter(quoteCharacter);
        }

        if (literalCharacter != null) {
            entityObject.setLiteralCharacter(literalCharacter);
        }

        entityObject.setCollapseDelimiters(isCollapseDelimiters);
        entityObject.setRecordDelimiter(recordDelimiter);
        entityObject.setURL(onlineUrl);
        entityObject.setDataFormat(format);
        entityObject.setCompressionMethod(compressionMethod);
        entityObject.setIsImageEntity(isImageEntity);
        entityObject.setIsOtherEntity(isOtherEntity);
        entityObject.setHasGZipDataFile(isGZipDataFile);
        entityObject.setHasZipDataFile(isZipDataFile);
        entityObject.setHasTarDataFile(isTarDataFile);
        entityObject.setPackageId(packageId);

        try {
            NodeList attributeListNodeList = xpathapi.selectNodeList(entityNode, "attributeList");
            processAttributeList(xpathapi, attributeListNodeList, xpath, entityObject);
            entityObject.setDataFormatArray(formatArray);
        } catch (Exception e) {
            throw new Exception("Error parsing attributes: " + e.getMessage(), e);
        }

        //entityHash.put(Integer.toString(elementId), entityObject);
        emlDataPackage.add(entityObject);
        //fileHash.put(elementId, onlineUrl); 
    } // end for loop

}

From source file:com.netscape.cms.servlet.csadmin.ConfigurationUtils.java

public static Vector<String> getUrlListFromSecurityDomain(IConfigStore config, String type, String portType)
        throws Exception {
    Vector<String> v = new Vector<String>();

    String hostname = config.getString("securitydomain.host");
    int httpsadminport = config.getInteger("securitydomain.httpsadminport");

    logger.debug("getUrlListFromSecurityDomain(): Getting domain.xml from CA...");
    String c = getDomainXML(hostname, httpsadminport, true);

    logger.debug("getUrlListFromSecurityDomain: Getting " + portType + " from Security Domain ...");
    if (!portType.equals("UnSecurePort") && !portType.equals("SecureAgentPort")
            && !portType.equals("SecurePort") && !portType.equals("SecureAdminPort")) {
        logger.debug("getUrlListFromSecurityDomain:  " + "unknown port type " + portType);
        return v;
    }/*  www . j ava 2s. c  o  m*/

    ByteArrayInputStream bis = new ByteArrayInputStream(c.getBytes());
    XMLObject parser = new XMLObject(bis);
    Document doc = parser.getDocument();
    NodeList nodeList = doc.getElementsByTagName(type);

    // save domain name in cfg
    config.putString("securitydomain.name", parser.getValue("Name"));

    int len = nodeList.getLength();

    logger.debug("Len " + len);
    for (int i = 0; i < len; i++) {
        Vector<String> v_name = parser.getValuesFromContainer(nodeList.item(i), "SubsystemName");
        Vector<String> v_host = parser.getValuesFromContainer(nodeList.item(i), "Host");
        Vector<String> v_port = parser.getValuesFromContainer(nodeList.item(i), portType);
        Vector<String> v_admin_port = parser.getValuesFromContainer(nodeList.item(i), "SecureAdminPort");

        if (v_host.elementAt(0).equals(hostname)
                && v_admin_port.elementAt(0).equals(new Integer(httpsadminport).toString())) {
            // add security domain CA to the beginning of list
            v.add(0, v_name.elementAt(0) + " - https://" + v_host.elementAt(0) + ":" + v_port.elementAt(0));
        } else {
            v.addElement(v_name.elementAt(0) + " - https://" + v_host.elementAt(0) + ":" + v_port.elementAt(0));
        }
    }

    return v;
}

From source file:com.netscape.cms.servlet.csadmin.ConfigurationUtils.java

public static boolean isSDHostDomainMaster(IConfigStore config) throws Exception {
    String dm = "false";

    String hostname = config.getString("securitydomain.host");
    int httpsadminport = config.getInteger("securitydomain.httpsadminport");

    logger.debug("isSDHostDomainMaster(): Getting domain.xml from CA...");
    String c = getDomainXML(hostname, httpsadminport, true);

    ByteArrayInputStream bis = new ByteArrayInputStream(c.getBytes());
    XMLObject parser = new XMLObject(bis);
    Document doc = parser.getDocument();
    NodeList nodeList = doc.getElementsByTagName("CA");

    int len = nodeList.getLength();
    for (int i = 0; i < len; i++) {
        Vector<String> v_hostname = parser.getValuesFromContainer(nodeList.item(i), "Host");
        Vector<String> v_https_admin_port = parser.getValuesFromContainer(nodeList.item(i), "SecureAdminPort");
        Vector<String> v_domain_mgr = parser.getValuesFromContainer(nodeList.item(i), "DomainManager");

        if (v_hostname.elementAt(0).equals(hostname)
                && v_https_admin_port.elementAt(0).equals(Integer.toString(httpsadminport))) {
            dm = v_domain_mgr.elementAt(0).toString();
            break;
        }/* ww w .  j  a  v a  2s. c  om*/
    }
    return dm.equalsIgnoreCase("true");
}

From source file:io.snappydata.hydra.cluster.SnappyTest.java

protected void executeSparkJob(Vector jobClassNames, String logFileName) {
    String snappyJobScript = getScriptLocation("spark-submit");
    ProcessBuilder pb = null;//  w  w  w  .j av a  2s.  c om
    File log = null, logFile = null;
    userAppJar = SnappyPrms.getUserAppJar();
    snappyTest.verifyDataForJobExecution(jobClassNames, userAppJar);
    try {
        for (int i = 0; i < jobClassNames.size(); i++) {
            String userJob = (String) jobClassNames.elementAt(i);
            String masterHost = getSparkMasterHost();
            String locatorsList = getLocatorsList("locators");
            String command = snappyJobScript + " --class " + userJob + " --master spark://" + masterHost + ":"
                    + MASTER_PORT + " --conf snappydata.store.locators=" + locatorsList + " "
                    + " --conf spark.extraListeners=io.snappydata.hydra.SnappyCustomSparkListener" + " "
                    + snappyTest.getUserAppJarLocation(userAppJar, jarPath) + " " + SnappyPrms.getUserAppArgs();
            Log.getLogWriter().info("spark-submit command is : " + command);
            log = new File(".");
            String dest = log.getCanonicalPath() + File.separator + logFileName;
            logFile = new File(dest);
            pb = new ProcessBuilder("/bin/bash", "-c", command);
            snappyTest.executeProcess(pb, logFile);
            String searchString = "Spark ApplicationEnd: ";
            String expression = "cat " + logFile + " | grep -e Exception -e '" + searchString
                    + "' | grep -v java.net.BindException" + " | wc -l)\"";
            String searchCommand = "while [ \"$(" + expression + " -le  0 ] ; do sleep 1 ; done";
            pb = new ProcessBuilder("/bin/bash", "-c", searchCommand);
            Log.getLogWriter().info("spark job " + userJob + " starts at: " + System.currentTimeMillis());
            executeProcess(pb, logFile);
            Log.getLogWriter().info("spark job " + userJob + " finishes at:  " + System.currentTimeMillis());
        }
    } catch (IOException e) {
        throw new TestException("IOException occurred while retriving destination logFile path " + log
                + "\nError Message:" + e.getMessage());
    }
}

From source file:org.adl.samplerte.server.CourseService.java

/**
 * Returns a list (Vector) of global objectives for the desired user
 * @param iUserID - the desired user//  w  w  w  .j a va  2  s .c  o m
 * @param iObjs - the course specific objectives for the desired user
 * @return List (Vector) of global objectives
 */
public Vector getGlobalObjs(String iUserID, Vector iObjs) {
    Vector obj = iObjs;
    try {
        Connection conn;
        PreparedStatement stmtSelectGlobals;

        conn = LMSDBHandler.getConnection();

        String sqlSelectGlobals = "SELECT * FROM Objectives where " + "learnerID = ? and scopeID = ''";
        stmtSelectGlobals = conn.prepareStatement(sqlSelectGlobals);
        synchronized (stmtSelectGlobals) {
            stmtSelectGlobals.setString(1, iUserID);
        }

        ResultSet globalsRS;

        globalsRS = stmtSelectGlobals.executeQuery();

        boolean foundObjective = false;
        boolean firstQueryEmpty = true;
        while (globalsRS.next()) {
            ObjectivesData od = new ObjectivesData();
            // Process the whitespace of the value because it is of type ID, xs:ID, or IDREF
            od.mObjectiveID = decodeHandler
                    .decodeObjectiveID(decodeHandler.processWhitespace(globalsRS.getString("objID")));

            od.mUserID = globalsRS.getString("learnerID");
            od.mSatisfied = globalsRS.getString("satisfied");
            od.mMeasure = globalsRS.getString("measure");
            od.mRawScore = globalsRS.getString("rawscore");
            od.mMinScore = globalsRS.getString("minscore");
            od.mMaxScore = globalsRS.getString("maxscore");
            od.mProgressMeasure = globalsRS.getString("progressmeasure");
            od.mCompletionStatus = globalsRS.getString("completion");

            if (obj != null) {
                for (int i = 0; i < obj.size(); i++) {
                    firstQueryEmpty = false;
                    ObjectivesData od2 = (ObjectivesData) obj.elementAt(i);
                    if (od.mObjectiveID.equals(od2.mObjectiveID)) {
                        foundObjective = true;
                        break;
                    }
                }
            }
            if (firstQueryEmpty || !foundObjective) {
                obj.add(od);
            }
        }
        globalsRS.close();
        stmtSelectGlobals.close();
        LMSDBHandler.closeConnection();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return obj;
}

From source file:edu.umn.cs.spatialHadoop.core.RTree.java

/**
 * k nearest neighbor query//from w w  w.ja  va 2  s.  c o m
 * @param qx
 * @param qy
 * @param k
 * @param output
 */
public int knn(final double qx, final double qy, int k, final ResultCollector2<T, Double> output) {
    double query_area = ((getMBR().x2 - getMBR().x1) * (getMBR().y2 - getMBR().y1)) * k / getElementCount();
    double query_radius = Math.sqrt(query_area / Math.PI);

    boolean result_correct;
    final Vector<Double> distances = new Vector<Double>();
    final Vector<T> shapes = new Vector<T>();
    // Find results in the range and increase this range if needed to ensure
    // correctness of the answer
    do {
        // Initialize result and query range
        distances.clear();
        shapes.clear();
        Rectangle queryRange = new Rectangle();
        queryRange.x1 = qx - query_radius;
        queryRange.y1 = qy - query_radius;
        queryRange.x2 = qx + query_radius;
        queryRange.y2 = qy + query_radius;
        // Retrieve all results in range
        search(queryRange, new ResultCollector<T>() {
            @Override
            public void collect(T shape) {
                distances.add(shape.distanceTo(qx, qy));
                shapes.add((T) shape.clone());
            }
        });
        if (shapes.size() < k) {
            // Didn't find k elements in range, double the range to get more items
            if (shapes.size() == getElementCount()) {
                // Already returned all possible elements
                result_correct = true;
            } else {
                query_radius *= 2;
                result_correct = false;
            }
        } else {
            // Sort items by distance to get the kth neighbor
            IndexedSortable s = new IndexedSortable() {
                @Override
                public void swap(int i, int j) {
                    double temp_distance = distances.elementAt(i);
                    distances.set(i, distances.elementAt(j));
                    distances.set(j, temp_distance);

                    T temp_shape = shapes.elementAt(i);
                    shapes.set(i, shapes.elementAt(j));
                    shapes.set(j, temp_shape);
                }

                @Override
                public int compare(int i, int j) {
                    // Note. Equality is not important to check because items with the
                    // same distance can be ordered anyway. 
                    if (distances.elementAt(i) == distances.elementAt(j))
                        return 0;
                    if (distances.elementAt(i) < distances.elementAt(j))
                        return -1;
                    return 1;
                }
            };
            IndexedSorter sorter = new QuickSort();
            sorter.sort(s, 0, shapes.size());
            if (distances.elementAt(k - 1) > query_radius) {
                result_correct = false;
                query_radius = distances.elementAt(k);
            } else {
                result_correct = true;
            }
        }
    } while (!result_correct);

    int result_size = Math.min(k, shapes.size());
    if (output != null) {
        for (int i = 0; i < result_size; i++) {
            output.collect(shapes.elementAt(i), distances.elementAt(i));
        }
    }
    return result_size;
}

From source file:edu.lternet.pasta.dml.parser.eml.Eml200Parser.java

private TextDelimitedDataFormat handleComplexDelimitedDataFormatNode(Node node) throws Exception {
    TextDelimitedDataFormat textDelimitedDataFormat = null;

    if (node == null) {
        return textDelimitedDataFormat;
    }//from  w  w  w.j  av  a  2 s  .  c  o  m

    NodeList childNodes = node.getChildNodes();
    int length = childNodes.getLength();
    Vector quoteList = new Vector();

    for (int i = 0; i < length; i++) {
        Node childNode = childNodes.item(i);
        String elementName = childNode.getNodeName();

        if (elementName != null && elementName.equals("fieldDelimiter")) {
            String fieldDelimiter = childNode.getFirstChild().getNodeValue();

            if (isDebugging) {
                //log.debug("The field delimiter for complex format in eml is " +
                //          fieldDelimiter);
            }

            textDelimitedDataFormat = new TextDelimitedDataFormat(fieldDelimiter);
        } else if (elementName != null && elementName.equals("lineNumber") && textDelimitedDataFormat != null) {
            String lineNumberStr = childNode.getFirstChild().getNodeValue();
            int lineNumber = (new Integer(lineNumberStr)).intValue();

            if (isDebugging) {
                //log.debug("The line number is " + lineNumber);
            }

            textDelimitedDataFormat.setLineNumber(lineNumber);
        } else if (elementName != null && elementName.equals("collapseDelimiters")
                && textDelimitedDataFormat != null) {
            String collapseDelimiters = childNode.getFirstChild().getNodeValue();

            if (isDebugging) {
                //log.debug("The collapse delimiter: " + collapse);
            }

            textDelimitedDataFormat.setCollapseDelimiters(collapseDelimiters);
        } else if (elementName != null && elementName.equals("quoteCharacter")
                && textDelimitedDataFormat != null) {
            String quoteCharacter = childNode.getFirstChild().getNodeValue();
            quoteList.add(quoteCharacter);
        }
    } // end for loop

    // set up quoteList
    if (textDelimitedDataFormat != null) {
        int size = quoteList.size();
        String[] quoteCharacterArray = new String[size];

        for (int i = 0; i < size; i++) {
            quoteCharacterArray[i] = (String) quoteList.elementAt(i);
        }

        textDelimitedDataFormat.setQuoteCharacterArray(quoteCharacterArray);
    }

    return textDelimitedDataFormat;
}

From source file:io.snappydata.hydra.cluster.SnappyTest.java

protected void executeSnappyStreamingJobUsingJobScript(Vector jobClassNames, String logFileName) {
    String snappyJobScript = getScriptLocation("snappy-job.sh");
    ProcessBuilder pb = null;/*ww  w  .j av  a 2  s.  c  o m*/
    File log = null;
    File logFile = null;
    userAppJar = SnappyPrms.getUserAppJar();
    snappyTest.verifyDataForJobExecution(jobClassNames, userAppJar);
    leadHost = getLeadHost();
    String leadPort = (String) SnappyBB.getBB().getSharedMap().get("primaryLeadPort");
    try {
        for (int i = 0; i < jobClassNames.size(); i++) {
            String userJob = (String) jobClassNames.elementAt(i);
            pb = new ProcessBuilder(snappyJobScript, "submit", "--lead", leadHost + ":" + leadPort,
                    "--app-name", "myapp", "--class", userJob, "--app-jar",
                    snappyTest.getUserAppJarLocation(userAppJar, jarPath), "--stream");
            java.util.Map<String, String> env = pb.environment();
            if (SnappyPrms.getCommaSepAPPProps() == null) {
                env.put("APP_PROPS", "shufflePartitions=" + SnappyPrms.getShufflePartitions());
            } else {
                env.put("APP_PROPS", SnappyPrms.getCommaSepAPPProps() + ",shufflePartitions="
                        + SnappyPrms.getShufflePartitions());
            }
            log = new File(".");
            String dest = log.getCanonicalPath() + File.separator + logFileName;
            logFile = new File(dest);
            snappyTest.executeProcess(pb, logFile);
        }
        snappyTest.getSnappyJobsStatus(snappyJobScript, logFile, leadPort);
    } catch (IOException e) {
        throw new TestException("IOException occurred while retriving destination logFile path " + log
                + "\nError Message:" + e.getMessage());
    }
}

From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java

/**
 * @see de.juwimm.cms.remote.ViewServiceSpring#getParents4ViewComponent(java.lang.Integer)
 *///  w  w  w  .j a v a  2 s .c om
@Override
protected Integer[] handleGetParents4ViewComponent(Integer viewComponentId) throws Exception {
    try {
        ViewComponentHbm view = super.getViewComponentHbmDao().load(viewComponentId);
        Vector<Integer> vec = new Vector<Integer>();
        Vector<Integer> topDown = new Vector<Integer>();
        ViewComponentHbm parentView = view;
        while ((parentView = parentView.getParent()) != null) {
            vec.addElement(parentView.getViewComponentId());
        }
        for (int i = vec.size() - 1; i > -1; i--) {
            topDown.addElement(vec.elementAt(i));
        }
        return topDown.toArray(new Integer[0]);
    } catch (Exception e) {
        throw new UserException(e.getMessage());
    }
}