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:nzilbb.agcsv.AgCsvDeserializer.java

/**
 * Create annotations from the given CSV rows.
 * @param lines CSV records./*from   ww  w  . j av  a 2 s. c  o m*/
 * @param layer Layer for the annotations.
 * @param graph Graph to add the annotations to.
 * @throws SerializationException On error.
 */
public void readAnnotations(Vector<CSVRecord> lines, Layer layer, Graph graph) throws SerializationException {
    // map header columns
    HashMap<String, Integer> mHeadings = new HashMap<String, Integer>();
    for (int c = 0; c < lines.elementAt(1).size(); c++) {
        String sHeader = lines.elementAt(1).get(c);
        if (sHeader.equalsIgnoreCase("id"))
            mHeadings.put("id", c);
        else if (sHeader.equalsIgnoreCase("startAnchor.id"))
            mHeadings.put("startAnchor.id", c);
        else if (sHeader.equalsIgnoreCase("endAnchor.id"))
            mHeadings.put("endAnchor.id", c);
        else if (sHeader.equalsIgnoreCase("label"))
            mHeadings.put("label", c);
        else if (sHeader.equalsIgnoreCase("labelStatus"))
            mHeadings.put("labelStatus", c);
        else if (sHeader.equalsIgnoreCase("turnAnnotationId"))
            mHeadings.put("turnAnnotationId", c);
        else if (sHeader.equalsIgnoreCase("ordinalInTurn"))
            mHeadings.put("ordinalInTurn", c);
        else if (sHeader.equalsIgnoreCase("wordAnnotationId"))
            mHeadings.put("wordAnnotationId", c);
        else if (sHeader.equalsIgnoreCase("ordinalInWord"))
            mHeadings.put("ordinalInWord", c);
        else if (sHeader.equalsIgnoreCase("segmentAnnotationId"))
            mHeadings.put("segmentAnnotationId", c);
    } // next header
    int highestHeaderIndex = 0;
    for (Integer i : mHeadings.values())
        highestHeaderIndex = Math.max(highestHeaderIndex, i);
    mHeadings.put("comment", highestHeaderIndex + 1);

    for (int i = 2; i < lines.size(); i++) {
        CSVRecord line = lines.elementAt(i);
        Annotation annotation = new Annotation(line.get(mHeadings.get("id")), line.get(mHeadings.get("label")),
                layer.getId(), line.get(mHeadings.get("startAnchor.id")),
                line.get(mHeadings.get("endAnchor.id")));
        annotation.setConfidence(new Integer(line.get(mHeadings.get("labelStatus"))));
        if (mHeadings.get("comment") < line.size()) {
            String comment = line.get(mHeadings.get("comment"));
            if (comment.length() > 0) {
                annotation.put("comment", comment);
            }
        }

        // parent
        if (layer.getParentId().equals("graph")) {
            annotation.setParentId(graph.getId());
        } else if (layer.getParentId().equals(graph.getSchema().getTurnLayerId())) {
            if (layer.getId().equals(graph.getSchema().getUtteranceLayerId())) {
                // make sure turn exists
                Annotation turn = graph.getAnnotation(line.get(mHeadings.get("turnAnnotationId")));
                if (turn == null) {

                    // make sure participant exists
                    Annotation participant = graph.getAnnotation(annotation.getLabel());
                    if (participant == null) {
                        participant = new Annotation(annotation.getLabel(), annotation.getLabel(),
                                graph.getSchema().getParticipantLayerId());
                        graph.addAnnotation(participant);
                    }

                    turn = new Annotation(line.get(mHeadings.get("turnAnnotationId")), annotation.getLabel(),
                            graph.getSchema().getTurnLayerId(),
                            // start/end IDs are set, but the anchor's themselves aren't added
                            line.get(mHeadings.get("turnAnnotationId")) + " start",
                            line.get(mHeadings.get("turnAnnotationId")) + " end", participant.getId());
                    graph.addAnnotation(turn);
                } // turn isn't there
            } // utterance layer
            annotation.setParentId(line.get(mHeadings.get("turnAnnotationId")));
        } else if (layer.getParentId().equals(graph.getSchema().getWordLayerId())) {
            annotation.setParentId(line.get(mHeadings.get("wordAnnotationId")));
        } else if (layer.getParentId().equals("segments")) {
            annotation.setParentId(line.get(mHeadings.get("segmentAnnotationId")));
        } else if (layer.getId().equals(graph.getSchema().getTurnLayerId())) { // turn layer
                                                                               // make sure participant exists
            Annotation participant = graph.getAnnotation(annotation.getLabel());
            if (participant == null) {
                participant = new Annotation(annotation.getLabel(), annotation.getLabel(),
                        graph.getSchema().getParticipantLayerId());
                graph.addAnnotation(participant);
            }
            annotation.setParentId(participant.getId());
        }

        // ordinal
        if (layer.getId().equals(graph.getSchema().getWordLayerId())) {
            annotation.setOrdinal(Integer.parseInt(line.get(mHeadings.get("ordinalInTurn"))));
        } else if (layer.getId().equals("segments")) {
            annotation.setOrdinal(Integer.parseInt(line.get(mHeadings.get("ordinalInWord"))));
        }
        graph.addAnnotation(annotation);
    }
}

