Example usage for java.util Vector add

List of usage examples for java.util Vector add

Introduction

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

Prototype

public synchronized boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this Vector.

Usage

From source file:com.bluexml.xforms.demo.Util.java

public static Collection<? extends Vector<String>> showAvailableContentWithWorklowId(String alfrescohost,
        String user, String password, String workflowId) throws Exception {
    Set<Vector<String>> result = new HashSet<Vector<String>>();
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    PostMethod post = new PostMethod(alfrescohost + "service/xforms/workflow");
    post.setParameter("username", user);
    post.setParameter("method", "getWorkflowPaths");
    post.setParameter("arg0", workflowId);
    HttpClient client = new HttpClient();
    client.executeMethod(post);//from   ww w. ja  va  2  s. c o m

    Document document = builder.parse(new ByteArrayInputStream(
            ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + post.getResponseBodyAsString()).getBytes()));
    Node root = document.getDocumentElement();
    // in the case of the workflow is ended
    if (findNodes(root.getChildNodes(), "org.alfresco.service.cmr.workflow.WorkflowPath").size() > 0) {
        String pathId = findNode(
                findNode(root.getChildNodes(), "org.alfresco.service.cmr.workflow.WorkflowPath")
                        .getChildNodes(),
                "id").getTextContent();

        post = new PostMethod(alfrescohost + "service/xforms/workflow");
        post.setParameter("username", user);
        post.setParameter("method", "getTasksForWorkflowPath");
        post.setParameter("arg0", pathId);
        client = new HttpClient();
        client.executeMethod(post);

        document = builder.parse(new ByteArrayInputStream(
                ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + post.getResponseBodyAsString()).getBytes()));
        root = document.getDocumentElement();
        String taskId = findNode(
                findNode(root.getChildNodes(), "org.alfresco.service.cmr.workflow.WorkflowTask")
                        .getChildNodes(),
                "id").getTextContent();

        post = new PostMethod(alfrescohost + "service/xforms/workflow");
        post.setParameter("username", user);
        post.setParameter("method", "getPackageContents");
        post.setParameter("arg0", taskId);
        client = new HttpClient();
        client.executeMethod(post);

        document = builder.parse(new ByteArrayInputStream(
                ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + post.getResponseBodyAsString()).getBytes()));
        root = document.getDocumentElement();

        for (int i = 0; i < root.getChildNodes().getLength(); i++) {
            Node n = root.getChildNodes().item(i);
            if (n.getNodeType() == Element.ELEMENT_NODE) {
                String protocol = findNode(findNode(n.getChildNodes(), "storeRef").getChildNodes(), "protocol")
                        .getTextContent();
                String workspace = findNode(findNode(n.getChildNodes(), "storeRef").getChildNodes(),
                        "identifier").getTextContent();
                String id = findNode(n.getChildNodes(), "id").getTextContent();

                String url = alfrescohost + "service/api/node/" + protocol + "/" + workspace + "/" + id;
                GetMethod get = new GetMethod(url);
                client = new HttpClient();
                UsernamePasswordCredentials upc = new UsernamePasswordCredentials(user, password);
                client.getState().setCredentials(AuthScope.ANY, upc);
                get.setDoAuthentication(true);
                client.executeMethod(get);
                document = builder.parse(get.getResponseBodyAsStream());
                Node rootContent = document.getDocumentElement();

                Vector<String> v = new Vector<String>();
                String downloadUrl = findNode(rootContent.getChildNodes(), "content").getAttributes()
                        .getNamedItem("src").getNodeValue();
                String title = findNode(rootContent.getChildNodes(), "title").getTextContent();
                String icon = findNode(rootContent.getChildNodes(), "alf:icon").getTextContent();
                v.add(title);
                v.add(downloadUrl);
                v.add(icon);
                result.add(v);
            }
        }
    }
    return result;
}

From source file:edu.umn.cs.spatialHadoop.operations.Repartition.java

