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:edu.mayo.informatics.lexgrid.convert.directConversions.obo1_2.OBO2LGDynamicMapHolders.java

private void addOBODbxrefAsSource(Property prop, Vector<OBODbxref> srcVector, OBOAbbreviations abbreviations) {
    if ((srcVector != null) && (srcVector.size() > 0)) {
        for (int i = 0; i < srcVector.size(); i++) {
            OBODbxref dbxref = srcVector.elementAt(i);
            String src = dbxref.getSource();
            OBOAbbreviation abb = null;/*w  ww.  jav  a 2 s . c o  m*/
            if (!OBO2LGUtils.isNull(src)) {
                String srcVal = src;

                if (abbreviations != null) {
                    abb = getAbbreviationByCodeOrURL(abbreviations, src);
                    if ((abb != null) && (!OBO2LGUtils.isNull(abb.getAbbreviation())))
                        srcVal = abb.getAbbreviation();
                }

                Source s = new Source();
                if (srcVal.length() > 250) {
                    messages_.warn("Property name: "
                            + (prop.getPropertyName() == null ? "MISSING" : prop.getPropertyName()) + " value: "
                            + (prop.getValue().getContent() == null ? "MISSING" : prop.getValue().getContent())
                            + " source too long for storage: " + srcVal + " Truncating to 250 characters");
                    srcVal = srcVal.substring(0, 237) + "(TRUNCATED!)";
                }
                s.setContent(srcVal);
                if (StringUtils.isNotBlank(dbxref.getSubrefAndDescription())) {
                    s.setSubRef(dbxref.getSubrefAndDescription());
                }
                prop.getSourceAsReference().add(s);

                if (abb == null) {
                    abb = new OBOAbbreviation();
                    abb.abbreviation = srcVal;
                    abb.genericURL = srcVal;
                }
                addSource(abb);
            }
        }
    }
}

From source file:org.globus.security.gridmap.GridMap.java

/**
 * Returns all globus IDs associated with the
 * specified local user name./* ww w. j a va  2  s  .  co  m*/
 *
 * @param userID local user name
 * @return associated globus ID, null
 *         if there is not any.
 */
public String[] getAllGlobusID(String userID) {
    if (userID == null) {
        throw new IllegalArgumentException("userID is null");
    }

    if (this.map == null) {
        return null;
    }

    Vector v = new Vector();

    Iterator iter = this.map.entrySet().iterator();
    Map.Entry mapEntry;
    GridMapEntry entry;
    while (iter.hasNext()) {
        mapEntry = (Map.Entry) iter.next();
        entry = (GridMapEntry) mapEntry.getValue();
        if (entry.containsUserID(userID)) {
            v.add(entry.getGlobusID());
        }
    }

    // create array of strings and add values back in
    if (v.size() == 0) {
        return null;
    }

    String idS[] = new String[v.size()];
    for (int ctr = 0; ctr < v.size(); ctr++) {
        idS[ctr] = (String) v.elementAt(ctr);
    }

    return idS;
}

From source file:org.bench4Q.agent.rbe.EB.java

/**
 * @param state// www  .java  2 s  .c  o m
 * @param url
 * @return bolean
 */
