Example usage for java.util Vector removeElementAt

List of usage examples for java.util Vector removeElementAt

Introduction

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

Prototype

public synchronized void removeElementAt(int index) 

Source Link

Document

Deletes the component at the specified index.

Usage

From source file:org.sakaiproject.content.tool.AttachmentAction.java

/**
 * Handle the eventSubmit_doRemove command to remove the selected attachment(s).
 *//*from w  w  w . ja  v a  2  s  . c o m*/
static public void doRemove(RunData data) {
    if (!"POST".equals(data.getRequest().getMethod())) {
        return;
    }

    SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());

    // modify the attachments vector
    Vector attachments = (Vector) state.getAttribute(STATE_ATTACHMENTS);

    // read the form to figure out which attachment(s) to remove.
    String[] selected = data.getParameters().getStrings("select");

    // if nothing selected, and there's just one attachment, remove it
    if (selected == null) {
        if (attachments.size() == 1) {
            attachments.clear();
        } else {
            // leave a message
            state.setAttribute(VelocityPortletPaneledAction.STATE_MESSAGE, rb.getString("alert"));
        }
    }

    else {
        // run through these 1 based indexes backwards, so we can remove each without invalidating the rest
        // ASSUME: they are in ascending order
        for (int i = selected.length - 1; i >= 0; i--) {
            try {
                int index = Integer.parseInt(selected[i]) - 1;
                attachments.removeElementAt(index);
            } catch (Exception e) {
                M_log.warn(
                        "AttachmentAction" + ".doRemove(): processing selected [" + i + "] : " + e.toString());
            }
        }
    }

    // end up in main mode
    state.setAttribute(STATE_MODE, MODE_MAIN);

}

From source file:org.springframework.util.exec.Execute.java

/**
 * Patch the current environment with the new values from the user.
 *
 * @return the patched environment// w ww. j  a  v a  2 s .c o m
 */
private String[] patchEnvironment() {
    @SuppressWarnings("unchecked")
    Vector<String> osEnv = (Vector<String>) getProcEnvironment().clone();
    for (int i = 0; i < env.length; i++) {
        int pos = env[i].indexOf('=');
        // Get key including "="
        String key = env[i].substring(0, pos + 1);
        int size = osEnv.size();
        for (int j = 0; j < size; j++) {
            if ((osEnv.elementAt(j)).startsWith(key)) {
                osEnv.removeElementAt(j);
                break;
            }
        }
        osEnv.addElement(env[i]);
    }
    String[] result = new String[osEnv.size()];
    osEnv.copyInto(result);
    return result;
}

From source file:oscar.oscarEncounter.oscarMeasurements.util.WriteNewMeasurements.java