public static CellInfo[] packInRectangles(Path[] files, Path outFile, OperationsParams params,
        Rectangle fileMBR) throws IOException {
    final Vector<Point> sample = new Vector<Point>();

    float sample_ratio = params.getFloat(SpatialSite.SAMPLE_RATIO, 0.01f);
    long sample_size = params.getLong(SpatialSite.SAMPLE_SIZE, 100 * 1024 * 1024);

    LOG.info("Reading a sample of " + (int) Math.round(sample_ratio * 100) + "%");
    ResultCollector<Point> resultCollector = new ResultCollector<Point>() {
        @Override//from   w ww  .  j  a va  2s  .c o  m
        public void collect(Point value) {
            sample.add(value.clone());
        }
    };
    OperationsParams params2 = new OperationsParams(params);
    params2.setFloat("ratio", sample_ratio);
    params2.setLong("size", sample_size);
    params2.setClass("outshape", Point.class, TextSerializable.class);
    Sampler.sample(files, resultCollector, params2);
    LOG.info("Finished reading a sample of size: " + sample.size() + " records");

    long inFileSize = Sampler.sizeOfLastProcessedFile;

    // Compute an approximate MBR to determine the desired number of rows
    // and columns
    Rectangle approxMBR;
    if (fileMBR == null) {
        approxMBR = new Rectangle(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE);
        for (Point pt : sample)
            approxMBR.expand(pt);
    } else {
        approxMBR = fileMBR;
    }
    GridInfo gridInfo = new GridInfo(approxMBR.x1, approxMBR.y1, approxMBR.x2, approxMBR.y2);
    FileSystem outFs = outFile.getFileSystem(params);
    @SuppressWarnings("deprecation")
    long blocksize = outFs.getDefaultBlockSize();
    gridInfo.calculateCellDimensions(Math.max(1, (int) ((inFileSize + blocksize / 2) / blocksize)));
    if (fileMBR == null)
        gridInfo.set(-Double.MAX_VALUE, -Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
    else
        gridInfo.set(fileMBR);

    Rectangle[] rectangles = RTree.packInRectangles(gridInfo, sample.toArray(new Point[sample.size()]));
    CellInfo[] cellsInfo = new CellInfo[rectangles.length];
    for (int i = 0; i < rectangles.length; i++)
        cellsInfo[i] = new CellInfo(i + 1, rectangles[i]);

    return cellsInfo;
}

From source file:controller.OrderProductController.java

@RequestMapping(method = RequestMethod.GET)
public String orderProduct(Authentication authen, ModelMap mm) {
    Distributor dis = disModel.find(authen.getName(), "username", false).get(0);
    List<Product> listProduct = proModel.find(dis, "distributor", false);
    Vector data = new Vector();
    Vector column = new Vector();
    column.add("Product Name");
    column.add("Customer Name");
    column.add("Serial");
    column.add("Price");
    for (Product p : listProduct) {
        List<Requirement> listReq = rqModel.find(p, "product", false);
        for (Requirement requirement : listReq) {
            if (requirement != null) {
                Vector tmp = new Vector();
                tmp.add(requirement.getProduct().getProductName());
                tmp.add("id://" + requirement.getId().getProductId() + ":" + requirement.getId().getCustomerId()
                        + ":" + requirement.getId().getSerial());
                tmp.add(requirement.getCustomer().getCusName());
                tmp.add(requirement.getId().getSerial());
                tmp.add(nformat.format(requirement.getPrice()));
                data.add(tmp);/*w ww . j  ava  2s.  c om*/
            }
        }
    }
    mm.put("column", column);
    mm.put("data", data);
    mm.put("title", "Order Product Manager");
    return "orderProduct";
}

From source file:com.aquatest.dbinterface.tools.DatabaseUpdater.java

/**
 * Invoke web service to retrieve the tables to be updated
 * //from  w ww .j  av a2  s  . c o m
 * @return vector of table names
 * @throws ClientProtocolException
 * @throws JSONException
 * @throws IOException
 */
// method declared static for Android optimisation
private static Vector<String> getTables() throws JSONException, ClientProtocolException, IOException {
    // java compiler optimises this away if statement based on value of
    // MOCK_WEB_SERVICES i.e. similar to C compiler #ifdef blocks

    JSONObject tableResponse;
    if (DebugConstants.MOCK_WEB_SERVICES) {
        // mock web services
        tableResponse = MockAquaTestWebService.retrieveTables();
    } else {
        // real production server
        tableResponse = AquaTestWebService.retrieveTables();
        ;
    }

    if (tableResponse == null)
        return new Vector<String>();

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

    int count = 0;
    String status = "";
    JSONArray a = null;

    status = tableResponse.getString(STATUS_KEY);

    if (status.compareTo(STATUS_SUCCESS) == 0) {
        count = tableResponse.getInt(COUNT_KEY);

        if (count > 0) {
            a = tableResponse.getJSONArray(DATA_KEY);

            for (int i = 0; i < a.length(); i++) {
                tables.add((String) a.get(i));
            }
        }
    }

    return tables;
}

From source file:com.emr.utilities.SQLiteGetProcesses.java

@Override
protected CustomTableModel doInBackground() throws Exception {
    SQLite.setLibraryPath("lib");
    SQLiteConnection db = null;//  w  w  w. ja v a 2s .c om
    SQLiteStatement st = null;
    Vector data = new Vector();
    Vector columns = new Vector();
    columns.add("Name");
    columns.add("Description");
    columns.add("SelectQry");
    columns.add("DestinationTable");
    columns.add("TruncateFirst");
    columns.add("DestinationColumns");
    columns.add("ColumnsToBeMapped");
    columns.add("Delete?");

    try {
        File file = new File("sqlite/db");
        if (!file.exists()) {
            file.createNewFile();
        }
        db = new SQLiteConnection(file);
        db.open(true);
        st = db.prepare(
                "SELECT name,description,selectQry,destinationTable,truncateFirst,destinationColumns,columnsToBeMapped FROM procedures");
        Vector row;
        while (st.step()) {
            row = new Vector(5);
            row.add(st.columnString(0));
            row.add(st.columnString(1));
            row.add(st.columnString(2));
            row.add(st.columnString(3));
            row.add(st.columnString(4));
            row.add(st.columnString(5));
            row.add(st.columnString(6));
            row.add("");
            data.add(row);
        }
    } catch (Exception e) {
        System.err.println("Data Mover Error: " + e.getMessage());
        String stacktrace = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e);

        error_msg = stacktrace;
    } finally {
        if (st != null)
            st.dispose();
        if (db != null)
            db.dispose();
    }
    CustomTableModel tableModel = new CustomTableModel(data, columns);

    return tableModel;
}