From source file:mekhq.Utilities.java

public static int roll3d6() {
    Vector<Integer> rolls = new Vector<Integer>();
    rolls.add(Compute.d6());/*from   www.  j a  va 2  s. c om*/
    rolls.add(Compute.d6());
    rolls.add(Compute.d6());
    Collections.sort(rolls);
    return (rolls.elementAt(0) + rolls.elementAt(1));
}

From source file:ipnat.skel.Strahler.java

@Override
public boolean dialogItemChanged(final GenericDialog gd, final java.awt.AWTEvent e) {

    protectRoot = gd.getNextBoolean();//  w  w  w. ja v a2 s .  co  m
    erodeIsolatedPixels = gd.getNextBoolean();
    pruneChoice = gd.getNextChoiceIndex();
    grayscaleImpChoice = gd.getNextChoiceIndex();
    outIS = gd.getNextBoolean();
    verbose = gd.getNextBoolean();
    tabular = gd.getNextBoolean();

    // Enable/Disable key components of GenericDialog
    if (!IJ.macroRunning()) {
        final Choice cImgChoice = (Choice) gd.getChoices().elementAt(1);
        final Vector<?> checkboxes = gd.getCheckboxes();
        final Checkbox roiOption = (Checkbox) checkboxes.elementAt(0);
        final Checkbox stackOption = (Checkbox) checkboxes.elementAt(2);

        cImgChoice.setEnabled(pruneChoice == AnalyzeSkeleton_.LOWEST_INTENSITY_VOXEL
                || pruneChoice == AnalyzeSkeleton_.LOWEST_INTENSITY_BRANCH);
        roiOption.setEnabled(validRootRoi);
        stackOption.setEnabled(!tabular);

    }

    return !gd.wasCanceled();

}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java

