Example usage for java.util Vector get

List of usage examples for java.util Vector get

Introduction

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

Prototype

public synchronized E get(int index) 

Source Link

Document

Returns the element at the specified position in this Vector.

Usage

From source file:cl.utfsm.cdbChecker.CDBChecker.java

/**
 * This method validates the XML files./*from  w  w  w.j  av  a  2  s .c  om*/
 * 
 * @param filenames name with absolute path of the XML file to validate.
 */
protected void XMLValidate(Vector<String> filenames) {

    System.out.println("*** Will verify XML files in directory: " + this.XMLPath);

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

        File file = new File(filenames.get(i));
        if (file.length() != 0) {
            if (verbose) {
                System.out.print("    " + filenames.get(i));
                /*for(int j=0;j<(90-(int)((String)filename.get(i)).length())/8;j++)
                                  System.out.print("\t");
                 */}
            String targetNamespace = ((xsd_targetns.toString()).replace(',', ' ')).replace('=', ' ')
                    .replace('{', ' ').replace('}', ' ');
            errorFlag = false;
            try {
                validateFileEncoding(filenames.get(i));

                SP.reset();
                SP.setFeature("http://xml.org/sax/features/validation", true);
                SP.setFeature("http://apache.org/xml/features/validation/schema", true);
                SP.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
                SP.setFeature("http://xml.org/sax/features/namespaces", true);
                SP.setErrorHandler(new CDBErrorHandler(this));
                SP.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
                        targetNamespace);

                FileInputStream fis = new FileInputStream(file);
                InputSource inputSource = new InputSource(fis);
                inputSource.setSystemId("file:///" + file.getAbsolutePath());
                SP.parse(inputSource);
                fis.close();
                if (verbose && !errorFlag)
                    System.out.println("[OK]");
            } catch (SAXException e) {
                System.out.println("[SAXException] " + e.getMessage());
            } catch (IOException e) {
                System.out.println("[IOException] Probably " + filenames.get(i) + " doesn't exist.");
            }
        } else {
            System.out.print(filenames.get(i) + ": [Warning] file is empty.\n");
        }

    }
}

From source file:gsn.http.A3DWebServiceImpl.java

public String[] getMeteoDataMeasurement(String sensor, String measurement, long from, long to) {

    String str_from = Long.toString(from);
    String str_to = Long.toString(to);

    StringBuilder query = new StringBuilder("select timed, " + measurement + " from " + sensor
            + " where timed >= " + str_from + " and timed <= " + str_to + " order by timed ASC");
    logger.warn("query => " + query);
    DataEnumerator result;/*www .ja  v  a2  s  . co  m*/
    try {
        result = Main.getStorage(sensor).executeQuery(query, false);
    } catch (SQLException e) {
        logger.error("ERROR IN EXECUTING, query: " + query);
        logger.error(e.getMessage(), e);
        return new String[] { "ERROR IN EXECUTING, query: " + query };
    }

    Vector<String> meteoData = new Vector<String>();

    while (result.hasMoreElements()) {
        StreamElement se = result.nextElement();
        StringBuilder sb = new StringBuilder();

        sb.append(new StringBuilder("TIMED=" + se.getTimeStamp()).toString() + ";");

        for (int i = 0; i < se.getFieldNames().length; i++) {
            //sb.append(se.getFieldNames()[i]).append(":");
            if (se.getData()[i] != null)
                if (se.getFieldTypes()[i] == DataTypes.BINARY)
                    sb.append(measurement + "=" + se.getData()[i].toString());
                else
                    sb.append(measurement + "=" + StringEscapeUtils.escapeXml(se.getData()[i].toString()));
        }
        meteoData.add(sb.toString());
    }
    //result.close();

    String v_meteoData[] = new String[meteoData.size()];
    for (int i = 0; i < meteoData.size(); i++)
        v_meteoData[i] = meteoData.get(i);

    return v_meteoData;
}

