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:com.k42b3.kadabra.handler.Ssh.java

public Item[] getFiles(String path) throws Exception {
    logger.info(basePath + "/" + path);

    Vector list = channel.ls(basePath + "/" + path);
    Item[] items = new Item[list.size()];

    for (int i = 0; i < list.size(); i++) {
        LsEntry entry = (LsEntry) list.get(i);

        if (entry.getAttrs().isDir()) {
            items[i] = new Item(entry.getFilename(), Item.DIRECTORY);
        } else {/*w  w w  . j av a  2 s  . c  o  m*/
            byte[] content = this.getContent(path + "/" + entry.getFilename());
            String md5 = DigestUtils.md5Hex(Kadabra.normalizeContent(content));

            items[i] = new Item(entry.getFilename(), Item.FILE, md5);
        }
    }

    return items;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void updateHeaderRecordAttachments(int headerId, Vector<HashMap<String, String>> attachsVector,
        Context context) {//  ww w. j  a v a 2s. c  o m

    if (attachsVector == null || attachsVector.size() == 0)
        return;

    StringBuffer strbu = new StringBuffer();
    HashMap<String, String> attachData = null;
    int len = attachsVector.size();

    for (int i = 0; i < len; i++) {
        attachData = attachsVector.get(i);
        strbu.append(attachData.get("md5"));
        if (i != len - 1)
            strbu.append(";");
    }

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwriter = db.getWritableDatabase();
    String q = "UPDATE headers SET has_attachments=1, attachments_fnames=" + esc(strbu.toString())
            + " WHERE _id=" + headerId;
    dbwriter.execSQL(q);
    dbwriter.close();
    db.close();
}

From source file:PrepareToTrim.java

Data _generateTrimmingInfo(BlockEnvironment env, Data blastInfo) throws DataException {
    ColumnPickerCollection pickers = new ColumnPickerCollection();
    pickers.setPickersCopyData(false);//from  w w  w  .  j  a v a2s.c  o  m
    pickers.addColumnPicker(env.getStringProperty(Prop_QSEQID, (String) null));
    pickers.addColumnPicker(env.getStringProperty(Prop_QSTART, (String) null));
    pickers.addColumnPicker(env.getStringProperty(Prop_QEND, (String) null));

    Vector<?> columns = pickers.extractColumnVector(blastInfo);

    StringColumn seqId_Col = (StringColumn) columns.get(0);
    // QStart and QEnd columns may be String, Integer or Double depending on the nuances of the input data parsing
    // Let's parse integers manually in this block...
    Column qStart_Col = (Column) columns.get(1);
    Column qEnd_Col = (Column) columns.get(2);

    // Check for errors in the input
    if (seqId_Col.getRows() != qStart_Col.getRows() || seqId_Col.getRows() != qEnd_Col.getRows()) {
        throw new IllegalArgumentException("Invalid blast info uneven column lengths: " + seqId_Col.getRows()
                + ", " + qStart_Col.getRows() + ", " + qEnd_Col.getRows());
    }

    ArrayList<TrimInfo> startEndList = new ArrayList<>();

    // To make loop simpler...
    if (seqId_Col.getRows() == 0) {
        return new Data();
    }
    // initialise the list with the first element from the blastInfo data set.
    TrimInfo info = new TrimInfo(seqId_Col.getStringValue(0), Integer.parseInt(qStart_Col.getStringValue(0)),
            Integer.parseInt(qEnd_Col.getStringValue(0)));
    startEndList.add(info);

    for (int i = 1; i < seqId_Col.getRows(); i++) {
        int qStart = Integer.parseInt(qStart_Col.getStringValue(i));
        int qEnd = Integer.parseInt(qEnd_Col.getStringValue(i));

        if (info.sequenceId.equals(seqId_Col.getStringValue(i))) {
            if (qStart < info.trimStart) {
                info.trimStart = qStart;
            }
            if (qEnd > info.trimEnd) {
                info.trimEnd = qEnd;
            }
        } else {
            info = new TrimInfo(seqId_Col.getStringValue(i), qStart, qEnd);
            startEndList.add(info);
        }
    }

    seqId_Col = new StringColumn("qSeqId");
    IntegerColumn start_Col = new IntegerColumn("qStart");
    IntegerColumn end_Col = new IntegerColumn("qEnd");

    for (TrimInfo tInfo : startEndList) {
        seqId_Col.appendStringValue(tInfo.sequenceId);
        start_Col.appendIntValue(tInfo.trimStart);
        end_Col.appendIntValue(tInfo.trimEnd);
    }

    Data output = new Data();
    output.addColumn(seqId_Col);
    output.addColumn(start_Col);
    output.addColumn(end_Col);

    return output;
}

From source file:agentlogfileanalyzer.gui.ComparisonFrame.java

/**
 * Creates a chart frame for comparing a selected classifier to a set of
 * other classifiers./*  www.  j  a v a2s .  com*/
 * 
 * @param firstTitle
 *            the first line of the chart title
 * @param secondTitle
 *            the second line of the chart title
 * @param compDataForColumns
 *            the data the will be displayed in the chart
 */
public ComparisonFrame(String firstTitle, String secondTitle, Vector<ComparisonDataSet> compDataForColumns) {

    super("Classifier comparison");

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < compDataForColumns.size(); i++) {
        ComparisonDataSet mms = compDataForColumns.get(i);
        dataset.addValue(mms.getMax(), "max", mms.getColumnName());
        dataset.addValue(mms.getMin(), "min", mms.getColumnName());
        dataset.addValue(mms.getSelected(), "selected", mms.getColumnName());
    }

    JFreeChart jfreechart = ChartFactory.createBarChart("", // title
            "", // x-axis title
            "", // y-axis title
            dataset, PlotOrientation.VERTICAL, true, true, false);
    TextTitle subtitle1 = new TextTitle(firstTitle, new Font("SansSerif", Font.BOLD, 12));
    TextTitle subtitle2 = new TextTitle(secondTitle, new Font("SansSerif", Font.BOLD, 12));
    jfreechart.addSubtitle(0, subtitle1);
    jfreechart.addSubtitle(1, subtitle2);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    MinMaxCategoryRenderer minmaxcategoryrenderer = new MinMaxCategoryRenderer();
    categoryplot.setRenderer(minmaxcategoryrenderer);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(chartpanel);
}