@SuppressWarnings("unchecked")
public void queryChanged(String newQuery) {

    lastExecution++;//from  w w w .j  a  v  a2  s  . c om
    int thisExecution = lastExecution;
    // Execute a thread to perform the query change...

    String error_msg = "";
    lastExecution++;

    int in = lastExecution;

    if (getReportQueryDialog() == null)
        return;

    getReportQueryDialog().getJLabelStatusSQL().setText(I18n.getString("BeanInspectorPanel.Label.StatusSQL"));
    /////////////////////////////

    try {
        Thread.currentThread().setContextClassLoader(IReportManager.getInstance().getReportClassLoader());
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    if (in < lastExecution)
        return; //Abort, new execution requested

    HQLFieldsReader hqlFR = new HQLFieldsReader(newQuery,
            getReportQueryDialog().getDataset().getParametersList());

    if (in < lastExecution)
        return; //Abort, new execution requested

    try {
        Vector fields = hqlFR.readFields();

        List columns = new ArrayList();
        for (int i = 0; i < fields.size(); ++i) {
            JRDesignField field = (JRDesignField) fields.elementAt(i);
            columns.add(new Object[] { field, field.getValueClassName(), field.getDescription() });
        }

        Vector v = hqlFR.getNotScalars();

        if (v.size() == 0)
            v = null;

        if (in < lastExecution)
            return; //Abort, new execution requested
        setBeanExplorerFromWorker(v, true, true);

        if (in < lastExecution)
            return; //Abort, new execution requested
        setColumnsFromWorker(columns);

    } catch (Exception ex) {
        ex.printStackTrace();
        setBeanExplorerFromWorker(null, true, true);
        setColumnErrorFromWork(I18n.getString("BeanInspectorPanel.Message.Error3") + ex.getMessage());
    }

    getReportQueryDialog().getJLabelStatusSQL()
            .setText(I18n.getString("BeanInspectorPanel.Message.StatusSQL2"));
}

From source file:org.gbif.portal.registration.UDDIUtils.java

/**
 * Updates the resource given, which must have the UUID set or it'll be a create
 * TODO Fill in the rest of the details/*from  w  w w  . j a v  a2s  .com*/
 * @param resource To update
 * @param businessKey To update
 * @throws TransportException On uddi communication error - e.g. server down
 * @throws UDDIException  On uddi communication error - e.g. bad data
 */
@SuppressWarnings("unchecked")
public void updateResource(ResourceDetail resource, String businessKey)
        throws UDDIException, TransportException {
    BusinessService bs = new BusinessService();
    bs.setBusinessKey(businessKey);
    bs.setServiceKey(resource.getServiceKey());
    bs.setDefaultDescriptionString(resource.getDescription());
    bs.setDefaultNameString(resource.getName(), "en");
    bs.setDefaultName(new Name(resource.getName()));

    AuthToken authToken = uddiProxy.get_authToken(getUddiAuthUser(), getUddiAuthPassword());

    //create business service vector
    Vector businessServiceVector = new Vector();
    businessServiceVector.add(bs);

    //add other properties into a category bag
    CategoryBag cb = new CategoryBag();
    try {
        Map<String, Object> properties = BeanUtils.describe(resource);

        for (String key : properties.keySet()) {
            Object property = properties.get(key);
            PropertyDescriptor pd = org.springframework.beans.BeanUtils
                    .getPropertyDescriptor(ResourceDetail.class, key);
            Class propertyType = pd.getPropertyType();
            if (property != null) {
                if (property instanceof List) {
                    List propertyList = (List) property;
                    for (Object listItem : propertyList) {
                        if (listItem != null)
                            addToCategoryBagIfNotNull(cb, key, listItem.toString());
                    }
                } else if (propertyType.equals(Date.class)) {
                    SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
                    Method readMethod = pd.getReadMethod();
                    Date theDate = (Date) readMethod.invoke(resource, (Object[]) null);
                    if (theDate != null) {
                        addToCategoryBagIfNotNull(cb, key, sdf.format(theDate));
                    }
                } else {
                    addToCategoryBagIfNotNull(cb, key, property.toString());
                }
            }
        }

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    bs.setCategoryBag(cb);

    logger.info("About to save...");
    ServiceDetail sd = getUddiProxy().save_service(authToken.getAuthInfoString(), businessServiceVector);

    // set in the resource serviceKey if required
    Vector<BusinessService> resultVector = sd.getBusinessServiceVector();
    AccessPoint ap = null;
    BindingTemplate bt = null;
    BindingTemplates bts = null;
    for (BusinessService rbs : resultVector) {
        logger.info("Setting the service key (should be once): " + rbs.getServiceKey());
        resource.setServiceKey(rbs.getServiceKey());

        bts = rbs.getBindingTemplates();
        if (bts != null && bts.size() > 0) {
            bt = rbs.getBindingTemplates().get(0);
            ap = bt.getAccessPoint();
        }
        break;
    }

    //if there are no binding templates, then add them
    if (bts == null || bts.size() == 0) {

        // Saving TModel
        TModelDetail tModelDetail = null;
        TModelList tModelList = getUddiProxy().find_tModel(resource.getResourceType(), null, null, null, 1);
        if (tModelList.getTModelInfos().size() == 0) {
            //save this new tmodel
            Vector tModels = new Vector();
            TModel newTModel = new TModel("", resource.getResourceType());
            tModels.add(newTModel);
            tModelDetail = getUddiProxy().save_tModel(authToken.getAuthInfoString(), tModels);
        } else {
            TModelInfo tModelInfo = tModelList.getTModelInfos().get(0);
            tModelDetail = getUddiProxy().get_tModelDetail(tModelInfo.getTModelKey());
        }

        // Creating TModelInstanceDetails
        Vector tModelVector = tModelDetail.getTModelVector();
        String tModelKey = ((TModel) (tModelVector.elementAt(0))).getTModelKey();
        Vector tModelInstanceInfoVector = new Vector();
        TModelInstanceInfo tModelInstanceInfo = new TModelInstanceInfo(tModelKey);
        tModelInstanceInfoVector.add(tModelInstanceInfo);

        TModelInstanceDetails tModelInstanceDetails = new TModelInstanceDetails();
        tModelInstanceDetails.setTModelInstanceInfoVector(tModelInstanceInfoVector);
        Vector bindingTemplatesVector = new Vector();

        // Create a new binding templates using required elements constructor
        // BindingKey must be "" to save a new binding
        BindingTemplate bindingTemplate = new BindingTemplate("", tModelInstanceDetails,
                new AccessPoint(resource.getAccessPoint(), "http"));
        bindingTemplate.setServiceKey(resource.getServiceKey());
        bindingTemplatesVector.addElement(bindingTemplate);

        // **** Save the Binding Template
        BindingDetail bindingDetail = getUddiProxy().save_binding(authToken.getAuthInfoString(),
                bindingTemplatesVector);
    }

    logger.info("Save completed for " + resource.getName());
}

From source file:org.hyperic.util.exec.Execute.java

/**
 * Patch the current environment with the new values from the user.
 * @return the patched environment//from   w  ww  . j  a va 2  s. co  m
 */
private String[] patchEnvironment() {
    Vector osEnv = (Vector) getProcEnvironment().clone();
    for (int i = 0; i < env.length; i++) {
        int pos = env[i].indexOf('=');
        // Get key including "="
        String key = env[i].substring(0, pos + 1);
        int size = osEnv.size();
        for (int j = 0; j < size; j++) {
            if (((String) osEnv.elementAt(j)).startsWith(key)) {
                osEnv.removeElementAt(j);
                break;
            }
        }
        osEnv.addElement(env[i]);
    }
    String[] result = new String[osEnv.size()];
    osEnv.copyInto(result);
    return result;
}

From source file:org.ecoinformatics.seek.ecogrid.EcogridPreferencesTab.java

/**
 * Description of the Method/* ww  w. java2 s  . c o m*/
 */
private void initOriginalServiceList() {
    Vector serviceList = controller.getServicesList();
    if (serviceList != null) {

        int size = serviceList.size();
        for (int i = 0; i < size; i++) {
            SelectableEcoGridService service = (SelectableEcoGridService) serviceList.elementAt(i);
            try {
                SelectableEcoGridService newServcie = SelectableEcoGridService
                        .copySelectableEcoGridService(service);
                originalServiceList.add(newServcie);

            } catch (Exception e) {
                log.debug("Error for copy a servie in initOrignialServiceList ", e);
            }

        }
    }
}

From source file:no.ntnu.idi.dm.clustering.KMeans.java

/**
 * Searches for clusters which have no instances assigned. These are then
 * removed/*from  w  w  w  .  j  av a2 s .com*/
 */
private void removeEmptyClusters() {
    Vector<Cluster> nonEmptyClusters = new Vector<Cluster>();
    for (Cluster cluster : clusters) {
        if (cluster.getNumberOfInstances() != 0) {
            nonEmptyClusters.add(cluster);
        }
    }
    Cluster[] remainingClusters = new Cluster[nonEmptyClusters.size()];
    for (int i = 0; i < nonEmptyClusters.size(); i++) {
        remainingClusters[i] = nonEmptyClusters.elementAt(i);
    }
    clusters = remainingClusters;
}

From source file:org.ecoinformatics.seek.ecogrid.EcoGridServicesController.java

private static DocumentType[] transferRegDocTypeArray(RegistryEntryTypeDocumentType[] regTypeList)
        throws Exception {
    DocumentType[] docTypeList = null;
    if (regTypeList == null) {
        return docTypeList;
    } // if/*from w  w  w  .  jav  a2  s  .c om*/
    int length = regTypeList.length;
    Vector tmp = new Vector();
    for (int i = 0; i < length; i++) {
        RegistryEntryTypeDocumentType regDocType = regTypeList[i];
        String namespace = regDocType.getNamespace();
        String label = regDocType.getLabel();
        try {
            DocumentType type = new DocumentType(namespace, label);
            tmp.add(type);
        } catch (Exception e) {
            log.debug("Could not create document type ", e);
            throw e;
        }
    } // for
      // transfer the tmp vector to an array
    int size = tmp.size();
    docTypeList = new DocumentType[size];
    for (int i = 0; i < size; i++) {
        docTypeList[i] = (DocumentType) tmp.elementAt(i);
    } // for
    return docTypeList;
}

From source file:org.apache.tomcat.util.compat.JdkCompat.java

/**
 * Splits a string into it's components.
 * @param path String to split// w  w w  .  j  a v  a 2  s  . c  o m
 * @param pat Pattern to split at
 * @return the components of the path
 */
public String[] split(String path, String pat) {
    Vector comps = new Vector();
    int pos = path.indexOf(pat);
    int start = 0;
    while (pos >= 0) {
        if (pos > start) {
            String comp = path.substring(start, pos);
            comps.add(comp);
        }
        start = pos + pat.length();
        pos = path.indexOf(pat, start);
    }
    if (start < path.length()) {
        comps.add(path.substring(start));
    }
    String[] result = new String[comps.size()];
    for (int i = 0; i < comps.size(); i++) {
        result[i] = (String) comps.elementAt(i);
    }
    return result;
}