From source file:gsn.http.A3DWebServiceImpl.java

public String[] getLatestMeteoData(String sensor) {

    String vsFields = "*";

    StringBuilder query = new StringBuilder(
            "select " + vsFields + " from " + sensor + " order by timed DESC limit 1 offset 0");
    DataEnumerator result;/*from   www. j  av a2  s  . c  o m*/
    try {
        result = Main.getStorage(sensor).executeQuery(query, true);
    } catch (SQLException e) {
        logger.error("ERROR IN EXECUTING, query: " + query);
        logger.error(e.getMessage(), e);
        return new String[] { "ERROR IN EXECUTING, query: " + query };
    }

    Vector<String> latestMeteoData = new Vector<String>();

    while (result.hasMoreElements()) {
        StreamElement se = result.nextElement();

        latestMeteoData.add(new StringBuilder("TIMED=" + se.getTimeStamp()).toString());

        for (int i = 0; i < se.getFieldNames().length; i++) {
            StringBuilder sb = new StringBuilder();
            sb.append(se.getFieldNames()[i]).append("=");
            if (se.getData()[i] != null)
                if (se.getFieldTypes()[i] == DataTypes.BINARY)
                    sb.append(se.getData()[i].toString());
                else
                    sb.append(StringEscapeUtils.escapeXml(se.getData()[i].toString()));
            latestMeteoData.add(sb.toString());
        }

    }
    //result.close();

    String v_latestMeteoData[] = new String[latestMeteoData.size()];
    for (int i = 0; i < latestMeteoData.size(); i++)
        v_latestMeteoData[i] = latestMeteoData.get(i);

    return v_latestMeteoData;
}

From source file:net.sf.ginp.browser.FolderManagerImpl.java

/**
 * Gets the foldersInDirectory attribute of the PicCollection object.
 * @param root the root directory/*from   ww  w . j  a v a  2 s. c  om*/
 * @param  relPath  Description of the Parameter
 * @return          The foldersInDirectory value
 */