public boolean getHTML(int state, String url) {
    double tolerance = tolerance(curState);
    html = "";
    int statusCode;
    GetMethod httpget = new GetMethod(url);
    httpget.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    if (tolerance != 0) {
        httpget.getParams().setSoTimeout((int) (tolerance * 1000));
    }

    try {
        statusCode = HttpClientFactory.getInstance().executeMethod(httpget);

        if (statusCode != HttpStatus.SC_OK) {
            EBStats.getEBStats().error(state, "HTTP response ERROR: " + statusCode, url);
            return false;
        }
        BufferedReader bin = new BufferedReader(new InputStreamReader(httpget.getResponseBodyAsStream()));
        StringBuilder result = new StringBuilder();
        String s;
        while ((s = bin.readLine()) != null) {
            result.append(s);
        }
        html = new String(result);
    } catch (Exception e) {
        EBStats.getEBStats().error(state, "get methed ERROR.", url);
        return false;
    } finally {
        // always release the connection after we're done
        httpget.releaseConnection();
    }

    if (!m_args.isGetImage()) {
        return true;
    }
    Vector<ImageReader> imageRd = new Vector<ImageReader>(0);
    URL u;
    try {
        u = new URL(url);
    } catch (MalformedURLException e) {
        EBStats.getEBStats().error(state, "get image ERROR.", url);
        return false;
    }
    findImg(html, u, imgPat, srcPat, quotePat, imageRd);
    findImg(html, u, inputPat, srcPat, quotePat, imageRd);
    while (imageRd.size() > 0) {
        int max = imageRd.size();
        int min = Math.max(max - RBEUtil.maxImageRd, 0);
        int i;
        try {
            for (i = min; i < max; i++) {
                ImageReader rd = (ImageReader) imageRd.elementAt(i);
                if (!rd.readImage(state)) {
                    imageRd.removeElementAt(i);
                    i--;
                    max--;
                }
            }
        } catch (InterruptedException inte) {
            EBStats.getEBStats().error(state, "get image ERROR.", url);
            return true;
        }
    }

    return true;
}

From source file:alice.tuprolog.lib.OOLibrary.java

private static Constructor<?> mostSpecificConstructor(Vector<Constructor<?>> constructors)
        throws NoSuchMethodException {
    for (int i = 0; i != constructors.size(); i++) {
        for (int j = 0; j != constructors.size(); j++) {
            if ((i != j) && (moreSpecific(constructors.elementAt(i), constructors.elementAt(j)))) {
                constructors.removeElementAt(j);
                if (i > j)
                    i--;/*from ww w . j  a va  2s .co  m*/
                j--;
            }
        }
    }
    if (constructors.size() == 1)
        return constructors.elementAt(0);
    else
        throw new NoSuchMethodException(">1 most specific constructor");
}

From source file:net.aepik.alasca.core.ldap.Schema.java

/**
 * Retourne l'ensemble des syntaxes connues, qui sont
 * contenues dans le package 'ldap.syntax'.
 * @return String[] L'ensemble des noms de classes de syntaxes.
 *///from  ww w.j av a 2 s.c o m