static private ActionMessages validate(Vector measures, String demographicNo) {
    ActionMessages errors = new ActionMessages();
    try {//from  ww w.j a v a  2s  .  c  o  m

        EctValidation ectValidation = new EctValidation();
        ResultSet rs;
        boolean valid = true;
        for (int i = 0; i < measures.size(); i++) {
            Hashtable measure = (Hashtable) measures.get(i);
            String inputType = (String) measure.get("type");
            String inputValue = (String) measure.get("value");
            String dateObserved = (String) measure.get("dateObserved");
            String comments = (String) measure.get("comments");
            String mInstrc, regCharExp;
            String regExp = null;
            double dMax = 0;
            double dMin = 0;
            int iMax = 0;
            int iMin = 0;
            org.apache.commons.validator.GenericValidator gValidator = new org.apache.commons.validator.GenericValidator();
            if (GenericValidator.isBlankOrNull(inputValue)) {
                measures.removeElementAt(i);
                i--;
                continue;
            }
            mInstrc = (String) measure.get("measuringInstruction");
            rs = ectValidation.getValidationType(inputType, mInstrc);
            regCharExp = ectValidation.getRegCharacterExp();
            if (rs.next()) {
                dMax = rs.getDouble("maxValue");
                dMin = rs.getDouble("minValue");
                iMax = rs.getInt("maxLength");
                iMin = rs.getInt("minLength");
                regExp = oscar.Misc.getString(rs, "regularExp");
            } else {
                //if type with instruction does not exist
                errors.add(inputType, new ActionMessage("errors.oscarEncounter.Measurements.cannotFindType",
                        inputType, mInstrc));
                valid = false;
                continue;
            }
            rs.close();

            if (!ectValidation.isInRange(dMax, dMin, inputValue)) {
                errors.add(inputType, new ActionMessage("errors.range", inputType, Double.toString(dMin),
                        Double.toString(dMax)));
                valid = false;
            }
            if (!ectValidation.maxLength(iMax, inputValue)) {
                errors.add(inputType, new ActionMessage("errors.maxlength", inputType, Integer.toString(iMax)));
                valid = false;
            }
            if (!ectValidation.minLength(iMin, inputValue)) {
                errors.add(inputType, new ActionMessage("errors.minlength", inputType, Integer.toString(iMin)));
                valid = false;
            }
            if (!ectValidation.matchRegExp(regExp, inputValue)) {
                errors.add(inputType, new ActionMessage("errors.invalid", inputType));
                valid = false;
            }
            if (!ectValidation.isValidBloodPressure(regExp, inputValue)) {
                errors.add(inputType, new ActionMessage("error.bloodPressure"));
                valid = false;
            }
            if (!ectValidation.isDate(dateObserved) && inputValue.compareTo("") != 0) {
                errors.add(inputType, new ActionMessage("errors.invalidDate", inputType));
                valid = false;
            }

            if (!valid)
                continue;
            inputValue = org.apache.commons.lang.StringEscapeUtils.escapeSql(inputValue);
            inputType = org.apache.commons.lang.StringEscapeUtils.escapeSql(inputType);
            mInstrc = org.apache.commons.lang.StringEscapeUtils.escapeSql(mInstrc);
            comments = org.apache.commons.lang.StringEscapeUtils.escapeSql(comments);

            //Find if the same data has already been entered into the system
            String sql = "SELECT * FROM measurements WHERE demographicNo='" + demographicNo
                    + "' AND dataField='" + inputValue + "' AND measuringInstruction='" + mInstrc
                    + "' AND comments='" + comments + "' AND dateObserved='" + dateObserved + "'";
            rs = DBHandler.GetSQL(sql);
            if (rs.next()) {
                measures.remove(i);
                i--;
                continue;
            }
        }
    } catch (SQLException sqe) {
        MiscUtils.getLogger().error("Error", sqe);
    }
    return errors;
}

From source file:vitro.vspEngine.service.persistence.DBCommons.java

/**
 *
 * @param ssUNinfoGWHM// w ww  . ja va  2 s .c  o m
 * @param ssUNCapHM
 * @param in_advCapsToSensModelsToMerge
 * @param in_advSmDevs
 * @param in_advGatewayIDStr
 * @param in_regGatewayDescStr
 * @param in_advGatewayIPv4
 * @param in_advGatewayLocStr
 */
