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:org.rapidandroid.activity.FormReviewer.java

private void doCsvDirectBednetsInjection() {
    String rawMessageText = "";

    try {//  w ww  .ja v  a 2  s. co  m
        InputStream is = this.getAssets().open("testdata/rawdata.csv");

        int size = is.available();

        // Read the entire asset into a local byte buffer.
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();

        // Convert the buffer into a Java string.
        String text = new String(buffer);

        rawMessageText = text;

    } catch (IOException e) {
        // Should never happen!
        throw new RuntimeException(e);
    }

    StringReader sr = new StringReader(rawMessageText);
    BufferedReader bufRdr = new BufferedReader(sr);

    String line = null;
    //      int row = 0;
    //      int col = 0;
    Vector<String[]> lines = new Vector<String[]>();
    // read each line of text file
    try {
        while ((line = bufRdr.readLine()) != null) {
            StringTokenizer st = new StringTokenizer(line, ",");
            int tokCount = st.countTokens();

            String[] tokenizedLine = new String[tokCount];
            int toki = 0;
            while (st.hasMoreTokens()) {
                tokenizedLine[toki] = st.nextToken();
                toki++;
            }
            lines.add(tokenizedLine);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {

        try {
            sr.close();
            bufRdr.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    int len = lines.size();

    for (int i = 0; i < len; i++) {
        String[] csvline = lines.get(i);

        String datestr = csvline[0];

        Date dateval = new Date();
        try {
            dateval = Message.SQLDateFormatter.parse(datestr);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        String sender = csvline[1];
        String text = csvline[2];

        Monitor monitor = MessageTranslator.GetMonitorAndInsertIfNew(this, sender);

        ContentValues messageValues = new ContentValues();
        messageValues.put(RapidSmsDBConstants.Message.MESSAGE, text);
        messageValues.put(RapidSmsDBConstants.Message.MONITOR, monitor.getID());

        messageValues.put(RapidSmsDBConstants.Message.TIME, Message.SQLDateFormatter.format(dateval));
        messageValues.put(RapidSmsDBConstants.Message.RECEIVE_TIME, Message.SQLDateFormatter.format(dateval));
        messageValues.put(RapidSmsDBConstants.Message.IS_OUTGOING, false);

        Uri msgUri = null;

        msgUri = this.getContentResolver().insert(RapidSmsDBConstants.Message.CONTENT_URI, messageValues);
        Vector<IParseResult> results = ParsingService.ParseMessage(mForm, text);
        ParsedDataTranslator.InsertFormData(this, mForm,
                Integer.valueOf(msgUri.getPathSegments().get(1)).intValue(), results);
    }

}

From source file:webServices.RestServiceImpl.java

@GET
@Path("/mapInformation/{id}/{host}/{endpoint}/{qType}/{port}")
@Produces(MediaType.TEXT_PLAIN)//from www . java  2  s .  c o m
public String getMapInformation(@PathParam("id") String id, @PathParam("host") String host,
        @PathParam("endpoint") String endpoint, @PathParam("qType") String qType, @PathParam("port") int port)
        throws EndpointCommunicationException {

    //Reset to default registry values
    endpointStore = new MapEndpointStore();

    //Get host info if the map is not saved in Registry
    if (!host.equalsIgnoreCase("none")) {
        endpointStore.setEndpointQuery(host, port, endpoint + "/" + qType);
    }

    //query registry to get the layers of the map with the specific id
    Vector<String> results = endpointStore.getMapInformation(id);
    String format = "";
    for (int i = 0; i < results.size(); i++) {
        format = format.concat(results.get(i));
        format = format.concat("$");
    }

    //Add the application host to the results, for user feature loading
    if (PROXY_STATUS.equalsIgnoreCase("on")) {
        format = format
                .concat(HTTP + PROXY_NAME + ":" + PROXY_PORT + context.getContextPath() + "/" + STORE_FOLDER);
    } else {
        format = format.concat(HTTP + servlet.getServerName() + ":" + servlet.getServerPort()
                + context.getContextPath() + "/" + STORE_FOLDER);
    }
    format = format.concat("$");

    return format;
}

From source file:org.mahasen.util.PutUtil.java

/**
 * @param part//from w ww . j a va 2s. co m
 * @param parentFileName
 * @param partName
 * @throws MahasenConfigurationException
 * @throws PastException
 * @throws InterruptedException
 */
public void replicateFilePart(File part, String parentFileName, String partName)
        throws MahasenConfigurationException, PastException, InterruptedException, MahasenException {
    Vector<String> nodeIpsToPut = getNodeIpsToPut();

    String resourcePath = MahasenConstants.ROOT_REGISTRY_PATH + parentFileName;
    Id parentFileId = Id.build(String.valueOf(resourcePath.hashCode()));

    while (mahasenManager.lookupDHT(parentFileId) == null) {
        Thread.sleep(1000);
    }
    MahasenResource mahasenResourceToUpdate = mahasenManager.lookupDHT(parentFileId);

    getReplicaReference().put(partName, 0);

    Random random = new Random();

    Hashtable<String, Vector<String>> spittedPartsStoredIps = mahasenResourceToUpdate.getSplittedPartsIpTable();
    Vector<String> currentPartStoredIps = spittedPartsStoredIps.get(partName);
    List<String> replicateIds = new ArrayList<String>();
    final BlockFlag blockFlag = new BlockFlag(true, 3000);

    while (true) {

        if (nodeIpsToPut.size() >= MahasenConstants.NUMBER_OF_REPLICAS + 1) {
            if (getReplicaReference().get(partName) == MahasenConstants.NUMBER_OF_REPLICAS) {
                log.info("Success in replicating :" + getReplicaReference().get(partName) + " parts");
                break;
            }

            String nodeIp = nodeIpsToPut.get(random.nextInt(nodeIpsToPut.size()));

            if (!currentPartStoredIps.contains(nodeIp) && !replicateIds.contains(nodeIp)) {
                replicateIds.add(nodeIp);
                try {
                    sendReplicateRequest(nodeIp, part, partName, mahasenResourceToUpdate, parentFileId);
                } catch (URISyntaxException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                }
            }
        } else {

            for (String ip : nodeIpsToPut) {
                if (!currentPartStoredIps.contains(ip)) {
                    try {
                        sendReplicateRequest(ip, part, partName, mahasenResourceToUpdate, parentFileId);
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            }
            blockFlag.unblock();
            break;

        }

        if (blockFlag.isBlocked()) {

            mahasenManager.getNode().getEnvironment().getTimeSource().sleep(10);
        } else {
            throw new MahasenException("Time out in storing " + part.getName());
        }
        Thread.sleep(100);
    }
}

From source file:eionet.gdem.dcm.business.SchemaManager.java

/**
 * Get XML Schema info with related QA scripts.
 * @param schemaId XML Schema database ID.
 * @return QAScriptListHolder holding XML Schema and QA scripts information.
 * @throws DCMException in case of database error.
 *///from  w  w  w.  j  av  a  2 s  .  c om
public QAScriptListHolder getSchemasWithQAScripts(String schemaId) throws DCMException {

    QAScriptListHolder st = new QAScriptListHolder();
    Vector hcSchemas;
    List<Schema> schemas;

    try {
        schemas = new ArrayList<Schema>();
        hcSchemas = schemaDao.getSchemas(schemaId);
        if (hcSchemas == null) {
            hcSchemas = new Vector();
        }

        for (int i = 0; i < hcSchemas.size(); i++) {
            HashMap schema = (HashMap) hcSchemas.get(i);
            Schema sc = new Schema();
            sc.setId((String) schema.get("schema_id"));
            sc.setSchema((String) schema.get("xml_schema"));
            sc.setDescription((String) schema.get("description"));
            boolean validate = (!Utils.isNullStr((String) schema.get("validate"))
                    && ((String) schema.get("validate")).equals("1"));
            sc.setDoValidation(validate);
            boolean blocker = (!Utils.isNullStr((String) schema.get("blocker"))
                    && ((String) schema.get("blocker")).equals("1"));
            sc.setBlocker(blocker);

            Vector qascripts = new Vector();
            if (schema.containsKey("queries")) {
                qascripts = (Vector) schema.get("queries");
            }

            List<QAScript> qases = new ArrayList<QAScript>();
            for (int j = 0; j < qascripts.size(); j++) {
                HashMap qascript = (HashMap) qascripts.get(j);
                QAScript qas = new QAScript();
                qas.setScriptId((String) qascript.get("query_id"));
                qas.setFileName((String) qascript.get("query"));
                qas.setDescription((String) qascript.get("description"));
                qas.setShortName((String) qascript.get("short_name"));
                qas.setScriptType((String) qascript.get("script_type"));
                qas.setResultType((String) qascript.get("result_type"));
                qas.setActive((String) qascript.get("is_active"));
                qases.add(qas);

                // get file last modified only if schemaId is known
                if (schemaId != null) {
                    if (!Utils.isNullStr(qas.getFileName())) {
                        qas.setFilePath(Names.QUERY_FOLDER + qas.getFileName());
                        String queryFolder = Properties.queriesFolder;
                        if (!queryFolder.endsWith(File.separator)) {
                            queryFolder = queryFolder + File.separator;
                        }
                        try {
                            File f = new File(queryFolder + qas.getFileName());
                            if (f != null && f.exists()) {
                                qas.setModified(Utils.getDateTime(new Date(f.lastModified())));
                            }
                        } catch (Exception e) {
                            LOGGER.error("Unable to read QA script file last modified time.", e);
                        }

                    }
                }

            }
            if (qases.size() > 0) {
                sc.setQascripts(qases);
            }
            if (qases.size() > 0 || schemaId != null || sc.isDoValidation()) {
                schemas.add(sc);
            }
        }
        if (schemas.size() > 0) {
            st.setQascripts(schemas);
        }

    } catch (Exception e) {
        e.printStackTrace();
        LOGGER.error("Error getting schemas with QA scripts", e);
        throw new DCMException(BusinessConstants.EXCEPTION_GENERAL);
    }
    return st;

}

From source file:webServices.RestServiceImpl.java

@POST
@Path("/mapSearch/{host}/{endpoint}/{port}")
@Consumes({ MediaType.WILDCARD, MediaType.APPLICATION_JSON })
@Produces({ MediaType.TEXT_PLAIN })/* ww  w  . j a v  a 2 s .c om*/
public String mapSearchQuery(String inputData, @PathParam("host") String host,
        @PathParam("endpoint") String endpoint, @PathParam("port") int port)
        throws EndpointCommunicationException {
    String format = "";
    String[] parser = inputData.split("\\$");
    String title = parser[0];
    String creator = parser[1];
    String license = parser[2];
    String theme = parser[3];
    String extent = parser[4];

    //Reset to default registry values
    endpointStore = new MapEndpointStore();

    //Get host info if the map is not saved in Registry
    if (!host.equalsIgnoreCase("registry")) {
        endpointStore.setEndpointQuery(host, port, endpoint + "/Query");
    }

    //Construct query
    String query = "PREFIX strdf: <http://strdf.di.uoa.gr/ontology#> "
            + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "
            + "SELECT ?mapId ?title ?creator ?license ?theme ?description WHERE { "
            + "?mapId <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" + MapVocabulary.MAP + ">  . "
            + "?mapId <" + MapVocabulary.HASTITLE + "> ?title . " + "?mapId <" + MapVocabulary.HASCREATOR
            + "> ?creator . " + "?mapId <" + MapVocabulary.HASLICENSE + "> ?license . " + "?mapId <"
            + MapVocabulary.HASTHEME + "> ?theme . " + "?mapId <" + MapVocabulary.HASDESCRIPTION
            + "> ?description . " + "?mapId <" + MapVocabulary.HASGEOMETRY + "> ?geom . ";

    if (!title.equalsIgnoreCase("none")) {
        query = query.concat("FILTER regex(?title, \"" + title + "\", \"i\") . ");
    }
    if (!creator.equalsIgnoreCase("none")) {
        query = query.concat("FILTER regex(?creator, \"" + creator + "\", \"i\") . ");
    }
    if (!license.equalsIgnoreCase("none")) {
        query = query.concat("FILTER regex(?license, \"" + license + "\", \"i\") . ");
    }
    if (!theme.equalsIgnoreCase("none")) {
        query = query.concat("FILTER regex(?theme, \"" + theme + "\", \"i\") . ");
    }
    if (!extent.equalsIgnoreCase("none")) {
        query = query.concat("FILTER (strdf:mbbIntersects(?geom, \"" + extent
                + "\"^^<http://www.opengis.net/ont/geosparql#wktLiteral>)) . ");
    }
    query = query.concat("}");
    System.out.println(query);

    //Pose query
    Vector<String> results = endpointStore.searchForMaps(query);

    //Parse results
    for (int i = 0; i < results.size(); i++) {
        format = format.concat(results.get(i));
        format = format.concat("$");
    }

    return format;
}

From source file:edu.ku.brc.specify.tasks.SystemSetupTask.java

/**
 * @return the User Name who will get the resources imported into
 */// w ww.j  av a 2 s. co m
protected String pickUserName() {
    Division division = AppContextMgr.getInstance().getClassObject(Division.class);
    String currUserName = (AppContextMgr.getInstance().getClassObject(SpecifyUser.class)).getName();
    String postSQL = String
            .format(" FROM specifyuser su INNER JOIN agent a ON su.SpecifyUserID = a.SpecifyUserID "
                    + "INNER JOIN division d ON a.DivisionID = d.UserGroupScopeId "
                    + "WHERE su.Name <> '%s' AND d.UserGroupScopeId = %d", currUserName, division.getId());

    int count = BasicSQLUtils.getCountAsInt("SELECT COUNT(*) " + postSQL);
    if (count == 0) {
        return null;
    }

    int choice = askYesNoLocalized("SYSSTP_CHSE_ME", "SYSSTP_CHSE_DIF", getResourceString("SYSSTP_CHSE_USER"),
            "SYSSTP_CHSE_USER_TITLE");
    if (choice == JOptionPane.YES_OPTION) {
        return null; // null means choose the current user
    }

    Vector<Object> names = BasicSQLUtils.querySingleCol("SELECT su.Name " + postSQL);
    if (names.size() == 1) {
        return names.get(0).toString();
    }

    ChooseFromListDlg<Object> dlg = new ChooseFromListDlg<Object>((Frame) getMostRecentWindow(),
            getResourceString("SYSSTP_CHSE_USER_TITLE"), names);
    UIHelper.centerAndShow(dlg);
    return !dlg.isCancelled() ? dlg.getSelectedObject().toString() : CANCELLED;
}

From source file:webServices.RestServiceImpl.java

@POST
@Path("/endpoint/queries/{host}/{endpoint}/{port}")
@Consumes({ MediaType.WILDCARD, MediaType.APPLICATION_JSON })
@Produces({ MediaType.TEXT_PLAIN })/* w w  w  .  j ava  2 s . c  o  m*/
public String getQueries(@PathParam("host") String host, @PathParam("endpoint") String endpoint,
        @PathParam("port") int port) throws EndpointCommunicationException {
    Vector<String> results = new Vector<String>();
    String format = "";
    results = endpointStore.getQueriesText(host, endpoint.replaceAll("@@@", "/"), port);

    for (int i = 0; i < results.size(); i++) {
        format = format.concat(results.get(i));
        format = format.concat("$");
    }

    return format;
}

From source file:it.classhidra.core.controller.bsController.java

public static Vector getActionStreams_(String id_action) {

    Vector _streams_orig = (Vector) getAction_config().get_streams_apply_to_actions().get("*");

    //Modifica 20100521 Warning 
    /*//from  w ww. j a va 2s  .  com
       try{
          _streams = (Vector)util_cloner.clone(_streams_orig);
       }catch(Exception e){
       }
    */
    Vector _streams4action = (Vector) getAction_config().get_streams_apply_to_actions().get(id_action);
    if (_streams4action == null)
        return (_streams_orig == null) ? new Vector() : _streams_orig;
    else {
        Vector _streams = new Vector();
        if (_streams_orig != null)
            _streams.addAll(_streams_orig);
        Vector _4add = new Vector();
        HashMap _4remove = new HashMap();
        for (int i = 0; i < _streams4action.size(); i++) {
            info_stream currentis = (info_stream) _streams4action.get(i);
            if (currentis.get_apply_to_action() != null) {
                info_apply_to_action currentiata = (info_apply_to_action) currentis.get_apply_to_action()
                        .get(id_action);
                if (currentiata.getExcluded() != null && currentiata.getExcluded().equalsIgnoreCase("true"))
                    _4remove.put(currentis.getName(), currentis.getName());
                else
                    _4add.add(currentis);
            }
        }
        _streams.addAll(_4add);
        if (_4remove.size() > 0) {
            int i = 0;
            while (i < _streams.size()) {
                info_stream currentis = (info_stream) _streams.get(i);
                if (_4remove.get(currentis.getName()) != null)
                    _streams.remove(i);
                else
                    i++;
            }
        }
        _streams = new util_sort().sort(_streams, "int_order", "A");
        return _streams;
    }
}

From source file:webServices.RestServiceImpl.java

@POST
@Path("/endpoint/charts/staticQuery/{host}/{endpoint}/{port}")
@Consumes({ MediaType.WILDCARD, MediaType.APPLICATION_JSON })
@Produces({ MediaType.TEXT_PLAIN })//from   w  w w  .  j  a  va  2  s.  co m
public String getStaticQuery(@PathParam("host") String host, @PathParam("endpoint") String endpoint,
        @PathParam("port") int port) throws EndpointCommunicationException {
    Vector<String> results = new Vector<String>();
    String format = "";

    results = endpointStore.getStaticPart(host, endpoint.replaceAll("@@@", "/"), port);

    for (int i = 0; i < results.size(); i++) {
        format = format.concat(results.get(i));
        format = format.concat("$");
    }

    return format;
}

From source file:webServices.RestServiceImpl.java

@POST
@Path("/endpoint/explore/{host}/{endpoint}/{port}")
@Consumes({ MediaType.WILDCARD, MediaType.APPLICATION_JSON })
@Produces({ MediaType.TEXT_PLAIN })//from w w  w  . j av a2s .  c  o m
public String getExploreClasses(@PathParam("host") String host, @PathParam("endpoint") String endpoint,
        @PathParam("port") int port) throws EndpointCommunicationException {
    Vector<String> results = new Vector<String>();
    String format = "";
    results = endpointStore.getExploreClasses(host, endpoint.replaceAll("@@@", "/"), port);

    for (int i = 0; i < results.size(); i++) {
        format = format.concat(results.get(i));
        format = format.concat("$");
    }

    return format;
}