From source file:com.crankworks.cycletracks.TripUploader.java

private List<NameValuePair> getPostData(long tripId) throws JSONException {
    JSONObject coords = getCoordsJSON(tripId);
    JSONObject user = getUserJSON();//from  ww w.j  av  a2 s  . c  o  m
    String deviceId = getDeviceId();
    Vector<String> tripData = getTripData(tripId);
    String notes = tripData.get(0);
    String purpose = tripData.get(1);
    String startTime = tripData.get(2);
    String endTime = tripData.get(3);

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("coords", coords.toString()));
    nameValuePairs.add(new BasicNameValuePair("user", user.toString()));
    nameValuePairs.add(new BasicNameValuePair("device", deviceId));
    nameValuePairs.add(new BasicNameValuePair("notes", notes));
    nameValuePairs.add(new BasicNameValuePair("purpose", purpose));
    nameValuePairs.add(new BasicNameValuePair("start", startTime));
    nameValuePairs.add(new BasicNameValuePair("end", endTime));
    nameValuePairs.add(new BasicNameValuePair("version", "2"));

    return nameValuePairs;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SetUnitsListener.java

@Override
public void handleEvent(Event event) {
    Vector<String> columns = this.setUnitsUI.getColumns();
    Vector<String> units = this.setUnitsUI.getUnits();
    if (columns.size() == 1) {
        if (columns.get(0).compareTo("") == 0 && columns.get(0).compareTo("") == 0) {
            columns = new Vector<String>();
            units = new Vector<String>();
        }/* w w  w  .  ja va 2s  .  c  om*/
    }
    for (int i = 0; i < columns.size(); i++) {
        if (columns.get(i).compareTo("") == 0 || units.get(i).compareTo("") == 0) {
            this.setUnitsUI.displayMessage("Some values are not set");
            return;
        }
        String columnFileName = columns.get(i).split(" - ", 2)[0];
        String unitFileName = units.get(i).split(" - ", 2)[0];
        if (columnFileName.compareTo(unitFileName) != 0) {
            this.setUnitsUI.displayMessage("Columns for value and unit have to been from the same file");
        }
    }
    if (((ClinicalData) this.dataType).getCMF() == null) {
        this.setUnitsUI.displayMessage("Error: no column mapping file");
        return;
    }
    if (!this.checkValues(columns, units))
        return;
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".columns.tmp");
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "Filename\tCategory Code\tColumn Number\tData Label\tData Label Source\tControlled Vocab Code\n");
        try {
            BufferedReader br = new BufferedReader(new FileReader(((ClinicalData) this.dataType).getCMF()));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                if (line.split("\t", -1)[3].compareTo("UNITS") != 0) {
                    out.write(line + "\n");
                }
            }
            br.close();
        } catch (Exception e) {
            this.setUnitsUI.displayMessage("Error: " + e.getLocalizedMessage());
            e.printStackTrace();
            out.close();
        }
        for (int i = 0; i < columns.size(); i++) {
            String fileName = columns.get(i).split(" - ", 2)[0];
            int columnColumnNumber = -1;
            for (File rawFile : ((ClinicalData) this.dataType).getRawFiles()) {
                if (rawFile.getName().compareTo(fileName) == 0) {
                    columnColumnNumber = FileHandler.getHeaderNumber(rawFile,
                            columns.get(i).split(" - ", 2)[1]);
                }
            }
            int unitColumnNumber = -1;
            for (File rawFile : ((ClinicalData) this.dataType).getRawFiles()) {
                if (rawFile.getName().compareTo(fileName) == 0) {
                    unitColumnNumber = FileHandler.getHeaderNumber(rawFile, units.get(i).split(" - ", 2)[1]);
                }
            }
            if (columnColumnNumber != -1 && unitColumnNumber != -1) {
                out.write(fileName + "\t\t" + String.valueOf(unitColumnNumber) + "\tUNITS\t"
                        + String.valueOf(columnColumnNumber) + "\t\t\n");

            }
        }

        out.close();
        String fileName = ((ClinicalData) this.dataType).getCMF().getName();
        FileUtils.deleteQuietly(((ClinicalData) this.dataType).getCMF());
        try {
            File fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            FileUtils.moveFile(file, fileDest);
            ((ClinicalData) this.dataType).setCMF(fileDest);
        } catch (Exception ioe) {
            this.setUnitsUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setUnitsUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setUnitsUI.displayMessage("Column mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SetUnitsListener.java

private boolean checkValues(Vector<String> columns, Vector<String> units) {
    File wmf = ((ClinicalData) this.dataType).getWMF();
    for (int i = 0; i < columns.size(); i++) {
        File rawFile = new File(this.dataType.getPath() + File.separator + columns.get(i).split(" - ", 2)[0]);
        String headColumn = columns.get(i).split(" - ", 2)[1];
        String headUnit = units.get(i).split(" - ", 2)[1];
        int numberColumn = FileHandler.getHeaderNumber(rawFile, headColumn);
        if (!FileHandler.isColumnNumerical(rawFile, wmf, numberColumn)) {
            this.setUnitsUI.displayMessage("Values have to be numerical (term mapping considered).\nAt least '"
                    + headColumn + "' is not numerical");
            return false;
        }//from   www  .j  av a2s. com
        int numberUnit = FileHandler.getHeaderNumber(rawFile, headUnit);
        if (FileHandler.isColumnNumerical(rawFile, wmf, numberUnit)) {
            this.setUnitsUI.displayMessage(
                    "Units have to be non numerical.\nAt lease '" + headUnit + "' is numerical");
            return false;
        }
    }
    return true;
}

From source file:azkaban.common.utils.Utils.java

/**
 * Parse lines in byteArray and store the last *lineCount* lines in
 * *lastNLines*/*from   www . j  av a 2 s  .co m*/
 * 
 * @param byteArray         source byte array
 * @param offset                offset of the byte array
 * @param length                length of the byte array
 * @param lineCount             desired number of lines
 * @param lastNLines        vector of last N lines
 * @return true         indicates we get *lineCount* lines 
 *                false         otherwise
 */
protected static boolean parseLinesFromLast(byte[] byteArray, int offset, int length, int lineCount,
        Vector<String> lastNLines) {

    if (lastNLines.size() > lineCount)
        return true;

    // convert byte array to string
    String lastNChars = new String(byteArray, offset, length);

    // reverse the string
    StringBuffer sb = new StringBuffer(lastNChars);
    lastNChars = sb.reverse().toString();

    // tokenize the string using "\n"
    String[] tokens = lastNChars.split("\n");

    // append lines to lastNLines
    for (int index = 0; index < tokens.length; index++) {
        StringBuffer sbLine = new StringBuffer(tokens[index]);
        String newline = sbLine.reverse().toString();

        if (index == 0 && !lastNLines.isEmpty()) { // first line might not be a complete line
            int lineNum = lastNLines.size();
            String halfLine = lastNLines.get(lineNum - 1);
            lastNLines.set(lineNum - 1, newline + halfLine);
        } else {
            lastNLines.add(newline);
        }

        if (lastNLines.size() > lineCount) {
            return true;
        }
    }

    return false;
}

From source file:edu.ku.brc.specify.rstools.SpAnalysis.java

public void checkAgents(final TableWriter tblWriter) {
    tblWriter.append("<H3>Agents</H3>");
    tblWriter.startTable();/*from www  .j  a  va 2s  .  c om*/
    tblWriter.append(
            "<TR><TH>AgentID</TH><TH>LastName</TH><TH>FirstName</TH><TH>MiddleInitial</TH><TH>Ids</TH></TR>");

    Statement stmt = null;
    Statement stmt2 = null;
    try {
        Integer cnt = BasicSQLUtils.getCount(
                "SELECT (COUNT(LOWER(nm)) - COUNT(DISTINCT LOWER(nm))) AS DIF  FROM (SELECT CONCAT(LN,FN,MI) NM FROM(select IFNULL(LastName, '') LN, IFNULL(FirstName, '') FN, IFNULL(MiddleInitial, '') MI from agent) T1) T2");
        if (cnt != null && cnt > 0) {
            String sql = "SELECT AgentID, LOWER(nm) C1 FROM (SELECT AgentID, CONCAT(LN,FN,MI) NM FROM (select AgentID, IFNULL(LastName, '') LN, IFNULL(FirstName, '') FN, IFNULL(MiddleInitial, '') MI from agent) T1) T2 ";

            Vector<Integer> extraIds = new Vector<Integer>();

            Connection conn = DBConnection.getInstance().getConnection();
            stmt = conn.createStatement();
            stmt2 = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql + "  ORDER BY AgentID");
            while (rs.next()) {
                int id = rs.getInt(1);
                String str = rs.getString(2);

                extraIds.clear();

                str = StringUtils.replace(str, "'", "''");
                String sql2 = sql + " WHERE LOWER(nm) = '" + str + "' AND AgentID > " + id
                        + "  ORDER BY AgentID";

                //System.err.println(sql2);

                int dupCnt = 0;
                ResultSet rs2 = stmt2.executeQuery(sql2);
                while (rs2.next()) {
                    extraIds.add(rs2.getInt(1));
                    dupCnt++;
                }
                rs2.close();

                if (dupCnt > 0) {
                    String s = "SELECT AgentID, LastName, FirstName, MiddleInitial FROM agent WHERE AgentID = "
                            + id;
                    Vector<Object[]> rows = BasicSQLUtils.query(s);
                    Object[] row = rows.get(0);
                    tblWriter.append("<TR><TD>" + row[0] + "</TD><TD>" + row[1] + "</TD><TD>" + row[2]
                            + "</TD><TD>" + row[3] + "</TD><TD>");
                    for (int i = 0; i < extraIds.size(); i++) {
                        if (i > 0)
                            tblWriter.log(", ");
                        tblWriter.append(extraIds.get(i).toString());
                    }
                    tblWriter.append("</TD></TR>");
                }
            }
            rs.close();
        }

    } catch (Exception ex) {
        ex.printStackTrace();

    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
            if (stmt2 != null) {
                stmt2.close();
            }
        } catch (Exception ex) {
        }
    }

    tblWriter.endTable();
}