public static String[] getSyntaxes() {
    String[] result = null;
    try {
        String packageName = getSyntaxPackageName();
        URL url = Schema.class.getResource("/" + packageName.replace('.', '/'));
        if (url == null) {
            return null;
        }
        if (url.getProtocol().equals("jar")) {
            Vector<String> vectTmp = new Vector<String>();
            int index = url.getPath().indexOf('!');
            String path = URLDecoder.decode(url.getPath().substring(index + 1), "UTF-8");
            JarFile jarFile = new JarFile(URLDecoder.decode(url.getPath().substring(5, index), "UTF-8"));
            if (path.charAt(0) == '/') {
                path = path.substring(1);
            }
            Enumeration<JarEntry> jarFiles = jarFile.entries();
            while (jarFiles.hasMoreElements()) {
                JarEntry tmp = jarFiles.nextElement();
                //
                // Pour chaque fichier dans le jar, on regarde si c'est un
                // fichier de classe Java.
                //
                if (!tmp.isDirectory() && tmp.getName().substring(tmp.getName().length() - 6).equals(".class")
                        && tmp.getName().startsWith(path)) {
                    int i = tmp.getName().lastIndexOf('/');
                    String classname = tmp.getName().substring(i + 1, tmp.getName().length() - 6);
                    vectTmp.add(classname);
                }
            }
            jarFile.close();
            result = new String[vectTmp.size()];
            for (int i = 0; i < vectTmp.size(); i++) {
                result[i] = vectTmp.elementAt(i);
            }
        } else if (url.getProtocol().equals("file")) {
            //
            // On cr le fichier associ pour parcourir son contenu.
            // En l'occurence, c'est un dossier.
            //
            File[] files = (new File(url.toURI())).listFiles();
            //
            // On liste tous les fichiers qui sont dedans.
            // On les stocke dans un vecteur ...
            //
            Vector<File> vectTmp = new Vector<File>();
            for (File f : files) {
                if (!f.isDirectory()) {
                    vectTmp.add(f);
                }
            }
            //
            // ... pour ensuite les mettres dans le tableau de resultat.
            //
            result = new String[vectTmp.size()];
            for (int i = 0; i < vectTmp.size(); i++) {
                String name = vectTmp.elementAt(i).getName();
                int a = name.indexOf('.');
                name = name.substring(0, a);
                result[i] = name;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (result != null) {
        Arrays.sort(result);
    }
    return result;
}

From source file:com.duroty.utils.mail.MessageUtilities.java

public static void attach(MimeMultipart multipart, Vector attachments, String charset)
        throws MessagingException {
    for (int xindex = 0; xindex < attachments.size(); xindex++) {
        Object xobject = attachments.elementAt(xindex);

        // attach based on type of object
        if (xobject instanceof Part) {
            attach(multipart, (Part) xobject, charset);
        } else if (xobject instanceof File) {
            attach(multipart, (File) xobject, charset);
        } else if (xobject instanceof String) {
            attach(multipart, (String) xobject, charset, Part.ATTACHMENT, false);
        } else if (xobject instanceof vCard) {
            attach(multipart, (vCard) xobject, charset);
        } else {//from w  ww  . j a va  2 s  . c  o m
            throw new MessagingException("Cannot attach objects of type " + xobject.getClass().getName());
        }
    }
}

From source file:org.ecoinformatics.seek.datasource.EcogridCompressedDataCacheItem.java

/**
 * This method will get a file path which matches the given file extension
 * in unzipped file list. If no match, null will be returned
 * /*  ww  w  .ja va 2  s  .com*/
 * @param fileExtension
 *            String
 * @return String[]
 */
public String[] getUnzippedFilePath(String fileExtension) {
    String[] result = null;
    if (unCompressedFileList == null || fileExtension == null) {
        return result;
    }
    int length = unCompressedFileList.length;
    Vector tmp = new Vector();
    for (int i = 0; i < length; i++) {
        String fileName = (String) unCompressedFileList[i];
        if (fileName != null) {
            log.debug("file name in file list is " + fileName);
            int dotPosition = fileName.lastIndexOf(FILEEXTENSIONSEP);
            String extension = fileName.substring(dotPosition + 1, fileName.length());
            log.debug("The file extension for file name " + fileName + " in file list is " + extension);
            if (extension.equals(fileExtension)) {
                // store the file path into a tmp array
                tmp.add(unCompressedFilePath + File.separator + fileName);
            }
        }
    }
    // transfer vector in array
    if (!tmp.isEmpty()) {
        int len = tmp.size();
        result = new String[len];
        for (int j = 0; j < len; j++) {
            result[j] = (String) tmp.elementAt(j);
            log.debug("The file path which math file extension " + fileExtension + " is " + result[j]);
        }
    }
    return result;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetSubjectsIdListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setSubjectsIdUI.getValues();
    Vector<String> samples = this.setSubjectsIdUI.getSamples();
    for (String v : values) {
        if (v.compareTo("") == 0) {
            this.setSubjectsIdUI.displayMessage("All identifiers have to be set");
            return;
        }/*  ww  w.  j  a v a  2  s .  com*/
    }

    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

        File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
        if (stsmf == null) {
            for (int i = 0; i < samples.size(); i++) {
                out.write(this.dataType.getStudy().toString() + "\t" + "\t" + values.elementAt(i) + "\t"
                        + samples.elementAt(i) + "\t" + "\t" + "\t" + "\t" + "\t" + "\n");
            }
        } else {
            try {
                BufferedReader br = new BufferedReader(new FileReader(stsmf));
                String line = br.readLine();
                while ((line = br.readLine()) != null) {
                    String[] fields = line.split("\t", -1);
                    String sample = fields[3];
                    String subject;
                    if (samples.contains(sample)) {
                        subject = values.get(samples.indexOf(sample));
                    } else {
                        br.close();
                        return;
                    }
                    out.write(fields[0] + "\t" + fields[1] + "\t" + subject + "\t" + sample + "\t" + fields[4]
                            + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
                }
                br.close();
            } catch (Exception e) {
                this.setSubjectsIdUI.displayMessage("File error: " + e.getLocalizedMessage());
                out.close();
                e.printStackTrace();
            }
        }
        out.close();
        try {
            File fileDest;
            if (stsmf != null) {
                String fileName = stsmf.getName();
                stsmf.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
        } catch (IOException ioe) {
            this.setSubjectsIdUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setSubjectsIdUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setSubjectsIdUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
    UsedFilesPart.sendFilesChanged(dataType);
}

From source file:org.globus.gsi.gridmap.GridMap.java

/**
 * Returns all globus IDs associated with the
 * specified local user name.//from  w w  w  . jav  a 2 s  .c  om
 *
 * @param userID local user name
 * @return associated globus ID, null
 *         if there is not any.
 */
public String[] getAllGlobusID(String userID) {
    if (userID == null) {
        throw new IllegalArgumentException(i18n.getMessage("userIdNull"));
    }

    if (this.map == null) {
        return null;
    }

    Vector v = new Vector();

    Iterator iter = this.map.entrySet().iterator();
    Map.Entry mapEntry;
    GridMapEntry entry;
    while (iter.hasNext()) {
        mapEntry = (Map.Entry) iter.next();
        entry = (GridMapEntry) mapEntry.getValue();
        if (entry.containsUserID(userID)) {
            v.add(entry.getGlobusID());
        }
    }

    // create array of strings and add values back in
    if (v.size() == 0) {
        return null;
    }

    String idS[] = new String[v.size()];
    for (int ctr = 0; ctr < v.size(); ctr++) {
        idS[ctr] = (String) v.elementAt(ctr);
    }

    return idS;
}

From source file:edu.umd.cfar.lamp.viper.util.StringHelp.java

/**
 * Split using a separator, but allow for the separator to occur
 * in nested parentheses without splitting.  
 *   E.g.   //www .  j a  va 2s .c o m
 * <pre>
 *     1, (2,3), 4
 * </pre>
 *  would split into 
 * <UL>
 *   <li> 1 </li>
 *   <li> (2,3)  (Doesn't get split, even though it has comma) </li>
 *   <li> 4 </li>
 * </ul>
 *
 * @param line The String to be seperated.
 * @param sep The seperator character, eg a comma
 * @return An array of Strings containing the seperated data.
 * @see #splitBySeparator(String line, char c)
 */
public static String[] splitBySeparatorAndParen(String line, char sep) {
    boolean withinQuotes = false;
    String newLine = new String(line);
    Vector temp = new Vector();

    int startIndex = 0;
    int nesting = 0;
    for (int i = 0; i < newLine.length(); i++) {
        char c = newLine.charAt(i);
        if (c == '"') {
            withinQuotes = !withinQuotes;
        } else if (!withinQuotes) {
            if (c == '(') {
                nesting++;
            } else if (c == ')') {
                nesting--;
            } else {
                if ((nesting == 0) && (c == sep)) {
                    String s = newLine.substring(startIndex, i);
                    temp.addElement(s);

                    startIndex = i + 1;
                }
            }
        }
    }
    String s = newLine.substring(startIndex);
    temp.addElement(s);

    String[] result = new String[temp.size()];
    for (int i = 0; i < result.length; i++) {
        result[i] = (String) temp.elementAt(i);
    }
    return (result);
}