From source file:com.redhat.rhn.frontend.servlets.test.CreateRedirectURITest.java

/**
 *
 *//*from www . j  a  v a 2 s . c o  m*/
public final void testExecuteWhenRequestHasParams() throws Exception {
    String paramName = "foo";
    String paramValue = "param value = bar#$%!";

    String expected = "/YourRhn.do?foo=" + URLEncoder.encode(paramValue, "UTF-8") + "&";

    Vector<String> paramNames = new Vector<String>();
    paramNames.add(paramName);

    mockRequest.stubs().method("getParameterNames").will(returnValue(paramNames.elements()));
    mockRequest.stubs().method("getParameter").with(eq(paramName)).will(returnValue(paramValue));

    CreateRedirectURI command = new CreateRedirectURI();
    String redirectURI = command.execute(getMockRequest());

    assertEquals(expected, redirectURI);
}

From source file:Main.java

public Main() throws Exception {
    ArrayList columnNames = new ArrayList();
    ArrayList data = new ArrayList();
    String url = "jdbc:mysql://localhost:3306/yourdb";
    String userid = "root";
    String password = "sesame";
    String sql = "SELECT * FROM animals";

    Connection connection = DriverManager.getConnection(url, userid, password);
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    ResultSetMetaData md = rs.getMetaData();
    int columns = md.getColumnCount();
    for (int i = 1; i <= columns; i++) {
        columnNames.add(md.getColumnName(i));
    }//from   w  w w. j av  a  2  s  .  c o m
    while (rs.next()) {
        ArrayList row = new ArrayList(columns);
        for (int i = 1; i <= columns; i++) {
            row.add(rs.getObject(i));
        }
        data.add(row);
    }
    Vector columnNamesVector = new Vector();
    Vector dataVector = new Vector();
    for (int i = 0; i < data.size(); i++) {
        ArrayList subArray = (ArrayList) data.get(i);
        Vector subVector = new Vector();
        for (int j = 0; j < subArray.size(); j++) {
            subVector.add(subArray.get(j));
        }
        dataVector.add(subVector);
    }
    for (int i = 0; i < columnNames.size(); i++)
        columnNamesVector.add(columnNames.get(i));
    JTable table = new JTable(dataVector, columnNamesVector) {
        public Class getColumnClass(int column) {
            for (int row = 0; row < getRowCount(); row++) {
                Object o = getValueAt(row, column);
                if (o != null) {
                    return o.getClass();
                }
            }
            return Object.class;
        }
    };
    JScrollPane scrollPane = new JScrollPane(table);
    getContentPane().add(scrollPane);
    JPanel buttonPanel = new JPanel();
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
}