From source file:edu.ku.brc.specify.rstools.SpAnalysis.java

public void checkAddress(final TableWriter tblWriter) {
    Statement stmt = null;//from   w ww  .  j  a  v  a2  s  . c o  m
    Statement stmt2 = null;
    try {
        Integer cnt = BasicSQLUtils.getCount(
                "SELECT COUNT(LOWER(ADDR)) - COUNT(DISTINCT LOWER(ADDR)) AS DIF FROM (SELECT CONCAT(ID,A1,A2,C,S,Z) ADDR FROM (SELECT AgentID ID, IFNULL(Address, '') A1, IFNULL(Address2, '') A2, IFNULL(City, '') C, IFNULL(State, '') S, IFNULL(State, ''), IFNULL(PostalCode, '') Z from address) T1) T2 ");
        if (cnt != null && cnt > 0) {
            tblWriter.append("<H3>Address</H3>");
            tblWriter.startTable();
            tblWriter.append(
                    "<TR><TH>AddressID</TH><TH>Address</TH><TH>Address2</TH><TH>City</TH><TH>State</TH><TH>PostalCode</TH><TH>Ids</TH></TR>");

            String sql = "SELECT AddressID, LOWER(ADDR) C1 FROM (SELECT AddressID, CONCAT(ID, A1,A2,C,S,Z) ADDR FROM (SELECT AddressID, AgentID ID, IFNULL(Address, '') A1, IFNULL(Address2, '') A2, IFNULL(City, '') C, IFNULL(State, '') S, IFNULL(State, ''), IFNULL(PostalCode, '') Z from address) T1) T2 ";

            Vector<Integer> extraIds = new Vector<Integer>();

            Connection conn = DBConnection.getInstance().getConnection();
            stmt = conn.createStatement();
            stmt2 = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql + "  ORDER BY AddressID");
            while (rs.next()) {
                int id = rs.getInt(1);
                String str = rs.getString(2);

                extraIds.clear();

                str = StringUtils.replace(str, "'", "''");
                String sql2 = sql + " WHERE LOWER(ADDR) = '" + str + "' AND AddressID > " + id;// +"  ORDER BY AddressID";

                int dupCnt = 0;
                ResultSet rs2 = stmt2.executeQuery(sql2);
                while (rs2.next()) {
                    extraIds.add(rs2.getInt(1));
                    dupCnt++;
                }
                rs2.close();

                if (dupCnt > 0) {
                    String s = "SELECT AddressID, Address, Address2, City, state, PostalCode FROM address WHERE AddressID = "
                            + id;
                    Vector<Object[]> rows = BasicSQLUtils.query(s);
                    Object[] row = rows.get(0);
                    tblWriter.append("<TR>");
                    for (Object data : row) {
                        tblWriter.append("<TD>" + data + "</TD>");
                    }
                    tblWriter.append("<TD>");
                    for (int i = 0; i < extraIds.size(); i++) {
                        if (i > 0)
                            tblWriter.log(", ");
                        tblWriter.append(extraIds.get(i).toString());
                    }
                    tblWriter.append("</TD></TR>");
                }
            }
            rs.close();
        }

    } catch (Exception ex) {
        ex.printStackTrace();

    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
            if (stmt2 != null) {
                stmt2.close();
            }
        } catch (Exception ex) {
        }
    }

    tblWriter.endTable();
}