synchronized public void mergeAdvDataToGateway(HashMap<String, GatewayWithSmartNodes> ssUNinfoGWHM,
        HashMap<String, Vector<SensorModel>> ssUNCapHM,
        HashMap<String, Vector<SensorModel>> in_advCapsToSensModelsToMerge, Vector<SmartNode> in_advSmDevs,
        String in_advGatewayIDStr, String in_regGatewayDescStr, String in_advGatewayIPv4,
        String in_advGatewayLocStr) {
    //
    // For each generic capability found in the GatewayDescriptionAdvertisement (even when went per smart device separately)
    // Check if the UserPeer's capHMap contains it
    //  (if not add it, with its full vector of sensormodels).
    //  (if it does, then add only those sensormodels that don't exist in the existing vector of sensormodels (of the UserPeer's capHMap)
    //  TODO: support String for id for sensorModels ...(?)
    Set<String> advCapsSet = in_advCapsToSensModelsToMerge.keySet();
    Iterator<String> advCapsIt = advCapsSet.iterator(); // from the received GW ADV
    String currentAdvCap;
    // place one check-box for each Generic Capability Description
    while (advCapsIt.hasNext()) {
        currentAdvCap = advCapsIt.next();
        Vector<SensorModel> listOfSensToAdd = in_advCapsToSensModelsToMerge.get(currentAdvCap);
        if (ssUNCapHM.containsKey(currentAdvCap)) {
            Vector<SensorModel> previousListOfSensModel = ssUNCapHM.get(currentAdvCap);
            // concatenate with previous List (skip if the results are from an existing gateway)
            // so this does not PRECLUDE the same sensor model being added for the generic capability. (TODO: this can only be fixed in the gateways retroactively make a shared hastable for unique ids for specifi sensormodels)
            // but each model is uniquely indexed within its gateway (and maintains the gateway id info in its class type). This is good and similar to the SensorML specs
            // SensorML additionally allows for multiple output formats for a "sensor model" (component) and unlimited nesting in components though....
            for (int k1 = 0; k1 < previousListOfSensModel.size(); k1++) {
                for (int m1 = 0; m1 < listOfSensToAdd.size(); m1++) {
                    if ((previousListOfSensModel.get(k1).getGatewayId()
                            .equals(listOfSensToAdd.get(m1).getGatewayId()))
                            && (previousListOfSensModel.get(k1).getSmID()
                                    .equals(listOfSensToAdd.get(m1).getSmID()))) { // we should add only the newly added models...if any
                        listOfSensToAdd.removeElementAt(m1);
                        m1 -= 1;
                    }
                }
            }
            previousListOfSensModel.addAll(listOfSensToAdd);
        } else if (listOfSensToAdd.size() > 0) {
            ssUNCapHM.put(currentAdvCap, listOfSensToAdd);
        }
    }

    // Find an existing entry for the gateway
    if (ssUNinfoGWHM.containsKey(in_advGatewayIDStr)) {
        // update existing mapped gateway with new possible values for each field
        GatewayWithSmartNodes tmpToUpd = ssUNinfoGWHM.get(in_advGatewayIDStr);
        Vector<SmartNode> existingSmDevs = tmpToUpd.getSmartNodesVec();

        tmpToUpd.setName(in_regGatewayDescStr); //renew description
        tmpToUpd.setDescription("GwDesc"); //????

        boolean foundDev = false;
        for (int j = 0; j < in_advSmDevs.size(); j++) {
            foundDev = false;
            for (int o = 0; o < existingSmDevs.size(); o++) {
                if (in_advSmDevs.elementAt(j).getId().equalsIgnoreCase(existingSmDevs.elementAt(o).getId())) {
                    foundDev = true;
                    existingSmDevs.setElementAt(in_advSmDevs.elementAt(j), o); //replace (update)

                }
            }
            if (foundDev == false) {
                existingSmDevs.add(in_advSmDevs.elementAt(j));
            }
        }
    } else {
        GatewayWithSmartNodes tmpToInsert = null;
        if (in_regGatewayDescStr != null && !(in_regGatewayDescStr.trim().isEmpty())) {

            tmpToInsert = new GatewayWithSmartNodes(new Gateway(in_advGatewayIDStr, in_regGatewayDescStr,
                    "GwDesc", null, null, in_advGatewayIPv4, in_advGatewayLocStr));
            tmpToInsert.setSmartNodesVec(in_advSmDevs);
        } else {
            GeoPoint gwGP = null;
            if (in_advGatewayLocStr != null) {
                String[] locTokensLatLong = in_advGatewayLocStr.split(",");
                if (locTokensLatLong != null && locTokensLatLong.length == 2) {
                    gwGP = new GeoPoint(locTokensLatLong[0].trim(), locTokensLatLong[1].trim(), "0");
                }
            }
            tmpToInsert = new GatewayWithSmartNodes(
                    new Gateway(in_advGatewayIDStr, "GwName", "GwDesc", null, gwGP, in_advGatewayIPv4, null));
            tmpToInsert.setSmartNodesVec(in_advSmDevs);
        }
        ssUNinfoGWHM.put(in_advGatewayIDStr, tmpToInsert);
    }
}