From source file:eu.learnpad.simulator.mon.example.MyGlimpseProbe_BPMN_LearnPAd.java

private void generateAndSendExample_GlimpseBaseEvents_StringPayload(String data, int sendingInterval)
        throws UnknownHostException {
    DebugMessages.ok();//from   w  w  w  .  j a  v a 2 s.c o m
    DebugMessages.print(TimeStamp.getCurrentTime(), MyGlimpseProbe_BPMN_LearnPAd.class.getName(),
            "Creating GlimpseBaseEventBPMN message");
    GlimpseBaseEventBPMN<String> message;
    DebugMessages.ok();
    DebugMessages.line();
    try {

        AbstractEvent theEvent = new SessionScoreUpdateEvent();

        for (int i = 0; i < 1000; i++) {
            Vector<Learner> usersInvolved = new Vector<>();
            usersInvolved.add(new Learner(1, 12, "testName1", "testSurname1"));
            usersInvolved.add(new Learner(2, 24, "testName2", "testSurname2"));

            message = new GlimpseBaseEventBPMN<String>(data, "aGenericProbe", System.currentTimeMillis(),
                    "EventGeneratedFromActivitiEngineSimulated", false, "ExtraField", theEvent);

            this.sendEventMessage(message, false);
            DebugMessages.println(TimeStamp.getCurrentTime(), MyGlimpseProbe_BPMN_LearnPAd.class.getName(),
                    "GlimpseBaseEventBPMN message sent: {\n" + "eventName: " + message.getEventName() + "\n"
                            + "eventData: " + message.getEventData() + "\n" + "timestamp: "
                            + message.getTimeStamp() + "\n" + "extraField: " + message.getExtraDataField()
                            + "\n" + "sessionID_Field: " + message.event.simulationsessionid + "\n"
                            + "usersInvolvedSize: " + message.event.involvedusers + "\n" + "eventType: "
                            + message.event.type + "}");
            DebugMessages.line();
            Thread.sleep(sendingInterval);
        }
    } catch (JMSException e1) {
        e1.printStackTrace();
    } catch (NamingException e1) {
        e1.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:de.betterform.connector.xmlrpc.XMLRPCURIResolver.java

/**
 * Parses the URI into three elements.//w ww  .  j a va 2 s  .c  o  m
 * The xmlrpc URL, the function and the params
 *
 * @return a Vector
 */
private Vector parseURI(URI uri) {
    String host = uri.getHost();
    int port = uri.getPort();
    String path = uri.getPath();
    String query = uri.getQuery();

    /* Split the path up into basePath and function */
    int finalSlash = path.lastIndexOf('/');
    String basePath = "";
    if (finalSlash > 0) {
        basePath = path.substring(1, finalSlash);
    }
    String function = path.substring(finalSlash + 1, path.length());

    String rpcURL = "http://" + host + ":" + port + "/" + basePath;

    log.debug("New URL  = " + rpcURL);
    log.debug("Function = " + function);

    Hashtable paramHash = new Hashtable();

    if (query != null) {
        String[] params = query.split("&");

        for (int i = 0; i < params.length; i++) {
            log.debug("params[" + i + "] = " + params[i]);
            String[] keyval = params[i].split("=");
            log.debug("\t" + keyval[0] + " -> " + keyval[1]);
            paramHash.put(keyval[0], keyval[1]);
        }
    }

    Vector ret = new Vector();
    ret.add(rpcURL);
    ret.add(function);
    ret.add(paramHash);
    return ret;
}

From source file:marytts.util.io.FileUtils.java

public static Collection<File> listFiles(File directory, FilenameFilter filter, boolean recurse) {
    // List of files / directories
    Vector<File> files = new Vector<File>();

    // Get files / directories in the directory
    File[] entries = directory.listFiles();

    // Go over entries
    for (File entry : entries) {
        // If there is no filter or the filter accepts the 
        // file / directory, add it to the list
        if (filter == null || filter.accept(directory, entry.getName())) {
            files.add(entry);
        }//w ww  . j  a  v  a 2  s  .  co m

        // If the file is a directory and the recurse flag
        // is set, recurse into the directory
        if (recurse && entry.isDirectory()) {
            files.addAll(listFiles(entry, filter, recurse));
        }
    }

    // Return collection of files
    return files;
}