private String[] getFoldersInDirectory(final String root, final String relPath) {
    long duration = System.currentTimeMillis() - picCacheTimeout;

    if ((picCacheTimeout < 0) || (duration > MAX_CACHE)) {
        synchronized (folderCache) {
            //Clearing a cache while doing a get can
            //cause hashmap to hang.  Hence all the synchronized blocks
            folderCacheTimeout = System.currentTimeMillis();
            folderCache.clear();
        }
    }

    synchronized (folderCache) {
        if (folderCache.get(root + relPath) != null) {
            return (String[]) folderCache.get(root + relPath);
        }
    }

    Vector dirs = new Vector();

    File dir = new File(root + relPath);

    if (dir.isDirectory()) {
        String[] files = dir.list();
        Arrays.sort(files);

        for (int i = 0; i < files.length; i++) {
            File file = new File(root + relPath + "/" + files[i]);

            if (file.isDirectory()) {
                if (!(files[i].startsWith("."))) {
                    dirs.add(files[i]);
                }
            }
        }
    }

    String[] retFolders = new String[dirs.size()];

    for (int i = 0; i < dirs.size(); i++) {
        retFolders[i] = relPath + (String) dirs.get(i);
    }

    Arrays.sort(retFolders);

    synchronized (folderCache) {
        folderCache.put(root + relPath, retFolders);
    }

    return retFolders;
}

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

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setSiteIdUI.getValues();
    Vector<String> samples = this.setSiteIdUI.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
        this.setSiteIdUI.displayMessage("Error: no subject to sample mapping file");
    }//from  w  w w  . j  a v  a2  s . co m
    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");

        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 site;
                if (samples.contains(sample)) {
                    site = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + site + "\t" + fields[2] + "\t" + sample + "\t" + fields[4] + "\t"
                        + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.setSiteIdUI.displayMessage("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.setSiteIdUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setSiteIdUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setSiteIdUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:eionet.meta.dao.mysql.DataElementDAOImpl.java

/**
 * {@inheritDoc}/*from   w  w  w . ja v  a 2  s .  com*/
 *
 * @throws SQLException
 */
@Override
public List<Attribute> getDataElementAttributes() throws SQLException {
    List<Attribute> result = new ArrayList<Attribute>();
    DDSearchEngine searchEngine = new DDSearchEngine(getConnection());

    @SuppressWarnings("rawtypes")
    Vector attrs = searchEngine.getDElemAttributes();

    for (int i = 0; i < attrs.size(); i++) {
        DElemAttribute attribute = (DElemAttribute) attrs.get(i);

        if (attribute.displayFor("CH1") || attribute.displayFor("CH2")) {
            Attribute a = new Attribute();
            a.setId(Integer.parseInt(attribute.getID()));
            a.setName(attribute.getName());
            a.setShortName(attribute.getShortName());

            result.add(a);
        }
    }
    return result;
}

From source file:at.tuwien.ifs.somtoolbox.reportgenerator.output.SOMDescriptionLATEX.java

/**
 * creates and outputs one out of two possible tables the first possible table: \\\\ the first table contains for
 * each unit only the number of input vectors mapped to it, and a pie chart image of the class distribution within
 * this unit. (lookup == null) If no class information is available, this table is not created\\\\ \\\\ The second
 * table additionally contains the ids of input vectors selected by the user within the unit they are mapped to.
 * Therefore lookup must be a hashtable that contains for each unit (key = "x_y") a list of InputDatum objects
 * specifying the input elements mapped to this unit. If for a key there's no list, then nothing is mapped to this
 * unit. if no class information is available, the table does not contain the number of input vectors mapped to each
 * unit//from  w w w.  ja  va  2 s  . c  o m
 * 
 * @param lookup a hashtable with the content specified above to map input vectors to units
 * @param classInformationAvailable true if class information (and therefore pie chart diagrams for the units are
 *            available, false otherwise
 */
protected void printDistributionDetailTable(Hashtable<String, Vector<InputDatum>> lookup,
        boolean classInformationAvailable) {

    File pieDir = null;
    if (classInformationAvailable) {
        pieDir = new File(
                this.imgDir + "pieCharts_" + this.testrun.getRunId() + System.getProperty("file.separator"));
    }

    this.writer.appendLatexOutput("\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{");
    for (int x = 0; x < Integer
            .parseInt(((String) this.testrun.getMapProperty(TestRunResultCollection.keyXDim))); x++) {
        if (x == 0) {
            this.writer.appendOutput("|");
        }

        this.writer.appendOutput("|l");
        if (x == Integer.parseInt(((String) this.testrun.getMapProperty(TestRunResultCollection.keyXDim)))
                - 1) {
            this.writer.appendOutput("||");
        }
    }
    this.writer.appendLatexOutput("}\n");
    this.writer.appendOutput("\\hline\\hline");

    // as we want to create html output, we first have to iterate about the rows (tr elements)
    for (int y = 0; y < Integer
            .parseInt(((String) this.testrun.getMapProperty(TestRunResultCollection.keyYDim))); y++) {

        // and only within these elements about the columns (td elements)
        for (int x = 0; x < Integer
                .parseInt(((String) this.testrun.getMapProperty(TestRunResultCollection.keyXDim))); x++) {

            String img = "";
            String numbDiv = "";
            String mappedInputsDiv = "";
            String content1 = "";

            // the class pie chart and number of input items per unit (as these number is encoded within the pie
            // chart images names
            if (classInformationAvailable) {
                String[] matches = pieDir.list(new PrefixFileFilter(x + "_" + y + "_")); // lookup whether
                // there's an image
                if (matches != null && matches.length > 0) {
                    // image exists => insert it
                    String number = matches[0].substring((x + "_" + y + "_").length());
                    number = number.substring(0, number.length() - 4);

                    img = "\n\\includegraphicstotab[width=20pt]{" + SOMDescriptionLATEX.imgSubdir
                            + "/pieCharts_" + this.testrun.getRunId() + "/" + matches[0] + "}\n";
                    numbDiv = "" + number;
                    content1 = numbDiv + img;
                }
            } else {
                int count = this.testrun.getNumberOfInputsOnUnit(x, y);
                if (count > 0) {
                    numbDiv = "" + count;
                    content1 = numbDiv;
                }
            }
            // the mapped input vectors
            if (lookup != null) {
                String key = x + "_" + y;
                Vector<InputDatum> mapped = lookup.get(key);
                if (mapped != null) {
                    for (int i = 0; i < mapped.size(); i++) {
                        mappedInputsDiv += "\"" + mapped.get(i).getLabel() + "\"\\\\\n";
                    }
                }
            }
            String content = content1 + mappedInputsDiv;

            // if there's an empty unit (if no unit => show noting)
            if (content.length() == 0 && this.testrun.hasUnitOn(x, y)) {
                content = " ";
            }

            // write the table cell
            this.writer.appendOutput(content);
            if (x + 1 < Integer
                    .parseInt(((String) this.testrun.getMapProperty(TestRunResultCollection.keyXDim)))) {
                this.writer.appendOutput("&\n");
            }
        } // for x
        this.writer.appendLatexOutput("\\\\\\hline\n");
    } // for y
    this.writer.appendLatexOutput(
            "\\hline\n\\end{tabular}\n\\caption{Visualisation of the Hit Histogram and the corresponding Pie-chart Class images}\n\\label{tab:pie}\n\\end{center}\n\\end{table}\n");
}

From source file:cn.labthink.ReadAccess060.java

private void outputexcelCell(Vector columns, Vector data, int cellno) {
    if (outputfile == null) {
        return;//  ww  w .j  a  va2s.  c om
    }
    if (book == null) {
        try {
            //
            book = Workbook.createWorkbook(outputfile);
        } catch (IOException ex) {
            Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        //?
    }

    try {

        WritableSheet sheet1 = book.createSheet("Cell" + cellno, cellno + 1);// 0
        int count = columns.size();
        for (int i = 0; i < count; i++) {
            Label l = new Label(i, 0, (String) columns.get(i));//i0
            sheet1.addCell(l);
        }
        int irow = 1;
        //            System.out.println("rows:" + data.size());
        for (Iterator it = data.iterator(); it.hasNext();) {
            Vector row = (Vector) it.next();
            for (int i = 0; i < count; i++) {
                Label l = new Label(i, irow, (String) row.get(i));//iirow
                sheet1.addCell(l);
            }
            irow++;
        }
        //            book.write();
        //            book.close();
    } catch (WriteException ex) {
        Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:cn.labthink.ReadAccess330.java

private void outputexcelCell(Vector columns, Vector data, int cellno) {
    if (outputfile == null) {
        return;//from   w ww  . j  av  a 2 s . c  om
    }
    if (book == null) {
        try {
            //
            book = Workbook.createWorkbook(outputfile);
        } catch (IOException ex) {
            Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        //?
    }

    try {

        WritableSheet sheet1 = book.createSheet("Cell" + cellno, cellno + 1);// 0
        int count = columns.size();
        for (int i = 0; i < count; i++) {
            Label l = new Label(i, 0, (String) columns.get(i));//i0
            sheet1.addCell(l);
        }
        int irow = 1;
        //            System.out.println("rows:" + data.size());
        for (Iterator it = data.iterator(); it.hasNext();) {
            Vector row = (Vector) it.next();
            for (int i = 0; i < count; i++) {
                Label l = new Label(i, irow, (String) row.get(i));//iirow
                sheet1.addCell(l);
            }
            irow++;
        }
        //            book.write();
        //            book.close();
    } catch (WriteException ex) {
        Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex);
    }

}