Example usage for java.util Vector ensureCapacity

List of usage examples for java.util Vector ensureCapacity

Introduction

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

Prototype

public synchronized void ensureCapacity(int minCapacity) 

Source Link

Document

Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    Vector v = new Vector(5);
    for (int i = 0; i < 10; i++) {
        v.add(0, i);/*  ww  w  .  j a  v a2  s.  c  o  m*/
    }
    System.out.println(v);
    System.out.println(v.size());

    v.ensureCapacity(40);
    for (int i = 0; i < 10; i++) {
        v.add(0, i);
    }

    System.out.println(v);
    System.out.println(v.size());
}

From source file:Main.java

public static void main(String args[]) {
    Vector vec = new Vector(5);
    for (int i = 0; i < 10; i++) {
        vec.add(0, i);/*from w  ww.  j av  a2 s .c  o  m*/
    }
    System.out.println("Content of the vector: " + vec);
    System.out.println("Size of the vector: " + vec.size());

    // ensure the capacity of the vector and add elements
    vec.ensureCapacity(40);
    for (int i = 0; i < 10; i++) {
        vec.add(0, i);
    }
    System.out.println(vec);
    System.out.println(vec.size());
}

From source file:Main.java

public static Vector appendInto(Vector v, Object[] array, int quantity) {
    v.ensureCapacity(v.size() + quantity);
    for (int i = 0; i < quantity; i++) {
        v.addElement(array[i]);/*w  ww  . ja v a  2 s. c o m*/
    }

    return v;
}

From source file:com.yahoo.ycsb.db.PostgreSQLJsonbClient.java

@Override
public Status scan(String tableName, String startKey, int recordcount, Set<String> fields,
        Vector<HashMap<String, ByteIterator>> result) {
    try {/*ww  w  .j a va  2  s . c  o m*/
        StatementType type = new StatementType(StatementType.Type.SCAN, tableName, 1, "",
                getShardIndexByKey(startKey));
        PreparedStatement scanStatement = cachedStatements.get(type);
        if (scanStatement == null) {
            scanStatement = createAndCacheScanStatement(type, startKey);
        }
        scanStatement.setString(1, startKey);
        scanStatement.setInt(2, recordcount);
        result.ensureCapacity(recordcount);
        ResultSet resultSet = scanStatement.executeQuery();
        System.out.println(startKey + ", " + recordcount);
        for (int i = 0; i < recordcount && resultSet.next(); i++) {
            if (result != null && fields != null) {
                HashMap<String, ByteIterator> values = new HashMap<String, ByteIterator>();
                for (String field : fields) {
                    String value = resultSet.getString(field);
                    //values.put(field, new StringByteIterator(value));
                }
                result.add(values);
            }
        }
        resultSet.close();
        return Status.OK;
    } catch (SQLException e) {
        System.err.println("Error in processing scan of table: " + tableName + e);
        return Status.ERROR;
    }
}

From source file:cn.labthink.ReadAccess060.java

private void generateCellData(Integer testID, int cellno) throws SQLException {
    Vector columns = null;
    Vector data = null;/*from  ww  w  .j av a 2s  . c om*/

    data = new Vector();
    columns = new Vector();

    //                PreparedStatement st = con.prepareStatement("SELECT * FROM RESULTS WHERE TESTID = ? AND CELLID = ? ORDER BY RESULTID");
    PreparedStatement st = conn.prepareStatement(
            "SELECT TESTTEMPERATURE,HUMIDITY,WEIGHT,AMBTEMP,PRODUCETIME,AREA,THICKNESS  FROM RESULTS WHERE TESTID = ? AND CELLID = ? ORDER BY RESULTID");
    st.setInt(1, testID);
    st.setObject(2, cellno);

    rs = st.executeQuery();

    ResultSetMetaData md = rs.getMetaData();
    int columnCount = md.getColumnCount();
    //store column names 
    for (int i = 1; i <= columnCount; i++) {
        columns.add(md.getColumnName(i));
        //                System.out.println(md.getColumnName(i));
    }
    columns.ensureCapacity(columnCount);

    Vector row;
    while (rs.next()) {

        row = new Vector(columnCount);
        for (int i = 1; i <= columnCount; i++) {
            row.add(rs.getString(i));
            //                    System.out.print(rs.getString(i));
            //                    System.out.print(",");
        }
        //                System.out.print("\r\n");
        data.add(row);

        //Debugging    
    }

    outputexcelCell(columns, data, cellno);
}

From source file:cn.labthink.ReadAccess330.java

private void generateCellData(Integer testID, int cellno) throws SQLException {
    Vector columns = null;
    Vector data = null;//from   w  ww .j a va  2 s . c  o m

    data = new Vector();
    columns = new Vector();

    //                PreparedStatement st = con.prepareStatement("SELECT * FROM RESULTS WHERE TESTID = ? AND CELLID = ? ORDER BY RESULTID");
    PreparedStatement st = conn.prepareStatement(
            "SELECT TIMESPAN,TESTTEMPERATURE,ABOVEHUMIDITY,BELOWHUMIDITY,ABOVEPRESSURE,BELOWPRESSURE,FLOWRATE,OPPM,WPPM,OTR,WVTR,SENSORTEMP,AMBTEMP,TESTTYPE,AMTEMPERATURE,AMHUMIDITY,PRODUCETIME,COFFICIENT  FROM RESULTS WHERE TESTID = ? AND CELLID = ? ORDER BY RESULTID");
    st.setInt(1, testID);
    st.setObject(2, cellno);

    rs = st.executeQuery();

    ResultSetMetaData md = rs.getMetaData();
    int columnCount = md.getColumnCount();
    //store column names 
    for (int i = 1; i <= columnCount; i++) {
        columns.add(md.getColumnName(i));
        //                System.out.println(md.getColumnName(i));
    }
    columns.ensureCapacity(columnCount);

    Vector row;
    while (rs.next()) {

        row = new Vector(columnCount);
        for (int i = 1; i <= columnCount; i++) {
            row.add(rs.getString(i));
            //                    System.out.print(rs.getString(i));
            //                    System.out.print(",");
        }
        //                System.out.print("\r\n");
        data.add(row);

        //Debugging    
    }

    outputexcelCell(columns, data, cellno);
}

From source file:com.yahoo.ycsb.db.couchbase2.Couchbase2Client.java

/**
 * Performs the {@link #scan(String, String, int, Set, Vector)} operation N1Ql only for a subset of the fields.
 *
 * @param table The name of the table//from w  ww.j a v a  2  s.c  om
 * @param startkey The record key of the first record to read.
 * @param recordcount The number of records to read
 * @param fields The list of fields to read, or null for all of them
 * @param result A Vector of HashMaps, where each HashMap is a set field/value pairs for one record
 * @return The result of the operation.
 */
private Status scanSpecificFields(final String table, final String startkey, final int recordcount,
        final Set<String> fields, final Vector<HashMap<String, ByteIterator>> result) {
    String scanSpecQuery = "SELECT " + joinFields(fields) + " FROM `" + bucketName
            + "` WHERE meta().id >= '$1' LIMIT $2";
    N1qlQueryResult queryResult = bucket.query(
            N1qlQuery.parameterized(scanSpecQuery, JsonArray.from(formatId(table, startkey), recordcount),
                    N1qlParams.build().adhoc(adhoc).maxParallelism(maxParallelism)));

    if (!queryResult.parseSuccess() || !queryResult.finalSuccess()) {
        throw new RuntimeException("Error while parsing N1QL Result. Query: " + scanSpecQuery + ", Errors: "
                + queryResult.errors());
    }

    boolean allFields = fields == null || fields.isEmpty();
    result.ensureCapacity(recordcount);

    for (N1qlQueryRow row : queryResult) {
        JsonObject value = row.value();
        if (fields == null) {
            value = value.getObject(bucketName);
        }
        Set<String> f = allFields ? value.getNames() : fields;
        HashMap<String, ByteIterator> tuple = new HashMap<String, ByteIterator>(f.size());
        for (String field : f) {
            tuple.put(field, new StringByteIterator(value.getString(field)));
        }
        result.add(tuple);
    }
    return Status.OK;
}